SHELL


這是一個LNMP自動安裝的腳本,附帶優化,可作為線上安裝使用。首先聲明,本人才淺,如果有錯誤歡迎指正,有更好的方法請一起分享,此腳本是根據平常安裝總結,請根據您具體的業務應用選擇版本、編譯參數和擴展,此腳本根據LNMP一鍵安裝包修改。安裝中如出現擴展沒安裝上,請手動安裝- -哈哈哈。。。


#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo “Error: You must be root to run this script, please use root to install lnmp”
exit 1
fi
clear
cur_dir=$(pwd)
############
ntpdate ntp.api.bz >>/root/lnmp_error.log 2>&1
echo ” */10 * * * * root ntpdate ntp.api.bz ” >> /etc/crontab
echo “ulimit -SHn 655350″ >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
* soft nofile 655350
* hard nofile 655350
EOF
cp /etc/sysctl.conf /etc/sysctl.conf.`date +”%Y-%m-%d_%H-%M-%S”`
echo “” > /etc/sysctl.conf
# load ip_contrack modules
/sbin/modprobe ip_conntrack
cat >> /etc/sysctl.conf << EOF
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 = 60
net.ipv4.ip_local_port_range = 1024 65500
net.ipv4.tcp_max_syn_backlog = 819200
net.ipv4.tcp_max_tw_buckets = 20000
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 120
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 60
net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60
net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120
net.ipv4.netfilter.ip_conntrack_max = 655360
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.core.wmem_max = 16777216
net.core.wmem_default = 8388608
net.core.somaxconn = 32768
net.core.rmem_max = 16777216
net.core.rmem_default = 8388608
net.core.netdev_max_backlog = 32768
kernel.sysrq = 0
kernel.shmmax = 4294967295
kernel.shmall = 8388608
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.core_uses_pid = 1
fs.file-max = 655350
#vm.swappiness = 0 #max use physical memory
EOF
/sbin/sysctl -p
cat >> /etc/profile << EOF
export PROMPT_COMMAND=”history -a”
export HISTTIMEFORMAT=”%F %T ”
EOF
source /etc/profile
/etc/init.d/iptables stop
setenforce 0
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config
sed -i ‘s/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/’ /etc/ssh/sshd_config
service sshd restart
# shutdown service
for p_stop in acpid apmd atd auditd auditd avahi-daemon bluetooth cpuspeed cups firstboot gpm haldaemon hidd ip6tables irqbalance isdn mcstrans messagebus pcscd rawdevices restorecond sendmail xfs yum-updatesd
do /sbin/service $p_stop stop && /sbin/chkconfig $p_stop off ;done
echo “install lnmp ……”
rpm -qa|grep nginx
rpm -e nginx
rpm -qa|grep mysql
rpm -e mysql
rpm -qa|grep php
rpm -e php
yum -y remove httpd*
yum -y remove php*
yum -y remove mysql-server mysql
yum -y remove php-mysql
yum -y remove httpd
yum -y remove nginx
################
for packages in lrzsz patch make gcc gcc-c++ m4 file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel unzip libcap ntp;
do yum -y install $packages ; done
echo “============================check files==================================”
if [ -s php-5.2.9.tar.gz ]; then
echo “php-5.2.9.tar.gz [found]”
else
echo “Error: php-5.2.9.tar.gz not found!!!download now……”
wget -c http://51daiwei.com/software/php-5.2.9.tar.gz
fi
if [ -s php-5.2.9-fpm-0.5.10.diff.gz ]; then
echo “php-5.2.9-fpm-0.5.10.diff.gz [found]”
else
echo “Error: php-5.2.9-fpm-0.5.10.diff.gz not found!!!download now……”
wget -c http://51daiwei.com/software/php-5.2.9-fpm-0.5.10.diff.gz
fi
if [ -s memcache-3.0.6.tgz ]; then
echo “memcache-3.0.6.tgz [found]”
else
echo “Error: memcache-3.0.6.tgz not found!!!download now……”
wget -c http://soft.vpser.net/web/memcache/memcache-3.0.6.tgz
fi
if [ -s pcre-8.20.tar.gz ]; then
echo “pcre-8.20.tar.gz [found]”
else
echo “Error: pcre-8.20.tar.gz not found!!!download now……”
wget -c http://51daiwei.com/software/pcre-8.20.tar.gz
fi
if [ -s nginx-1.0.10.tar.gz ]; then
echo “nginx-1.0.10.tar.gz [found]”
else
echo “Error: nginx-1.0.10.tar.gz not found!!!download now……”
wget -c http://51daiwei.com/software/nginx-1.0.10.tar.gz
fi
if [ -s mysql-5.0.45.tar.gz ]; then
echo “mysql-5.0.45.tar.gz [found]”
else
echo “Error: mysql-5.0.45.tar.gz not found!!!download now……”
wget -c http://51daiwei.com/software/mysql-5.0.45.tar.gz
fi
if [ -s patch.slow-micro.5.0.45.diff ]; then
echo “patch.slow-micro.5.0.45.diff [found]”
else
echo “Error: patch.slow-micro.5.0.45.diff not found!!!download now……”
wget -c http://51daiwei.com/software/patch.slow-micro.5.0.45.diff
fi
if [ -s libiconv-1.14.tar.gz ]; then
echo “libiconv-1.14.tar.gz [found]”
else
echo “Error: libiconv-1.14.tar.gz not found!!!download now……”
wget -c http://soft.vpser.net/web/libiconv/libiconv-1.14.tar.gz
fi
if [ -s libmcrypt-2.5.8.tar.gz ]; then
echo “libmcrypt-2.5.8.tar.gz [found]”
else
echo “Error: libmcrypt-2.5.8.tar.gz not found!!!download now……”
wget -c http://soft.vpser.net/web/libmcrypt/libmcrypt-2.5.8.tar.gz
fi
if [ -s mhash-0.9.9.9.tar.gz ]; then
echo “mhash-0.9.9.9.tar.gz [found]”
else
echo “Error: mhash-0.9.9.9.tar.gz not found!!!download now……”
wget -c http://soft.vpser.net/web/mhash/mhash-0.9.9.9.tar.gz
fi
if [ -s mcrypt-2.6.8.tar.gz ]; then
echo “mcrypt-2.6.8.tar.gz [found]”
else
echo “Error: mcrypt-2.6.8.tar.gz not found!!!download now……”
wget -c http://soft.vpser.net/web/mcrypt/mcrypt-2.6.8.tar.gz
fi
if [ -s laruence-laruence.github.com-b648cb1.tar.gz ]; then
echo “laruence-laruence.github.com-b648cb1.tar.gz [found]”
else
echo “Error: laruence-laruence.github.com-b648cb1.tar.gz not found!!!download now……”
wget -c http://51daiwei.com/software/laruence-laruence.github.com-b648cb1.tar.gz
fi
if [ -s autoconf-2.13.tar.gz ]; then
echo “autoconf-2.13.tar.gz [found]”
else
echo “Error: autoconf-2.13.tar.gz not found!!!download now……”
wget -c http://soft.vpser.net/lib/autoconf/autoconf-2.13.tar.gz
fi
cd $cur_dir
tar zxvf autoconf-2.13.tar.gz
cd autoconf-2.13/
./configure –prefix=/usr/local/autoconf-2.13
make && make install
cd ../
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure
make && make install
cd ../
cd $cur_dir
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 ../../
cd $cur_dir
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
cd $cur_dir
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure
make && make install
cd ../
if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
ln -s /usr/lib64/libpng.* /usr/lib/
ln -s /usr/lib64/libjpeg.* /usr/lib/
fi
if [ ! `grep -l "/lib" '/etc/ld.so.conf'` ]; then
echo “/lib” >> /etc/ld.so.conf
fi
if [ ! `grep -l '/usr/lib' '/etc/ld.so.conf'` ]; then
echo “/usr/lib” >> /etc/ld.so.conf
fi
if [ -d "/usr/lib64" ] && [ ! `grep -l '/usr/lib64' '/etc/ld.so.conf'` ]; then
echo “/usr/lib64″ >> /etc/ld.so.conf
fi
if [ ! `grep -l '/usr/local/lib' '/etc/ld.so.conf'` ]; then
echo “/usr/local/lib” >> /etc/ld.so.conf
fi
ldconfig
echo “============================mysql install==================================”
cd $cur_dir
tar zxvf mysql-5.0.45.tar.gz
cd mysql-5.0.45
patch -p1 < ../patch.slow-micro.5.0.45.diff
./configure –prefix=/usr/local/mysql \
–with-unix-socket-path=/tmp/mysql.sock \
–with-comment=Odin-DB \
–with-server-suffix=-Odin-DB-Server \
–with-charset=utf8 \
–with-extra-charsets=gbk,gb2312,utf8,latin1 \
–with-mysqld-user=mysql \
–without-debug \
–with-max-indexes=128 \
–with-archive-storage-engine \
–with-pthread \
–enable-static \
–enable-thread-safe-client \
–enable-assembler \
–without-ndb-debug
make && make install
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
mkdir -p /usr/local/mysql/var/
chown -R mysql.mysql /usr/local/mysql
mkdir -p /var/run/mysqld
chown -R mysql.mysql /var/run/mysqld
# vps select my-small.cnf
cp support-files/my-large.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db –user=mysql
/usr/local/mysql/bin/mysqld_safe –user=mysql &
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
echo “============================mysql intall completed=========================”
echo “============================php install======================”
cd $cur_dir
export PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf
export PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader
tar zxvf php-5.2.9.tar.gz
mkdir -m 777 -p /usr/local/php5/etc/
gzip -cd php-5.2.9-fpm-0.5.10.diff.gz | patch -d php-5.2.9 -p1
tar zxvf laruence-laruence.github.com-b648cb1.tar.gz
cd php-5.2.9
patch -p1 < ../laruence-laruence.github.com-b648cb1/php-5.2-max-input-vars/php-5-2.9-max-input-vars.patch
./buildconf –force
./configure –prefix=/usr/local/php5 \
–with-config-file-path=/usr/local/php5/etc \
–with-mysql=/usr/local/mysql \
–with-mysqli=/usr/local/mysql/bin/mysql_config \
–with-iconv-dir \
–with-freetype-dir \
–with-jpeg-dir \
–with-png-dir \
–with-zlib \
–with-libxml-dir=/usr \
–enable-xml \
–disable-rpath \
–enable-discard-path \
–enable-magic-quotes \
–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 \
–enable-ftp \
–with-gd \
–enable-gd-native-ttf \
–with-openssl \
–with-mhash \
–enable-pcntl \
–enable-sockets \
–with-xmlrpc \
–enable-zip \
–enable-soap \
–without-pear \
–with-gettext \
–with-mime-magic
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp -f php.ini-dist /usr/local/php5/etc/php.ini
cd ../
ln -s /usr/local/php5/bin/php /usr/bin/php
ln -s /usr/local/php5/bin/phpize /usr/bin/phpize
ln -s /usr/local/php5/sbin/php-fpm /usr/bin/php-fpm
cd $cur_dir
tar zxvf memcache-3.0.6.tgz
cd $cur_dir/memcache-3.0.6/
/usr/local/php5/bin/phpize
./configure –with-php-config=/usr/local/php5/bin/php-config
make && make install
cd ..
cd $cur_dir/php-5.2.9/ext/pdo_mysql/
/usr/local/php5/bin/phpize
./configure –with-php-config=/usr/local/php5/bin/php-config –with-pdo-mysql=/usr/local/mysql
make && make install
cd $cur_dir/
sed -i ‘s#extension_dir = “./”#extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/”\nextension = “memcache.so”\nextension = “pdo_mysql.so”\n#’ /usr/local/php5/etc/php.ini
sed -i ‘s#output_buffering = Off#output_buffering = On#’ /usr/local/php5/etc/php.ini
sed -i ‘s/post_max_size = 8M/post_max_size = 80M/g’ /usr/local/php5/etc/php.ini
sed -i ‘s/upload_max_filesize = 2M/upload_max_filesize = 20M/g’ /usr/local/php5/etc/php.ini
sed -i ‘s/;date.timezone =/date.timezone = PRC/g’ /usr/local/php5/etc/php.ini
sed -i ‘s/short_open_tag = Off/short_open_tag = On/g’ /usr/local/php5/etc/php.ini
sed -i ‘s/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g’ /usr/local/php5/etc/php.ini
sed -i ‘s/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g’ /usr/local/php5/etc/php.ini
sed -i ‘s/max_execution_time = 30/max_execution_time = 300/g’ /usr/local/php5/etc/php.ini
echo “============================php completed======================”
echo “============================nginx install=================================”
cd $cur_dir/
tar zxvf pcre-8.20.tar.gz
cd pcre-8.20/
./configure
make && make install
mkdir /usr/local/include/pcre
mkdir /usr/local/include/pcre/.libs
cp /usr/local/lib/libpcre.a /usr/local/include/pcre/libpcre.a
cp /usr/local/lib/libpcre.a /usr/local/include/pcre/libpcre.la
cp /usr/local/include/pcre.h /usr/local/include/pcre/pcre.h
cp /usr/local/include/pcre/*.* /usr/local/include/pcre/.libs
cd ..
tar zxvf nginx-1.0.10.tar.gz
cd nginx-1.0.10/
groupadd www
useradd www -s /sbin/nologin -g www
./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module
make && make install
cd $cur_dir/
wget -c http://51daiwei.com/software/fcgi.zip
unzip fcgi.zip
mkdir -p /www/web/nosite
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.source
cp nginx.conf /usr/local/nginx/conf/
mv /usr/local/php5/etc/php-fpm.conf /usr/local/php5/etc/php-fpm.conf.source
cp php-fpm.conf /usr/local/php5/etc/php-fpm.conf
cp fcgi.conf /usr/local/nginx/conf/
/usr/local/php5/sbin/php-fpm start >>/root/lnmp_error.log 2>&1
/usr/local/nginx/sbin/nginx -t >>/root/lnmp_error.log 2>&1
/usr/local/nginx/sbin/nginx >>/root/lnmp_error.log 2>&1
/usr/local/nginx/sbin/nginx -s reload >>/root/lnmp_error.log 2>&1
### autoboot
echo “/usr/local/nginx/sbin/nginx” >>/etc/rc.local
echo “/usr/local/mysql/bin/mysqld_safe –user=mysql &” >>/etc/rc.local
echo “/usr/local/php5/sbin/php-fpm start” >>/etc/rc.local
echo “============================nginx install completed=================================”
echo “done”

沒有留言:

張貼留言