VPS配置之最小化资源占用

使用环境假定:
ramhost主机,ubuntu 9.10系统,已用ssh dropper登录到了root

配置目标:
在保证日常功能:ssh,ftp,http的情况下尽量节约系统资源,所以http server就用nginx,mysql换成sqlite,博客程序使用wordpress+PDO插件(以使用sqlite)
内存方面,sshd 2M, proftpd 2M, nginx 2+4M, php-cgi 9*2=18M,其他不占内存,一共是28M内存,其他初始杂七杂八的如init,cron,syslog等等加起来10M左右,那么一共才用了38M的内存,再苛刻的plan都足够用了,当然配置的时候也可以不用那么抠门,呵呵。

1.为安全起见,创建非root用户,修改密码,修改sudo权限:

useradd observer -m
passwd observer
vi /etc/sudoers
observer ALL=(ALL) ALL
vi /etc/passwd
把observer那行的/bin/sh改为/bin/bash
su observer

2.安装和简单配置vim编辑器

sudo apt-get install vim
sudo vi /etc/vim/vimrc
syntax on
set ts=4
set enc=utf-8

3.安装编译环境(总会用得到的)

sudo apt-get install build-essential

4.安装sshd,使得可以通过ssh命令(windows下则是putty)直接进行访问

sudo apt-get install ssh

5.安装ftpd,使得可以通过ftp来上传下载文件

sudo apt-get install proftpd
sudo vi /etc/proftpd/proftpd.conf

#下面是一个修改案例,配置好以后可以用本机的用户登录ftp(例如刚才建的observer账户)

> ServerName “proftp server”
> ServerIdent on “Welcome to proftp server”
> UseReverseDNS off
> IdentLookups off
> DefaultRoot ~
> RequireValidShell off
> Maxclients 30
> MaxClientsPerHost 2 #每个客户端限制的连接个数
> #如果想要让某个账户直接访问http文件所在的位置,那么在/etc/passwd中修改home目录,然后再加上类似下行代码,/var/www改为目录,wwwuser改为给访问权限的用户,记得不要忘记把/var/www的owner改为wwwuser(sudo chown wwwuser /var/www):
> DefaultRoot /var/www wwwuser

6.nginx+php

sudo apt-get install nginx
sudo apt-get install php5-cgi

新建一个脚本文件php-fastcgi,用来监听php请求

#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=2
PHP_FCGI_MAX_REQUESTS=1000
PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0
start() {
echo -n "Starting PHP FastCGI: "
start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
RETVAL=$?
echo "$PHP_CGI_NAME."
}
stop() {
echo -n "Stopping PHP FastCGI: "
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo "$PHP_CGI_NAME."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL

然后挪到/etc/init.d/,并启动之

sudo mv php-fastcgi /etc/init.d/
sudo chmod 755 /etc/init.d/php-fastcgi
sudo /etc/init.d/php-fastcgi start

配置nginx的php转发,模板文件,供参考。

sudo vi /etc/nginx/sites-enabled/default

server {
listen 80;
server_name www.app-base.com;

access_log /var/log/nginx/app-base.access.log;

location / {
root /var/www/app-base.com/htdocs/;
index index.html index.htm;
}

fastcgi_index index.php;

location ~ \.php {
include /etc/nginx/fastcgi_params;
keepalive_timeout 0;
fastcgi_param SCRIPT_FILENAME /var/www/app-base.com/htdocs/$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}

启动nginx:

sudo /etc/init.d/nginx start

7.安装wordpress using sqlite
下载wordpress http://wordpress.org/download/
下载PDO插件 http://wordpress.org/extend/plugins/pdo-for-wordpress/
把插件解压到wp-content
然后:

cd wp-content
mkdir database
chmod 777 database
cd ..
cp wp-config-sample.php wp-config.php
vi wp-config.php
define('DB_COLLATE', '');
define('DB_TYPE', 'sqlite');

然后就是正常的安装了,访问wp-admin/install.php即可

原文地址:http://obmem.info/?p=278

本文为悠然居(https://wordpress.youran.me/)的原创文章,转载请注明出处!

One thought on “VPS配置之最小化资源占用”

Leave a Reply

Your email address will not be published. Required fields are marked *