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

全部博文(119)

文章存档

2012年(111)

2011年(8)

分类: LINUX

2012-04-21 17:11:45

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

#***************************************************************************************

#CentOS 5.5一键安装nginx+mysql+phphttp://blog.s135.com/nginx_php_v6/

#系统为定制安装,只安装Editors组件,系统内核升级到2.6.35.7,有两个地方需要注意下:

#1、安装patch
#yum install -y patch

#2、设置环境变量
#sed -i "s#PATH=$PATH:$HOME/bin#PATH=$PATH:$HOME/bin:/sbin#" /root/.bash_profile

#***************************************************************************************

#!/bin/bash
# BY kerryhu
# MAIL:king_819@163.com
# BLOG:http://kerry.blog.51cto.com
# Please manual operation yum of before Operation.....


echo "============================更新系统时间==========================================="
yum install -y ntp
ntpdate time.nist.gov
echo "00 01 * * * /usr/sbin/ntpdate time.nist.gov" >> /etc/crontab

echo "============================安装开源组件==========================================="
sudo -s
LANG=C
yum install -y 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

echo "============================下载安装包============================================="
cd /opt
wget

wget

wget

wget
http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.3-m3.tar.gz/from/http://mysql.he.net/
wget

wget "
"
wget "
"
wget

wget "
"
wget

wget

wget

wget
http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget

echo "============================编译安装php所需的支持库================================="
cd /opt
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./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.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
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

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

echo "=============================编译安装MySQL 5.5.3-m3========================="

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql -s /sbin/nologin
tar zxvf mysql-5.5.3-m3.tar.gz
cd mysql-5.5.3-m3/
./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
make;make install
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
cd ../

mkdir -p /data/mysql/data
mkdir -p /data/mysql/binlog
mkdir -p /data/mysql/relaylog
mkdir -p /data/mysql/mysql
chown -R mysql:mysql /data/mysql
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql

cp conf/my.cnf /data/mysql/my.cnf


#设置mysql启动文件
cp conf/mysqld /etc/rc.d/init.d/mysqld

#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#vi /etc/rc.d/init.d/mysqld
#basedir=
#basedir=/usr/local/mysql
#datadir=
#datadir=/data/mysql/data

chmod 700 /etc/rc.d/init.d/mysqld
/etc/rc.d/init.d/mysqld start
/sbin/chkconfig --add mysqld
/sbin/chkconfig --level 2345 mysqld on
ln -s /usr/local/mysql/bin/mysql /sbin/mysql
ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin

#设置root密码(1q2w3e)
/sbin/mysqladmin -u root password 1q2w3e

#配置库文件搜索路径
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
/sbin/ldconfig

#添加/usr/local/mysql/bin到环境变量PATH中
export PATH=$PATH:/usr/local/mysql/bin

#添加mysql管理帐户
#mysql -h localhost -u root -p1q2w3e
#msqyl> use mysql;
#msqyl> grant all on *.* to
identified by 'kerry1q2w3e';
#msqyl> flush privileges;
#msqyl> exit;


echo "==========================编译安装PHP(FastCGI模式)==============================="
#编译安装php-5.2.14
tar -zxvf php-5.2.14.tar.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
cd php-5.2.14/
./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=/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 --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/php/etc/php.ini
cd ../

#编译安装PHP5扩展模块

tar zxvf 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
cd ../

tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

tar zxvf 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
cd ../

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

tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

echo "===========================修改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
sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /usr/local/php/etc/php.ini

#配置eAccelerator加速PHP
mkdir -p /usr/local/eaccelerator_cache
cat >>/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"
EOF

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www -s /sbin/nologin
mkdir -p /data/htdocs/blog
chmod +w /data/htdocs/blog
chown -R www:www /data/htdocs/blog
mkdir -p /data/htdocs/www
chmod +w /data/htdocs/www
chown -R www:www /data/htdocs/www

mv /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf.bak
cp conf/php-fpm.conf /usr/local/php/etc/php-fpm.conf
ulimit -SHn 65535
/usr/local/php/sbin/php-fpm start

echo "================================ 安装Nginx 0.8.46 ============================="
tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make;make install
cd ../

tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make;make install
cd ../

mkdir -p /data/logs
chmod +w /data/logs
chown -R www:www /data/logs

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
cp conf/nginx.conf /usr/local/nginx/conf/nginx.conf
cp conf/fcgi.conf /usr/local/nginx/conf/fcgi.conf

ulimit -SHn 65535
/usr/local/nginx/sbin/nginx

echo "=============================== 添加php测试页面 ==============================="
cat >/data/htdocs/www/phpinfo.php<phpinfo();
$link=mysql_connect('localhost','root','1q2w3e');
if(!$link) echo "失败!";
else echo "成功!";
mysql_close();
?>
EOF

echo "=============================== 设置启动项 ====================================="

echo "ulimit -SHn 65535" >> /etc/rc.local
echo "/usr/local/php/sbin/php-fpm start" >> /etc/rc.local
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local

cat >>/etc/sysctl.conf<net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 300
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000

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
EOF

/sbin/sysctl -p

#测试nginx配置
#/usr/local/nginx/sbin/nginx -t
#平滑重启
#/usr/local/nginx/sbin/nginx -s reload

echo "======================== LNMP安装完成 ==============================="
echo "The path of some dirs:"
echo "mysql dir: /usr/local/mysql"
echo "php dir: /usr/local/php"
echo "nginx dir: /usr/local/nginx"
echo "web dir /data/htdocs/www"
echo "======================================================================"

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

阅读(3461) | 评论(1) | 转发(4) |
给主人留下些什么吧!~~

ops9112014-04-17 17:15:47

学习了