Skip to content


Linux Top命令翻页方法

一直以为Top是没有翻页的,汗~

Shift+< Shift+>

========================================
问了下man是这这么说的,确实不是翻页…
´<´ :Move_Sort_Field_Left Moves the sort column to the left unless the current sort field is the first field being displayed. ´>´ :Move_Sort_Field_Right
Moves the sort column to the right unless the current sort field is the last field being displayed.

Posted in Linux 命令, 技术.

Tagged with .


搜狐开源镜像上线

继网易在今年二月启动开源项目镜像之后(http://mirrors.163.com/),现在国内的另一家门户网站搜狐也上线了开源镜像站。浏览该站点,其中镜像的项目包括 Arch Linux、CentOS、Debian、Fedora、Gentoo、Ubuntu 等 Linux 发行版,同时也包括 FreeBSD、OpenBSD 等 BSD 版本
http://mirrors.sohu.com

页底红色的”Coming soon“字样提示目前尚未同步完毕,各位仍需稍作等待方能投入使用。

CentOs5 目前还没有…

Posted in LINUX, 技术.

Tagged with .


SSH,telnet终端中文显示乱码解决办法 (CentOS 5.2 )


vi /etc/sysconfig/i18n


LANG=”en_US.UTF-8″
SYSFONT=”latarcyrheb-sun16″

修改原内容为

LANG=”zh_CN.GB18030″
LANGUAGE=”zh_CN.GB18030:zh_CN.GB2312:zh_CN”
SUPPORTED=”zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en”
SYSFONT=”lat0-sun16″

用yum安装中文字体

yum install fonts-chinese.noarch

断开ssh重新连

date

2009年 09月 21日 星期一 13:47:53 CST

Posted in linux 维护优化, 技术.

Tagged with .


[转]MySQL 的調校 (軟硬體、版本、設定)

 

把一些關於 MySQL 的資料整理一下。

初期的 MySQL 隨便跑沒關係,備份的部份記得要把 binlog 也一起備份起來,用 gzip 壓過後 (不使用 bzip2 或是高壓縮率參數,是因為考量解壓縮速度;另外推薦用 Parallel gzip 壓縮,速度比較快) 再用 openssl 加密丟到 Amazon S3 上。

成長後,買獨立伺服器要一次買兩台跑 HA,每台分別是:

  • CPU 要考量 SQL query 的方式,如果打算在 MySQL 做很多事情 (i.e. JOIN),CPU 要選高階的;如果大多都是 simple query,則以 C/P 值高的 CPU 優先:兩顆四核心 CPU 算是現在比較划算的硬體。不管哪一種,選低電壓的,像是 Intel Xeon L5408 或是 Intel Xeon L5520,因為硬碟蠻熱的,要減少熱量以免伺服器容易當掉。
  • 記憶體愈多愈好,64GB 算是還蠻基本的。
  • 硬碟選轉速快的 15krpm SAS,挑大一點的硬碟 (以現在的市場就是 300GB) 省得以後空間不夠要搬動。最好是硬體 RAID1+0,依照應用決定單台 database 要多大,如果預定八顆的話可以買 2U 來塞。

軟體的部份:

  • 一定要跑 Linux x86-64 版本,挑大的 distribution 以免遇到問題卻無法解決。我自己還蠻偏好用 Debian。不論是 Debian 還是其他 distribution,儘量跟穩定的 branch,遇到需要升級時的問題會比較少,像是 Debian Lenny
  • 如果要跑 DRBD,先在兩台上面設定好 Heartbeat + DRBD。如果是跑 MMM 的話就設定 MMM,比較需要注意的是 MMM 的版本,參考「MySQL MMM 的情況」。
  • Filesystem 跑 XFS,很多人在上面跑很久了,經過時間考驗的 Filesystem,跑起 MySQL InnoDB 的效率還不錯。
  • MySQL 跑 Percona 的 5.0 標準版本 (非 highperf 版),穩定性還不錯。如果預期到資料量很大的時候會是 I/O bound,可以考慮 Percona 的 5.1 版本,並且開啟 InnoDB Plugin 壓縮的功能。
  • 跑監控程式,把系統的狀態記錄下來。可以是 MuninCacti 或是 nagios,資料對於瓶頸分析很重要。

my.cnf 設定的部份要花不少功夫,除了一般常見的設定外 (這部份網路上很多文件),有些在站台比較大時會發生的問題要注意:

  • back_log 要開大,因為站台大的時候通常不會用 pconnect (每個 web server 都掛著 64 個連線,當有十台 web server 就佔用 640 個連線),而是用 connect,在每次做完事情就斷線,配合 memcached 降低 MySQL 的需求。不過在量夠大的時候,還是會遇到預設的 back_log 不夠。Smugmug 的 CEO 在「Great things afoot in the MySQL community」有提到吃過這個值的虧。
  • max_allowed_packet 設大一點,避免比較大的 INSERT 或是 UPDATE 造成錯誤。通常這是設計上的問題,應該要避免在 MySQL 裡放 blob 資料,不過偶而還是會需要…
  • max_connect_errors 設 4294967295,可以避免當 client (像是 php) 發生太多錯誤時被 block 住。
  • innodb_adaptive_checkpoint 要打開,可以避免在 flush dirty pages 的時候產生 slow query。MySQL 官方的版本沒有這個參數,而這個參數也是為什麼要用 Percona 版本之一。效果可以參考「Adaptive checkpointing」這篇文章。

 

原文http://blog.gslin.org/archives/2009/09/13/2088/

Posted in Mysql, 技术.

Tagged with , .


2009年9月语言排行榜:php超越c++第一次进入前三

 

The TIOBE Programming Community index gives an indication of the popularity of programming languages. The index is updated once a month. The ratings are based on the number of skilled engineers world-wide, courses and third party vendors. The popular search engines Google, MSN, Yahoo!, Wikipedia and YouTube are used to calculate the ratings. Observe that the TIOBE index is not about the best programming language or the language in which most lines of code have been written.

The index can be used to check whether your programming skills are still up to date or to make a strategic decision about what programming language should be adopted when starting to build a new software system. The definition of the TIOBE index can be found here.

Position
Sep 2009
Position
Sep 2008
Delta in Position Programming Language Ratings
Sep 2009
Delta
Sep 2008
Status
1 1 Java 19.383% -1.33%   A
2 2 C 16.861% +1.48%   A
3 5 PHP 10.156% +0.91%   A
4 3 C++ 9.988% -0.73%   A
5 4 (Visual) Basic 9.196% -1.29%   A
6 7 Perl 4.528% -0.31%   A
7 8 C# 4.186% -0.15%   A
8 6 Python 3.930% -1.08%   A
9 9 JavaScript 2.995% -0.14%   A
10 11 Ruby 2.377% -0.38%   A
11 10 Delphi 1.972% -1.08%   A
12 18 Pascal 0.961% +0.56%   A
13 16 Lisp/Scheme 0.842% +0.42%   A–
14 13 PL/SQL 0.819% +0.12%   A
15 14 SAS 0.781% +0.14%   A
16 24 ABAP 0.705% +0.42%   A
17 12 D 0.588% -0.68%   B
18 42 Objective-C 0.585% +0.48%   B
19 17 Lua 0.507% +0.09%   B
20 25 MATLAB 0.506% +0.25%   B

 

Long term trends

The long term trends for the top 10 programming languages can be found in the line diagram below.

 

Posted in 其它, 分析报告.

Tagged with , .


配置一个内网网卡

先查看下网卡

ifconfig


eth0 ……外网
lo ……回路

启用第二块网卡做内网

ifconfig eth1 up
ifconfig eth1 192.168.0.11 netmask 255.255.0.0

这样就可以使用了,但重启网络或机器后配置就会失效

想要不失效就需写的文件里

vi etc/sysconfig/networking/profiles/default/ifcfg-eth1


DEVICE=eth1
BOOTPROTO=static
HWADDR=00:44:88:6C:3C:88
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.0.11
TYPE=Ethernet

Posted in linux 维护优化, 技术.

Tagged with .


Will not restore a file with more than one hard link (/etc/resolv.conf) No such file or directory

centos 5.2系统

tail /var/log/messages

Sep 7 18:04:31 bora ntpd[4063]: synchronized to 220.130.158.71, stratum 2
Sep 7 18:35:57 bora restorecond: Will not restore a file with more than one hard link (/etc/resolv.conf) No such file or directory

解决方法

$ ls -i /etc/resolv.conf #get inode
16711694 /etc/resolv.conf
$ sudo find /etc -inum 16711694#find hard link
Password:
/etc/sysconfig/networking/profiles/default/resolv.conf
/etc/resolv.conf
$ sudo /usr/sbin/lsof|grep resolv.conf #make sure it is not open
$ sudo rm /etc/sysconfig/networking/profiles/default/resolv.conf #delete
$ sudo restorecon /etc/resolv.conf
$ sudo ln /etc/resolv.conf /etc/sysconfig/networking/profiles/default/resolv.conf #recreate hard link

参考:
http://www.centos.org/modules/newbb/print.php?form=1&topic_id=17009&forum=37&order=ASC&start=0
http://forums.fedoraforum.org/showthread.php?t=159533

Posted in linux 维护优化, 技术.

Tagged with .


中国互联网络连接带宽图 数据截至日期:2008年12月31日

中国互联网络连接带宽图
数据来源CNNIC,他首页链接上的还是05年的。。。

详情:http://stats.cnnic.cn:8080/isp/statics.jsp?isp_date=2008-12-31

Posted in 其它, 分析报告.

Tagged with .


Nginx 0.7.x + PHP 5.2.10 +Mysql 5.1.37 on CentOs 5.2

系统环境
CentOs 5.2
Linux bora 2.6.18-128.el5 #1 SMP Wed Jan 21 10:41:14 EST 2009 x86_64 x86_64 x86_64 GNU/Linux

一、升级开源组件
1.利用CentOS Linux系统自带的yum命令安装、升级所需的程序库

sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2.下载相关软件
A.创建一个下载列表

vi lemp0.7.6_down_list.txt


http://sysoev.ru/nginx/nginx-0.7.61.tar.gz
http://www.php.net/get/php-5.2.10.tar.gz/from/this/mirror
http://php-fpm.org/downloads/php-5.2.10-fpm-0.5.13.diff.gz
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.37.tar.gz/from/http://mysql.he.net/
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.tar.gz
“http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0”
“http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0”
http://pecl.php.net/get/memcache-2.2.5.tgz
“http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0”
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
http://pecl.php.net/get/imagick-2.2.2.tgz

B.下载

wget -i lemp0.7.6_down_list.txt

3.安装iconv

tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure –prefix=/usr/local
make
make install
cd ../

4.安装libmcrypt

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure –enable-ltdl-install
make
make install
cd ../../

5.安装mhash

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

6.安装mcrypt

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../

错误

checking for libmcrypt – version >= 2.5.0…
*** ‘libmcrypt-config –version’ returned 2.4.0, but LIBMCRYPT (2.5.8)
*** was found! If libmcrypt-config was correct, then it is best
*** to remove the old version of LIBMCRYPT. You may also be able to fix the error
*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing
*** /etc/ld.so.conf. Make sure you have run ldconfig if that is
*** required on your system.
*** If libmcrypt-config was wrong, set the environment variable LIBMCRYPT_CONFIG
*** to point to the correct copy of libmcrypt-config, and remove the file config.cache
*** before re-running configure
configure: error: *** libmcrypt was not found

解决方法

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

二、安装mysql
1.添加用户及用户组

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql -d /dev/null -s /sbin/nologin

2.编译mysql

tar zxvf mysql-5.1.37.tar.gz
cd mysql-5.1.37/

CFLAGS=”-O3″ CXX=gcc CXXFLAGS=”-O3 -felide-constructors -fno-exceptions -fno-rtti” ./configure –prefix=/opt/mysql –localstatedir=/opt/mysql/var –sysconfdir=/opt/mysql –with-unix-socket-path=/opt/mysql/mysql.sock –with-charset=gbk –with-collation=gbk_chinese_ci –with-extra-charsets=gbk,gb2312,utf8 –with-client-ldflags=-all-static –with-mysqld-ldflags=-all-static –enable-assembler –without-debug –with-big-tables –with-readline –with-ssl –with-pthread –enable-thread-safe-client –with-embedded-server –enable-local-infile –with-plugins=innobase
make
make install

3.copy配置文件

#512M内存和web共用
cp support-files/my-medium.cnf /opt/mysql/my.cnf
#2G内存和web共用
#cp support-files/my-large.cnf /opt/mysql/my.cnf
#删除默认的my.cnf
rm /etc/my.cnf

4.初始数据库

/opt/mysql/bin/mysql_install_db –defaults-file=/opt/mysql/my.cnf –basedir=/opt/mysql –datadir=/opt/mysql/var –user=mysql –pid-file=/opt/mysql/var/mysql.pid –skip-locking –socket=/opt/mysql/mysql.sock

5.设置文件夹属主

chmod +w /opt/mysql
chown -R mysql:mysql /opt/mysql

cd ..
chgrp website /opt/mysql/my.cnf
chmod 0664 /opt/mysql/my.cnf

6.启动文件及自动启动

cp support-files/mysql.server /opt/mysql/bin/
chmod 755 /opt/mysql/bin/mysql.server

#A.自动启动
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig –add mysql
#某些linux上
#chkconfig –level 345 mysql on
#开启服务
/etc/init.d/mysql start
#关闭服务
#/etc/init.d/mysql stop

#B.脚本启动
#我这里使用lemp脚本启动。
#lemp脚本见下方

7.修改mysql root密码

#123456为密码
/opt/mysql/bin/mysqladmin -uroot password 123456
#测试密码
/opt/mysql/bin/mysql -uroot -p
Enter password:

8.编辑my.cnf

vi /opt/mysql/my.cnf

关闭log_bin
将log-bin=mysql-bin注释掉,需要热备份或主从服务器的可以保留,开启后会占很多空间
开启innodb
将innodb开头的注释去掉,除了innodb_log_arch_dir参数,开启它将无法启动msyql
修改完成后重启mysql服务

三、安装php
1.编译php

tar zxvf php-5.2.10.tar.gz
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1
cd php-5.2.10/
./configure –prefix=/opt/php –with-config-file-path=/opt/php/etc –with-mysql=/opt/mysql –with-mysqli=/opt/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –enable-xml –enable-zend-multibyte –disable-debug –disable-ipv6 –without-pear
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-dist /opt/php/etc/php.ini

这个版本的php有个bug,带上pear时会出错

Fatal error: Error: cannot open phar “/home/andychu/lemp/php-5.2.10/pear/install-pear-nozlib.phar” in /home/andychu/lemp/php-5.2.10/pear/install-pear-nozlib.phar on line 795

2.手动安装pear

cd /opt/php/
curl http://pear.php.net/go-pear | /opt/php/bin/php

3.安装memcache

tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/opt/php/bin/phpize
./configure –with-php-config=/opt/php/bin/php-config
make
make install
cd ..

4.安装eaccelerator

tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/opt/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/opt/php/bin/php-config
make
make install
cd ..

5.安装PDO_MYSQL

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/opt/php/bin/phpize
./configure –with-php-config=/opt/php/bin/php-config –with-pdo-mysql=/opt/mysql
make
make install
cd ../

6.安装ImageMagick

tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../

7.安装imagick

tar zxvf imagick-2.2.2.tgz
cd imagick-2.2.2/
/opt/php/bin/phpize
./configure –with-php-config=/opt/php/bin/php-config
make
make install
cd ../

8.编辑php.ini

mkdir -p /opt/php/eaccelerator_cache
vi /opt/php/etc/php.ini

  手工修改:查找/opt/php/etc/php.ini中的extension_dir = “./”
  修改为extension_dir = “/opt/php/lib/php/extensions/no-debug-non-zts-20060613/”
  并在此行后增加以下几行,然后保存:
  extension = “memcache.so”
  extension = “pdo_mysql.so”
  extension = “imagick.so”

  再查找output_buffering = Off
  修改为output_buffering = On

9.配置eAccelerator加速PHP
按shift+g键跳到配置文件的最末尾,加上以下配置信息:

[eaccelerator]
zend_extension=”/opt/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/opt/php/eaccelerator_cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″

10.创建web用户

/usr/sbin/groupadd website
/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -g website www -d /dev/null -s /sbin/nologin
mkdir -p /opt/htdocs/www/nginx
chmod -R 0775 /opt/htdocs/
chown -R www:website /opt/htdocs/

11.创建php-fpm配置文件
(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/opt/php/etc/目录中创建php-fpm.conf文件:

rm -f /opt/php/etc/php-fpm.conf
vi /opt/php/etc/php-fpm.conf

和原始配置文件的差别

用户组->www
max_children=64
MaxApareServers=250
rlimit_files=51200
max_requests=51200
去掉注释

12.优化文件句柄并开启php

ulimit -SHn 51200
/opt/php/sbin/php-fpm start

#/opt/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。

四、安装nginx
1.pcre

tar zxvf pcre-7.9.tar.gz
cd pcre-7.9/
./configure –enable-utf8 –enable-unicode-properties
make && make install
cd ../

2.nginx

tar zxvf nginx-0.7.61.tar.gz
cd nginx-0.7.61/

A关闭debug模式来减少nginx大小
http://bianbian.org/technology/271.html

du /opt/nginx/sbin/nginx
#未做优化时的大小
1712 /opt/nginx/sbin/nginx
#优化后的大小
404 /opt/nginx/sbin/nginx
vi auto/cc/gcc
# 最后几行sheft+g
#注释这行
#CFLAGS=”$CFLAGS -g”

B伪装header

vi src/core/nginx.h
#define NGINX_VERSION “1.0”
#define NGINX_VER “C1GWS/” NGINX_VERSION

C编译

./configure –user=www –group=website –prefix=/opt/nginx –with-http_stub_status_module –with-http_ssl_module
make
make install
cd ../

3.修改权限

chown -R www:website /opt/nginx/logs/
chmod -R 0775 /opt/nginx/logs/
chown -R www:website /opt/nginx/conf/
chmod -R 0775 /opt/nginx/conf/

4.创建Nginx配置文件

rm -f /opt/nginx/conf/nginx.conf
vi /opt/nginx/conf/nginx.conf

示例为discuz7的配置

user www website;

worker_processes 8;

error_log /var/log/nginx/nginx_error.log crit;

pid /dev/shm/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
{
use epoll;

worker_connections 51200;
}

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

log_format access ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_body_timeout 60;
client_max_body_size 8m;

#linux 2.4+
sendfile on;
tcp_nopush on;
tcp_nodelay on;

server_name_in_redirect off;

keepalive_timeout 60;

fastcgi_intercept_errors on;
fastcgi_hide_header X-Powered-By;
fastcgi_connect_timeout 180;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128K;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_temp_path /dev/shm;

gzip on;
gzip_min_length 1k;
gzip_comp_level 5;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css application/xml;

limit_zone one $binary_remote_addr 10m;

server
{
listen 80;
server_name bbs.c1gstudio.com;
index index.html index.htm index.php;
root /opt/htdocs/www;
error_page 404 403 /404.html;

location ~/\.ht {
deny all;
}

location ~ /bbs/attachment\.php?$ {
include fcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
limit_conn one 1;
limit_rate 30k;
}

location ~ .*\.php?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

rewrite ^(.*)/archiver/((fid|tid)-[\w\-]+\.html)$ $1/archiver/index.php?$2 last;
rewrite ^(.*)/forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3 last;
rewrite ^(.*)/profile-(username|uid)-(.+)\.html$ $1/viewpro.php?$2=$3 last;
rewrite ^(.*)/space-(username|uid)-(.+)\.html$ $1/space.php?$2=$3 last;

location ~(favicon.ico) {
log_not_found off;
expires 99d;
break;
}
location ~(robots.txt) {
log_not_found off;
expires 7d;
break;
}

location ~* ^.+\.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {
valid_referers none blocked *.c1gstudio.com;
if ($invalid_referer) {
rewrite ^/ http://leech.c1gstudio.com/leech_bbs.gif;
return 412;
}
access_log off;
root /opt/htdocs/www;
expires 7d;
break;
}

access_log /var/log/nginx/bbs.c1gstudio.com.log access;
}

}

5.在/opt/nginx/conf/目录中创建fcgi.conf文件

vi /opt/nginx/conf/fcgi.conf


fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

6.nginx的日志滚动

mkdir 0775 /opt/shell
chgrp website /opt/shell
vi /opt/shell/nginx_log.sh


#!/bin/sh
log_dir=/var/log/nginx/logs
yesterday=`date +%Y%m%d`
lastday=`date +%Y%m%d -d ‘-1 month’`
/bin/rm ${log_dir}/access.${lastday}.log
/bin/rm ${log_dir}/nginx_error.${lastday}.log
/bin/mv ${log_dir}/access.log ${log_dir}/access.${yesterday}.log
/bin/mv ${log_dir}/nginx_error.log ${log_dir}/nginx_error.${yesterday}.log
kill -USR1 `cat /opt/nginx/nginx.pid`
/bin/gzip ${log_dir}/access.${yesterday}.log &
/bin/gzip ${log_dir}/nginx_error.${yesterday}.log &

7.在crontab里每日23:59时

59 23 * * * /bin/sh /opt/shell/nginx_log.sh > /dev/null 2>&1

8.启动nginx和php

/opt/php/sbin/php-fpm start
/opt/php/nginx/sbin/nginx

五、优化Linux参数
1.优化Linux内核参数

vi /etc/sysctl.conf


# Add
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535

2.优化文件句柄

vi /etc/security/limits.conf

文件尾部增加

* soft nofile 51200
* hard nofile 51200

设置为星号代表全局
这个当中的硬限制是实际的限制,而软限制,是warnning限制,只会做出warning。

重启软件
退出控制台后就生效

使配置立即生效:

/sbin/sysctl -p

六、自动启动nginx+php+mysql

vi /etc/rc.local

在末尾添加

ulimit -SHn 51200
/opt/lemp start

点此下载lemp 脚本

参考:
nginx+php(FCGI)+xcache+mysql on as4
http://blog.c1gstudio.com/archives/152

Nginx 0.7.x + PHP 5.2.10(FastCGI)搭建胜过Apache十倍的Web服务器
http://blog.s135.com/nginx_php_v5

===================
2009/11/2 更新
内核增加参数
net.ipv4.ip_conntrack_max = 262144 #8G内存64位配制
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 36000
参考:
http://www.wallfire.org/misc/netfilter_conntrack_perf.txt

===================
2010-3-24更新
安装Zend Optimizer
discuz中电子商备功能加密了代码需用此模块
安装Zend Optimizer最为简单,到Zend官方网站下载相应CPU的版本
http://www.zend.com/en/products/guard/downloads
文件夹下有个data目录,然后根据自己的php的版本选择合适的ZendOptimizer.so
然后把这个so加载到php.ini中。

tar zxvf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
cd ZendOptimizer-3.3.9-linux-glibc23-x86_64
cp data/5_2_x_comp/ZendOptimizer.so /opt/php/lib/php/extensions/no-debug-non-zts-20060613/

编辑配置文件php.ini加入

extension_dir = “/opt/php/lib/php/extensions/no-debug-non-zts-20060613/”
extension = “ZendOptimizer.so”


/opt/php-5.2.10/sbin/php-fpm: line 40: 28411 Segmentation fault $php_fpm_BIN –fpm $php_opts

tail /var/log/messages

Mar 25 10:12:50 c1g kernel: php-cgi[30784]: segfault at 00002b9ea63cdc60 rip 00002b9ea63cdc60 rsp 00007fff08c47cd0 error 14

注意如果同时使用eaccelerator,不要使用上面的方式,需将zend optimize放在eaccelerator的下面,让eaccelerator先启动
否则phpfpm的reload会失败,启动时也会报错.


[eaccelerator]
zend_extension=”/opt/php-5.2.10/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/opt/php-5.2.10/eaccelerator_cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=””
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″

[Zend]
zend_extension=”/opt/php-5.2.10/lib/php/extensions/no-debug-non-zts-20060613/ZendOptimizer.so”
zend_optimizer.enable_loader = 1
zend_optimizer.optimization_level=15
zend_optimizer.disable_licensing=0

/opt/php-5.2.10/bin/php -v

Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

重启php后在phpinfo中可以看到
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

参考
http://genko.580sw.com/index.php/2010/01/06/linux%e4%b8%8bzend%e4%b8%8e-eaccelerator%e5%85%b1%e5%ad%98/

Posted in Nginx, 技术.

Tagged with , , , , .


crontab精确到以秒为单位

以秒运行Crontab
在Liux或BSD下,Crontab可以实现以秒运行程序的。
格式如下:

1 minute 1
1,5 minutes 1 and 5
* any minute
*/5 any minute that is divisible by 5

1:2 second 2 of minute 1
1:2,5:10 second 2 of minute 1 and second 10 of minute 5
*:3 second 3 of any minute
*:*/5 any second that is divisible by 5

1:2 第一分钟的第二秒
1:2,5:10 1分二秒与5分10秒
*:3 任意一分钟的第3秒

*:*/5 任意一分钟里可以被5整除的秒,比如,第5、10、15、20 。。。。

原文:http://linux.chinaunix.net/bbs/thread-1127315-1-1.html

Posted in linux 维护优化, 技术.

Tagged with .