【FAQ】如何检查VPS母鸡配置RAID10

我们的VPS母鸡配置RAID10,以保证客户的数据安全,如果检查我们的磁盘确实配置了RAID10呢,SSH登陆VPS,执行hdparm -t /dev/sda(硬盘设备, 也可能是/dev/xvda或则/dev/sda1等,使用df -a命令查看)命令测试硬盘速度。没有安装hdparm的,可以执行yum -y install hdparm安装

如果速度能达到100MB/S以上的(100MB/s基本上是普通sata硬盘的极限),一般就是RAID10。RAID1的话,一般是100M以下。当然这个还需要看服务器的整体配置,以及服务器整体负载。
下面是我的XEN VPS磁盘运算速度情况

[root@15099.net ~]#df -a   <-----查看磁盘情况
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1              5160576   1944100   2954332  40% /
none                         0         0         0   -  /proc
none                         0         0         0   -  /sys
none                         0         0         0   -  /dev/pts
none                     98304      5004     93300   6% /dev/shm
none                         0         0         0   -  /proc/sys/fs/binfmt_misc
/dev/shm/nginx           98304      5004     93300   6% /var/tmp/nginx

[root@15099.net ~]#hdparm -t /dev/sda1

/dev/sda1:
 Timing buffered disk reads:  762 MB in  3.00 seconds = 253.70 MB/sec
[root@15099.net ~]#
从上面可以看出,我们的美国VPS 磁盘速度为253.70MB/sec,肯定做了RAID 10

备注:
只能检查xen虚拟平台的VPS,不能检查openvz虚拟平台的VPS,因为openvz VPS使用文件目录做硬盘

关于RAID 10介绍,可以查看http://baike.baidu.com/view/1026824.htm

【nginx】在美国 Linux VPS配置nginx 支持asp程序

目的:

总所周知,linux VPS不支持ASP程序,虽然在上一篇文章在美国 Linux VPS配置nginx 通过fastcgi+mono代理访问asp.net程序介绍在美国linux VPS配置支持ASP.NET程序,那么如果是linux VPS支持asp程序呢,可能通过此下列方法解决,前提你有一个支持asp的虚拟空间,在nginx下配置反向代理指向虚拟主机的某个子目录

nginx虚拟主机配置内容

server {
        listen       80;
        server_name  asptest.15099.net;

        location / {
         proxy_pass              http://www.15099.net/aspcheck/;
         proxy_redirect          http://www.15099.net/aspcheck/ /;
         proxy_set_header        X-Real-IP       $remote_addr;
         proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
         }
 }

这样访问http://asptest.15099.net实际上是转发到http://www.15099.net/aspcheck/目录下(假设www.15099.net空间支持asp)。

【nginx】在美国 Linux VPS配置nginx 通过fastcgi+mono代理访问asp.net程序

概述:

本文详细描述在美国linux VPS配置nginx使用fastcgi反向代理mono,使得linux可以支持asp.net环境,但是需要说明,真正如果网站都是asp.net语言开发的,还是建议使用美国windows VPS配置IIS。

mono介绍:

Mono是一个有Novell公司(先前是Ximian)主持的项目。该项目的目标是创建一系列符合标准ECMA(Ecma-334和Ecma-335)的NET工具,包括C#编译器和共同语言(CL 即Common Language)执行平台(Platform)。与微软的.NAT不同,Mono项目不仅运行于Windows系统内,还可以运行于Linux、FreeBSD、Unix、Mac OS X和Solaris操作系统内,不过,部分windows上的asp.net程序移植到Linux+Mono平台时需要做一些移植、修改。

Mono的安装

在CentOS 5 linux(注:目前只兼容32位系统)上,安装下面步骤安装mono
yum groupinstall "Development Tools"
yum install httpd build-essential gcc bzip bison pkgconfig glib-devel glib2-devel httpd-devel libpng-devel libX11-devel freetype fontconfig pango-devel ruby ruby-rdoc gtkhtml38-devel wget

cd /usr/src/
wget http://ftp.novell.com/pub/mono/sources/mono/mono-2.6.1.tar.bz2
tar jxvf mono-2.6.1.tar.bz2
cd mono-2.6.1/
./configure --prefix=/usr
make
make install
cd ../
从SVN版本库安装fastcgi-mono-server,按下面代码操作
export PKG_CONFIG_PATH=/usr/lib/pkgconfig/:/usr/lib/
yum install subversion
cd /usr/src/
svn co http://mono-soc-2007.googlecode.com/svn/trunk/brian/FastCgi/ fastcgi-mono-server
cd fastcgi-mono-server/
./autogen.sh
make
make install
cd ../
以FastCGI方式启动fastcgi-mono-server2,监听本机的9001端口,网页根目录为/usr/share/nginx/html:
nohup /bin/sh /usr/local/bin/fastcgi-mono-server2 /socket=tcp:9001 /root=/usr/share/nginx/html 2>&1 > /dev/null &

Nginx与ASP.NET(FastCGI+Mono)的配置

nginx.conf配置文件如下:
user  nobody;
worker_processes  1;

error_log  /var/log/nginx/error.log  crit;
pid        /var/run/nginx/nginx.pid;

events {
    worker_connections  51200;
    use epoll;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile       on;
    tcp_nopush     on;

    keepalive_timeout  65;
    tcp_nodelay    on;

    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain text/css text/xml application/x-javascript application/atom+xml application/rss+xml;
    gzip_vary on;
    server_name_in_redirect off;
    
    
    server_names_hash_bucket_size 128;
    client_header_buffer_size 128k;
    large_client_header_buffers 4 128k;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    include /etc/nginx/conf.d/*.conf; 
}
新建一个虚拟主机配置文件
vi /etc/nginx/conf.d/apsnettest.conf
内容如下:
server
  {
    listen       80;
    server_name  apsnettest.15099.net;
    index index.html index.htm index.aspx default.aspx;
    root  /usr/share/nginx/html;  
                             
    location ~ \.(aspx|asmx|ashx|asax|ascx|soap|rem|axd|cs|config|dll)?$ {
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;

 fastcgi_cache cache_one;
        fastcgi_cache_valid  200 10m;
        fastcgi_cache_valid  301 302 1h;
        fastcgi_cache_valid  any 1m;
        fastcgi_cache_key 127.0.0.1:9000$request_uri;

    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      1h;
    }    

    access_log  off;
    }
}
在上面虚拟主机配置文件中,静态HTML网页、图片、JS、CSS、Flash等使用Nginx来处理,以便得到更快的速度,文件扩展名为:.aspx .asmx .ashx .asax .ascx .soap .rem .axd .cs .config .dll的请求,由Nginx交给fastcgi-mono-server2进程处理。
启动Nginx:
/usr/sbin/nginx -c /etc/nginx/nginx.conf
启动Nginx,在/usr/share/nginx/html目录下下载info.apsx的ASP.NET探针文件,以检查ASP.NET程序能否正常运行:
cd /usr/share/nginx/html
wget http://aspnetsysinfo.googlecode.com/files/aspnetsysinfo-revision_23.zip
unzip aspnetsysinfo-revision_23.zip
通过游览器访问http://apsnettest.15099.net/info.aspx,如果一切正常,则显示的内容如下图(只截了部分内容):
在美国 Linux VPS配置nginx 通过fastcgi+mono代理访问asp.net程序

【apache】在美国VPS apache 增加cache缓存模块

参考资料:
http://hi.baidu.com/%CE%E2_%F0%A9/blog/item/382e4e830067209bf603a6c9.html

官方模块参考链接:http://httpd.apache.org/docs/2.1/mod/mod_cache.html

【apache】在美国VPS apache 增加expires过期模块

美国VPS 通过yum命令安装好apache后,如何启用apache2.x的压缩模块expires呢?

方法一:

首先在配置文件/etc/http/conf/http.conf下找到下面一行,将注释#去掉
LoadModule expires_module modules/mod_expires.so
然后添加下面语句
<FilesMatch "\.(gif|jpg|js|css)$">
ExpiresDefault "access plus 30 days"
</FilesMatch>
在虚拟主机栏里增加:
<virtualhost 64.120.190.93:80>
ServerAdmin test@15099.net
DocumentRoot /var/www/html/test
ServerName test.15099.net
ExpiresActive on
</virtualhost>
最后重启apache

方法二:

首先在配置文件/etc/http/conf/http.conf下找到下面一行,将注释#去掉
LoadModule expires_module modules/mod_expires.so
然后在网站的目录下新建.htaccess,添加如下内容:
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/gif A2592000
  ExpiresByType image/jpeg A2592000
  ExpiresByType image/png A2592000
  ExpiresByType image/x-icon A2592000
  ExpiresByType application/x-javascript A604800
  ExpiresByType text/css A604800
  </IfModule> 
ExpiresByType 是通过MIME类型来设置具体文件的缓存时间,A表示访问,A后面的数字表示访问后的缓存时间。
最后重启apache
备注:使用第二种方法,需要开启APACHE支持.htaccess

【apache】如何让APACHE支持.htaccess

如何让美国VPS APACHE服务器支持".htaccess"呢?其实只要简单修改一下apache的httpd.conf设置就可以让APACHE支持.htaccess了,具体操作如下:
打开httpd.conf文件,找到如下内容

<Directory />
  Options FollowSymLinks
AllowOverride None
</Directory>
改为:
<Directory />
  Options FollowSymLinks
AllowOverride All
</Directory>
重启apache就ok了。

【apache】在美国VPS apache 增加deflate压缩模块

美国VPS 通过yum命令安装好apache后,如何启用apache2.x的压缩模块Deflate呢?

方法一:

首先在配置文件/etc/http/conf/http.conf下找到下面一行,将注释#去掉
LoadModule deflate_module modules/mod_deflate.so
然后添加下面语句
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php text/css application/x-javascript
在虚拟主机栏里增加:
<virtualhost 64.120.190.93:80>
ServerAdmin test@15099.net
DocumentRoot /var/www/html/test
ServerName test.15099.net
SetOutputFilter DEFLATE
</virtualhost>
最后重启apache

方法二:

首先在配置文件/etc/http/conf/http.conf下找到下面一行,将注释#去掉
LoadModule deflate_module modules/mod_deflate.so
然后在网站的目录下新建.htaccess,添加如下内容:
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
</IfModule>
最后重启apache
备注:使用第二种方法,需要开启APACHE支持.htaccess

【nginx】在VPS(centos)源码安装nginx

美国VPS(centos vps)上源码安装nginx 最新稳定版
系统预环境配置

yum -y update
yum -y install gcc gcc-c++ autoconf automake
安装模块依赖包
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

下载最新稳定nginx版
cd /usr/src/
wget "http://nginx.org/download/nginx-0.7.67.tar.gz"
tar zxvf nginx-0.7.67.tar.gz
cd nginx-0.7.67
预编译nginx
./configure \
  --prefix=/usr \
  --sbin-path=/usr/sbin/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_gzip_static_module \
  --http-log-path=/var/log/nginx/access.log \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ 
跟多的预编译选项请使用./configure --help查看
修改配置文件
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
vi /etc/nginx/nginx.conf
内容如下:
user  nobody;
worker_processes  1;

error_log  logs/error.log  crit;
pid        /var/run/nginx/nginx.pid;

events {
    worker_connections  51200;
    use epoll;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  65;
    tcp_nodelay    on;

    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain text/css text/xml application/x-javascript application/atom+xml application/rss+xml;
    gzip_vary on;
    server_name_in_redirect off;
    include /etc/nginx/conf.d/*.conf; 
    
    server_names_hash_bucket_size 128;
    client_header_buffer_size 128k;
    large_client_header_buffers 4 128k;

}

增加默认网站配置文件:
mkdir -p /etc/nginx/conf.d
vi /etc/nginx/conf.d/http.conf
内容如下:
server {
        listen       80 default;
        server_name  _;

        access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page  404              /404.html;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
 location /i/ { alias /usr/html/abc/; }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        
        location ~ \.php$ {
            proxy_pass   http://127.0.0.1;     #此条语句可以把php请求转发到apache处理,需要在apache那边配置虚拟主机
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
新建 /var/tmp/nginx/client/文件夹
mkdir -p /var/tmp/nginx/client/    #指定http客户端请求缓存文件存放目录的路径
启动nginx
/usr/sbin/nginx -t    #启动前测试一下配置文件是否正确
/usr/sbin/nginx -c /etc/nginx/nginx.conf

【openvpn】在VPS配置openvpn(debian5)

参考资料:
http://library.linode.com/networking/vpn-services/openvpn-debian-5-lenny
http://rashost.com/blog/centos-openvpn-install

【bash】在美国VPS检测系统负载脚本

美国VPS上检测系统负载脚本,首先

#vi /usr/src/detection-linux-system-load.sh
内容如下:
#!/bin/bash
cputotal=`head -1 /proc/stat |awk '{print $2+$3+$4+$5}'`
cpunow=`head -1 /proc/stat |awk '{print $2+$3+$4}'`
memtotal=`free  -m |sed -n '/Mem/p'|awk '{print $2}'`
memnow=`free  -m |sed -n '/Mem/p'|awk '{print $3}'`
cpuused=`gawk -v x=$cpunow -v y=$cputotal 'BEGIN{printf "%.5f",x * 100/y}'`
memused=`gawk -v x=$memnow -v y=$memtotal 'BEGIN{printf "%.5f",x * 100/y}'`
case "$1" in
  cpu)
        echo $cpuused
        ;;
  mem)
        echo $memused
        ;;
  clu)
        size=`(stat $2 | grep Size |awk '{print $2}')`
        num=`(stat $2 | grep Size |awk '{print $4}')`
        block=`expr $size / $num`
        echo $block
        ;;
  *)
        echo "it used cpu;mem;clu"
        ;;
esac
运行:
# sh /usr/src/detection-linux-system-load.sh cpu
或
# sh /usr/src/detection-linux-system-load.sh mem
或
# sh /usr/src/detection-linux-system-load.sh clu /etc/my.cnf

【ssh】限制用户单点登录SSH

限制用户单点登录SSH,也就是限制某个SSH账号连接服务器的最大连接数为1
主要用途:1.安全 2.防止SSH账号被滥用
方法一:使用pam限制
PAM是这个好东东哈,用户管理真是太方便了
首先让/etc/pam.d/sshd连接pam_limits.so
添加下面这行至/etc/pam.d/sshd

session required pam_limits.so
接着添加下面一行至/etc/security/limits.conf,实现用户vpstest单点登录SSH,后登录的会话失败.
vpstest - maxlogins 1
接着重启服务器,光重启sshd服务是不行的.
注:SSH证书登陆不受影响,SSH密码登录有效.
方法二:使用登录属性
vi /etc/profile
内容如下:
if [ $(w | grep $USER | wc -l) -gt 1 ]; then
        exit
fi