PHP部分:
#Building curl
cd $BUILD_DIR
gunzip -c curl-7.19.5.tar.gz | tar xf -
cd curl-7.19.5
./configure --prefix=$INSTALL_DIR
make && make install
#Building libiconv
cd $BUILD_DIR
gunzip -c libiconv-1.13.1.tar.gz | tar xf -
cd libiconv-1.13.1
./configure --prefix=$INSTALL_DIR
make && make install
#Building libmcrypt
cd $BUILD_DIR
gunzip -c libmcrypt-2.5.8.tar.gz | tar xf -
cd libmcrypt-2.5.8
./configure --prefix=$INSTALL_DIR
make && make install
#Building mhash
cd $BUILD_DIR
gunzip -c mhash-0.9.9.9.tar.gz | tar xf -
cd mhash-0.9.9.9
./configure --prefix=$INSTALL_DIR
make && make install
echo "/usr/local/build/lib/"> /etc/ld.so.conf.d/mhash.conf && ldconfig
#Building mcrypt
cd $BUILD_DIR
gunzip -c mcrypt-2.6.8.tar.gz | tar xf -
cd mcrypt-2.6.8
CFLAGS="-I/usr/local/build/include/" LDFLAGS="-L/usr/local/build/lib/" ./configure --prefix=$INSTALL_DIR
make && make install
#Building jpeg
cd $BUILD_DIR
gunzip -c jpegsrc.v6b.tar.gz |tar xf -
cd jpeg-6b/
mkdir -p /usr/local/build/man/man1/
cp /usr/bin/libtool .
./configure --prefix=$INSTALL_DIR --enable-shared
make && make install
#Building gettext
cd $BUILD_DIR
gunzip -c gettext-0.17.tar.gz | tar xf -
cd gettext-0.17
./configure --prefix=$INSTALL_DIR
make && make install
#Building gd
cd $BUILD_DIR
tar zxf gd-2.0.35.tar.gz
cd gd-2.0.35
CPPFLAGS="-I/usr/local/build/include" ./configure --prefix=$INSTALL_DIR --with-jpeg --with-freetype --with-png --with-libiconv-prefix --with-fontconfig --with-xpm --enable-shared --enable-m4_pattern_allow
make && make install
#Building mysql
cd $BUILD_DIR
gunzip -c mysql-5.1.37.tar.gz | tar xf -
cd mysql-5.1.37
./configure --prefix=/usr/local/mysql --sysconfdir=/usr/local/mysql/etc/ --datadir=/usr/local/mysql/data --enable-shared --enable-static --enable-assembler --with-charset=utf8 --with-extra-charsets=all --with-big-tables
make && make install
useradd mysql -s /sbin/nologin
chown -R root.root /usr/local/mysql/
chown -R mysql.mysql /usr/local/mysql/data
./scripts/mysql_install_db --user=mysql
mkdir /usr/local/mysql/etc
cp support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf
vi /usr/local/mysql/etc/my.cnf
在[mysqld]下面添加
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
/bin/cp -arf /usr/local/mysql/var/mysql/* /usr/local/mysql/data/mysql/
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
service mysqld start
ln -s /usr/local/mysql/bin/* /usr/bin/
mysqladmin -uroot password "passwd"
#Building PHP
cd $BUILD_DIR
gunzip -c php-5.2.10.tar.gz | tar xf -
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=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir=/usr/local/build/ --with-jpeg-dir=/usr/local/build/ --with-png-dir=/usr/local/build/ --with-zlib=/usr/local/build/ --with-libxml-dir=/usr/local/build/ --enable-xml=/usr/local/build/ --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/build/ --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt=/usr/local/build/ --with-gd=/usr/local/build/ --enable-gd-native-ttf --with-openssl --with-mhash=/usr/local/build/ --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext=/usr/local/build/
make ZEND_EXTRA_LIBS='-liconv'
make test #因开启safe-mode,所以会出现警告信息 忽略继续下一步
make install
cp php.ini-dist /usr/local/php/etc/php.ini
可选步骤(只做cacti服务器时一下软件可省略)
#Building memcache
cd $BUILD_DIR
tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
#Building eaccelerator
cd $BUILD_DIR
tar jxf eaccelerator-f61ebcfb533a.tar.bz2
cd eaccelerator-f61ebcfb533a
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install
#Building PDO_MYSQL
cd $BUILD_DIR
tar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql/
make && make install
#Building ImageMagick
cd $BUILD_DIR
tar zxf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure && make && make install
#Building imagick
cd $BUILD_DIR
tar zxf imagick-2.2.2.tgz
cd imagick-2.2.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
修改php.ini文件
vi /usr/local/php/etc/php.ini
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/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
自动修改:若嫌手工修改麻烦,可执行以下shell命令,自动完成对php.ini文件的修改:
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /usr/local/php/etc/php.ini
sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/php/etc/php.ini
sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /usr/local/php/etc/php.ini
配置eAccelerator加速PHP
mkdir -p /usr/local/eaccelerator_cache
vi /usr/local/php/etc/php.ini
文件最后加入:
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/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"
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /var/www/cacti
chmod +w /var/www/cacti
chown -R www:www /var/www/cacti
mkdir -p /var/www/html/
chmod +w /var/www/html/
chown -R www:www /var/www/html/
创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/usr/local/php/etc/目录中创建php-fpm.conf文件:
rm -f /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
Nginx + PHP 用于程序调试,请将以下的0改为1,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页
#####################################################################################
All relative paths in this config are relative to php's install prefix
Pid file
/usr/local/php/logs/php-fpm.pid
Error log file
/usr/local/php/logs/php-fpm.log
Log level
notice
When this amount of php processes exited with SIGSEGV or SIGBUS ...
10
... in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator's shared memory.
1m
Time limit on waiting child's reaction on signals from master
5s
Set to 'no' to debug fpm
yes
Name of pool. Used in logs and stats.
default
Address to accept fastcgi requests on.
Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
127.0.0.1:9000
Set listen(2) backlog
-1
Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.
0666
Additional php.ini defines, specific to this pool of workers.
/usr/sbin/sendmail -t -i
1
Unix user of processes
www
Unix group of processes
www
Process manager settings
Sets style of controling worker process count.
Valid values are 'static' and 'apache-like'
static
Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
128
Settings group for 'apache-like' pm style
Sets the number of server processes created on startup.
Used only when 'apache-like' pm_style is selected
20
Sets the desired minimum number of idle server processes.
Used only when 'apache-like' pm_style is selected
5
Sets the desired maximum number of idle server processes.
Used only when 'apache-like' pm_style is selected
35
The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when 'max_execution_time' ini option does not stop script execution for some reason
'0s' means 'off'
0s
The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
'0s' means 'off'
0s
The log file for slow requests
logs/slow.log
Set open file desc rlimit
51200
Set max core size rlimit
0
Chroot to this directory at the start, absolute path
Chdir to this directory at the start, absolute path
Redirect workers' stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
yes
How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
102400
Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
127.0.0.1
Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
$HOSTNAME
/usr/local/bin:/usr/bin:/bin
/tmp
/tmp
/tmp
$OSTYPE
$MACHTYPE
2
######################################################################################
启动php-fpm
ulimit -SHn 51200
/usr/local/php/sbin/php-fpm start
#Building pcre
tar zxvf pcre-7.9.tar.gz
cd pcre-7.9
./configure --prefix=$INSTALL_DIR && make && make install
cd ..
#Building nginx
tar zxvf nginx-0.7.61.tar.gz
cd nginx-0.7.61
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_dav_module --without-http_ssi_module --with-http_ssl_module --with-pcre=$BUILD_DIR/pcre-7.9 --with-zlib-opt=$INSTALL_DIR
make && make install
cd ..
注:--with-pcre后为pcre解压目录非pcre安装目录
创建nginx日志目录
mkdir -p /var/log/nginx/logs
chown -R /var/log/nginx/logs/
修改nginx配置文件
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vi /usr/local/nginx/conf/nginx.conf
写入
user www www;
worker_processes 8;
error_log /var/log/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/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;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
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;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80;
server_name ;
index index.html index.htm index.php;
root /var/www/html;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
log_format wwwlogs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /var/log/nginx/logs/wwwlogs.log wwwlogs;
}
server
{
listen 80;
server_name cacti.example.com;
index index.html index.htm index.php;
root /var/www/cacti;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
}
server
{
listen 80;
server_name status.example.com;
location / {
stub_status on;
access_log off;
}
}
}
创建fcgi配置文件
vi /usr/local/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;
fastcgi_param REDIRECT_STATUS 200;
启动nginx
ulimit -SHn 51200
/usr/local/nginx/sbin/nginx
停止nginx
killall nginx
在不停止Nginx服务的情况下平滑变更Nginx配置
修改/usr/local/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/nginx/sbin/nginx -t
如果屏幕显示以下两行信息,说明配置文件正确:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/nginx/conf/nginx.conf was tested successful
这时,输入以下命令查看Nginx主进程号:
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
屏幕显示的即为Nginx主进程号,例如:
6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:
kill -HUP 6302
或者无需这么麻烦,找到Nginx的Pid文件:
kill -HUP `cat /usr/local/nginx/nginx.pid`
-------------------------------------------------------------------------------
编写每天定时切割Nginx日志的脚本
创建脚本/usr/local/nginx/sbin/cut_nginx_log.sh
vi /usr/local/nginx/sbin/cut_nginx_log.sh
输入以下内容:
#!/bin/bash
# This script run at 00:00
# The Nginx logs path
logs_path="/usr/local/nginx/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/nginx.pid`
阅读(1594) | 评论(0) | 转发(0) |