Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1146605
  • 博文数量: 119
  • 博客积分: 1991
  • 博客等级: 上尉
  • 技术积分: 4452
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-23 21:28
文章分类

全部博文(119)

文章存档

2012年(111)

2011年(8)

分类: LINUX

2012-04-20 02:06:55

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://blog.chinaunix.net/space.php?uid=9419692&do=blog&id=3182666

#更新组件
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
#下载程序源码包
cd /opt
wget
wget
wget
#wget [url]http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.26-rc.tar.gz/from/http://mirror.x10.com/mirror/mysql/[/url]
wget [url]http://blog.s135.com/soft/linux/mysql/mysql-5.1.26-rc.tar.gz[/url]
wget
#wget ""
wget
#wget ""
wget
wget
#wget ""
wget
wget
wget

#二、安装PHP 5.2.6(FastCGI模式)
#  1、编译安装PHP 5.2.6所需的支持库:
cd /opt
tar zxvf libiconv-1.12.tar.gz
cd libiconv-1.12/
./configure --prefix=/usr/local
make
make install
cd ../
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 ../../
tar zxvf mhash-0.9.9.tar.gz
cd mhash-0.9.9/
./configure
make
make install
cd ../
cp /usr/local/lib/libmcrypt.* /usr/lib
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
tar zxvf mcrypt-2.6.7.tar.gz
cd mcrypt-2.6.7/
./configure
make
make install
cd ../
#2、编译安装MySQL 5.1.26-rc
cd /opt
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
mkdir -p /usr/local/webserver/mysql/
tar zxvf mysql-5.1.26-rc.tar.gz
cd mysql-5.1.26-rc/
./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
make;make install
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cp support-files/my-medium.cnf /usr/local/webserver/mysql/my.cnf
cd ../
#①、以mysql用户帐号的身份建立数据表:
/usr/local/webserver/mysql/bin/mysql_install_db --defaults-file=/usr/local/webserver/mysql/my.cnf --basedir=/usr/local/webserver/mysql --datadir=/usr/local/webserver/mysql/data --user=mysql --pid-file=/usr/local/webserver/mysql/mysql.pid --skip-locking --port=3306 --socket=/tmp/mysql.sock
#②、启动MySQL(最后的&表示在后台运行)
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &
echo "/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/usr/local/webserver/mysql/my.cnf &" >>/etc/rc.local
#3、编译安装PHP(FastCGI模式)
cd /opt
tar zxvf php-5.2.6.tar.gz
gzip -cd php-5.2.6-fpm-0.5.9.diff.gz | patch -d php-5.2.6 -p1
cd php-5.2.6/
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --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
sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile
make
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../
#4、编译安装PHP5扩展模块
tar zxvf memcache-2.2.3.tgz
cd memcache-2.2.3/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
#配置php.ini
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"\nextension = "memcache.so"\n#' /usr/local/webserver/php/etc/php.ini
sed -i 's#output_buffering = Off#output_buffering = On#' /usr/local/webserver/php/etc/php.ini
#配置eAccelerator加速PHP:
mkdir -p /usr/local/webserver/eaccelerator_cache
配置eAccelerator加速PHP:
mkdir -p /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini
#按shift+g键跳到配置文件的最末尾,加上以下配置信息:
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
#修改sysctl.conf
sed -i 's#kernel.shmmax = 4294967295#kernel.shmmax = 134217728#' /etc/sysctl.conf
/sbin/sysctl -p
#创建www用户和组,以及虚拟主机目录
groupadd www -g 48
useradd -u 48 -g www www
mkdir -p /var/htdoc/www
chmod +w /var/htdoc/www
chown -R www:www /var/htdoc/www
mkdir -p /var/htdoc/mail
chmod +w /var/htdoc/mail
chown -R www:www /var/htdoc/mail
#创建php-fpm配置文件
rm -f /usr/local/webserver/php/etc/php-fpm.conf
cp /opt/php-fpm.conf /usr/local/webserver/php/etc/
#启动php-cgi进程
ulimit -SHn 51200
/usr/local/webserver/php/sbin/php-fpm start
#安装Nginx 0.7.17
#1、安装Nginx所需的pcre库:
cd /opt
tar zxvf pcre-7.7.tar.gz
cd pcre-7.7/
./configure
make && make install
cd ../
#2、安装Nginx
tar zxvf nginx-0.7.17.tar.gz
cd nginx-0.7.17/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../
#3、创建Nginx日志目录
mkdir -p /var/nginx/logs
chmod +w /var/nginx/logs
chown -R www:www /var/nginx/logs
#创建Nginx配置文件
rm -f /usr/local/webserver/nginx/conf/nginx.conf
cp /opt/nginx.conf /usr/local/webserver/nginx/conf/
#nginx虚拟主机配置实例
server
{
listen 80;
server_name mail.1*****1.com;
index index.html index.htm index.php;
root /var/htdoc/56guider;
#limit_conn crawler 20;

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

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /var/nginx/logs/56guider/access.log access;
}
server
{
listen 80;
server_name mail.2*****2.com;
index index.html index.htm index.php;
root /var/htdoc/chembidworld;
#limit_conn crawler 20;

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

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
log_format chemlog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /var/nginx/logs/chembidworld/access.log chemlog;
}
server
{
listen 80;
server_name 192.168.8.152;
location /nginx_status {
stub_status on;
access_log off;
}
}
cp /opt/fcgi.conf /usr/local/webserver/nginx/conf/
#配置开机自动启动Nginx + PHP
echo "ulimit -SHn 51200" >> /etc/rc.local
echo "/usr/local/webserver/php/sbin/php-fpm start" >> /etc/rc.local
echo "/usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf" >> /etc/rc.local
#优化Linux内核参数
vi /etc/sysctl.conf
#在末尾增加以下内容:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000
#使配置立即生效
/sbin/sysctl -p
#七、编写每天定时切割Nginx日志的脚本
#1、创建脚本/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/webserver/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/webserver/nginx/nginx.pid`

#2、设置crontab,每天凌晨00:00切割nginx访问日志
crontab -e
#输入以下内容:
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh
以上配置参考了张宴的[url]http://blog.s135.com/read.php/366.htm[/url]的这篇文章,在此表示感谢!!

本文出自 “聆听未来” 博客,请务必保留此出处http://blog.chinaunix.net/space.php?uid=9419692&do=blog&id=3182666


附件下载:
  install
  nginx.conf

阅读(1706) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~