“vps应用”目录存档

在vps主机上配置防ping的方法

2009年02月25日,星期三
  1. 在/etc/rc.d/rc.local最后添加 echo “1″ >  /proc/sys/net/ipv4/icmp_echo_ignore_all  语句,将其值改为1后为禁止PING
    将其值改为0后为解除禁止PING
  2. 使用iptable最简单 0是echo-reply,8是echo-request禁止出去的icmp echo-request  意义不是很大
    iptables -A OUTPUT -p icmp –icmp-type echo-request -j DROP
    或者
    iptables -A OUTPUT -p icmp –icmp-type 8 -j DROP

    允许客户端的ping
    iptables -I INPUT -i eth0 -p icmp -s 0/0 -d 0/0 -j ACCEPT

    禁止客户端的ping

    iptables -I INPUT -i eth0 -p icmp -s 0/0 -d 0/0 -j DROP

    允许出去的ping 请求
    SERVER_IP=”202.54.10.20″
    iptables -A OUTPUT -p icmp –icmp-type 8 -s $SERVER_IP -d 0/0 -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT

    iptables -A INPUT -p icmp –icmp-type 0 -s 0/0 -d $SERVER_IP -m state –state ESTABLISHED,RELATED -j ACCEPT

在vps主机上mysql数据库优化

2009年01月13日,星期二

概述:在linux vps主机上配置mysql数据库,由于默认使用yum安装的数据库启动了InnoDB引擎,同时其/etc/my.cnf配置都我们的vps主机不是很适合,本文详细讲解如何配置适合自己vps主机的mysql配置文件

目的:优化vps主机上的mysql数据库,使之更合适vps主机这样的环境

query_cache_size = 268435456
query_cache_type=1
query_cache_limit=1048576

查看mysql-server静态参数值命令
mysql>show variables;
或者mysqladmin -uroot variables
mysql服务器的参数很多,如果需要了解某个参数的详细定义,可以使用mysqld –verbose –help | more
查看mysql-server动态状态信息命令

mysql>show status;

或者mysqladmin -uroot status
其中show status分为show [session|global]status;可以根据需要加上参数“session”或者”global”来显示session级(当前统计)的统计结果和global级(自数据库上次启动至今)的统计结果,如果不写,默认为”session”

1、查看和修改默认的存储引擎,关闭不需要的存储引擎
在我们使用vps主机过程中,很多用户只使用MyISAM一个引擎,关闭那么没有使用的InnoDB MEMORY等其他引擎
查看当前系统有哪些引擎

mysql>SHOW ENGINES \G
或者第二种方法
mysql>SHOW VARIABLES LIKE 'have%';

查看默认引擎

mysql> show variables like 'table_type';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| table_type    | MyISAM |
+---------------+--------+
1 row in set (0.00 sec)
或者
mysql> show variables like 'storage_engine';
+----------------+--------+
| Variable_name  | Value  |
+----------------+--------+
| storage_engine | MyISAM |
+----------------+--------+
1 row in set (0.00 sec)

mysql默认的存储引擎是MyISAM,修改默认的存储引擎可以修改/etc/my.cnf参数文件,在[mysqld]字段里面增加default-storage-engine=innodb,这里假设设置默认为innodb,根据自己的需要进行设置,关闭不需要的存储引擎,可以修改/etc/my.cnf参数文件,在[mysqld]字段里面增加–skip-innodb。
2、调节key_buffer_size大小

mysql> show variables like 'key_buffer_size';
+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| key_buffer_size | 402653184 |
+-----------------+-----------+
1 row in set (0.00 sec)
 
mysql>
从上面可以看到,key_buffer_size为:384M,可以修改/etc/my.cnf参数文件,在[mysqld]字段里面增加key_buffer_size = 384M,当然也可以使用mysql>set grobal key_buffer_size=512M修改。
此参数是用来<strong>设置索引块</strong>(Index Blocks)缓存的大小,它被所有的线程共享,只适合MyISAM存储引擎。

3、调节table_cache设置
这个参数表示数据库用户打开表的缓存数量,每个连接进来,都会至少打开一个表缓存,如此,table_cache与max_connections有关,
查看当前的table_cache值

mysql> show variables like 'table_cache';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| table_cache   | 4096  |
+---------------+-------+
1 row in set (0.00 sec)

从上面可以看到,table_cache为:4096,可以修改/etc/my.cnf参数文件,在[mysqld]字段里面增加table_cachee = 4096

4、调节query_cache设置

Query Cache 在提高数据库性能方面具有非常重要的作用,其设定也非常简单,仅需要在配置文件写入两行: query_cache_type 和 query_cache _size,而且 MySQL 的 query cache 非常快!而且一旦命中,就直接发送给客户端,节约大量的 CPU 时间。

当然,非 SELECT 语句对缓冲是有影响的,它们可能使缓冲中的数据过期。一个 UPDATE 语句引起的部分表修改,将导致对该表所有的缓冲数据失效,这是 MySQL 为了平衡性能而没有采取的措施。因为,如果每次 UPDATE 需要检查修改的数据,然后撤出部分缓冲将导致代码的复杂度增加。

query_cache_type :0 代表不使用缓冲, 1 代表使用缓冲,2 代表根据需要使用。

设置 1 代表缓冲永远有效,如果不需要缓冲,就需要使用如下语句:

SELECT SQL_NO_CACHE * FROM my_table WHERE …

如果设置为 2 ,需要开启缓冲,可以用如下语句:

SELECT SQL_CACHE * FROM my_table WHERE …

用 SHOW STATUS 可以查看缓冲的情况:

mysql> show status like 'Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_queries_in_cache | 8 |
| Qcache_inserts | 545875 |
| Qcache_hits | 83951 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 2343256 |
| Qcache_free_memory | 33508248 |
| Qcache_free_blocks | 1 |
| Qcache_total_blocks | 18 |
+-------------------------+----------+
8 rows in set (0.00 sec)

如果需要计算命中率,需要知道服务器执行了多少 SELECT 语句:

mysql> show status like 'Com_sel%';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| Com_select | 2889628 |
+---------------+---------+
1 row in set (0.01 sec)

在本例中, MySQL 命中了 2,889,628 条查询中的 83,951 条,而且 INSERT 语句只有 545,875 条。因此,它们两者的和和280万的总查询相比有很大差距,因此,我们知道本例使用的缓冲类型是 2 。

而在类型是 1 的例子中, Qcache_hits 的数值会远远大于 Com_select 。 Qcache_not_cached是可以记录DML语句的数量的

在vps主机配置Lighttpd+php5+mysql环境

2008年12月30日,星期二

概述:是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,本文详细讲解如何在vps主机下配置Lighttpd+php5+mysql环境
环境:centos5 特惠型vps主机

步骤:

1、安装数据库

yum remove httpd   < --我们的vps主机一般默认已经安装了httpd服务,所以我这里先卸载掉httpd
yum -y install mysql-server
chkconfig --level 235 mysqld on
/etc/init.d/mysqld start
mysqladmin -u root password yourrootsqlpassword    <--修改默认的管理员帐号密码,这里的yourrootsqlpassword 请使用自己想的秘密代替
mysqladmin -h server1.example.com -u root password yourrootsqlpassword

2、安装lighttpd

yum install yum-priorities  < --安装yum库优先包,是系统自带的包优先
rpm -Uvh http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm <--安装有lighttpd包的库
yum -y install lighttpd
chkconfig --level 235 lighttpd on   <--设置开启启动
/etc/init.d/lighttpd start

(全文...)

在vps主机快速布置nginx+php+mysql环境

2008年12月29日,星期一

概述:使用vps的朋友可以都知道,nginx是一款高性能的web服务器。本文基于我们的linux vps特惠型 centos5系统上使用yum快速配置nginx+php+mysql环境,同时也使用yum安装eaccelerator加速模块和memcache缓存模块

环境:linux vps特惠型 操作系统:centos5.2

步骤:

1、安装数据库

yum remove httpd  < --我们的vps主机一般默认已经安装了httpd服务,所以我这里先卸载掉httpd
yum -y install mysql-server
chkconfig --level 235 mysqld on
/etc/init.d/mysqld start

2、安装nginx

yum install yum-priorities   < --安装yum库优先包,是系统自带的包优先
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm  <--安装有nginx包的库
yum -y install nginx
chkconfig --level 235 nginx on   < --设置开启启动
/etc/init.d/nginx start

(全文...)

在vps主机上配置Python支持功能

2008年12月25日,星期四

概述:在centos5使用yum安装httpd,如果需要添加对python程序的支持,可以安装mod_python支持,本文详细讲解如何配置apache支持python的.py支持。
环境:centos5 特惠vps主机

步骤:

1、使用yum命令安装mod_python模块

yum -y install mod_python

2、让配置让apache配置文件

cp /etc/httpd/conf.d/python.conf /etc/httpd/conf.d/python.conf_orig
cat /dev/null > /etc/httpd/conf.d/python.conf
vi /etc/httpd/conf.d/python.conf
LoadModule python_module modules/mod_python.so
 
<directory /var/www/html/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride None
  Order allow,deny
  allow from all
  AddHandler mod_python .py
  PythonHandler mod_python.publisher
  PythonDebug On

3、重启httpd

/etc/init.d/httpd restart

4、测试python是否启用
vi /var/www/html/test.py

def index(req):
  return "Test successful";

保存后使用游览器访问:http://你的vps主机ip地址/test.py ,如果看到Test successful 就代表配置成功。

VPS主机下nginx环境安装wordpress重写(rewrite)

2008年12月20日,星期六

概述:wordpress可以很方便的重写(Rewrite),但是在nginx需要在nginx站点配置文件里,下面是我针对wordpress写的配置文件

server
{
  listen       80;
  server_name  vps.15099.net;
  index index.html index.htm index.php;
  root  /data0/htdocs/vps;
 
  #limit_conn   crawler  20;
 
 # 重写代码开始
  location / {
        index index.html index.php;
        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }
    }
  #重写代码结束
 
  location ~ .*\.(php|php5)?$
  {
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    #fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.conf;
  }
 
  # Blog more pictures, less change, they will be in the local browser cache 15 days, you can improve the next time I open the blog page loading speed
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  {
    expires      15d;
  }
 
  #Blog will be a lot of load javascript, CSS, they will be in the local browser cache 1 day, to improve the speed of page display
  location ~ .*\.(js|css)?$
  {
    expires      1d;
  }
 
 }