#!/bin/bash#LEMP Serverumount /dev/cdrommount /dev/cdrom /mediaIOS="/etc/yum.repos.d/rhel-debuginfo.repo"if [ $? = 0 ];thensed -i '3d' $IOSsed -i '3i baseurl=file:///media/Server' $IOSsed -i '4d' $IOSsed -i '4i enabled=1' $IOSelseecho "Yum is no"sleep 3fiyum -y install pcre-devel zilb-develif [ $? = 0 ];thenecho "YUM 仓库配置成功"sleep 3elseexitecho "YUM 仓库配置错误"cat $IOSfiuseradd -M -s /sbin/nologin nginxmkdir /ruanjianbaocd /ruanjianbaorzsleep 3if [ $? = 0 ];thenecho "Nginx 软件包已经上传"elseecho "Nginx 软件包没有上传"ficd /ruanjianbaotar zxf nginx-1.0.8.tar.gzcd nginx-1.0.8./configure --PRefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module ; make ; make installif [ $? = 0 ];thenecho "Nginx 正确配置编译安装"elseecho "Nginx错误配置编译安装"exitsleep 3fiulimit -n 65535echo "ulimit -n 65535" >> /etc/rc.d/rc.localln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ls -l /usr/local/sbin/nginxsleep 3cd ~nginx #启动Nginxif [ $? = 0 ];thennetstat -anpt | grep "nginx" #查看Nginx服务是否开启sleep 3elseecho "NO!,Nginx Server is down"fikillall -s HUP nginx #平滑重启nginx(或者killall -1 nginx)killall -s QUIT nginx #正常停止nginx (或者killall -3 nginx)#killall -s USR1 nginx nginx日志分割的话可执行#killall -s USR2 NGINX nginx平滑升级可执行(在线升级)echo '#!/bin/bash# chkconfig: 2345 99 20# description: Nginx Server Control ScriptPROG="/usr/local/nginx/sbin/nginx"PIDF="/usr/local/nginx/logs/nginx.pid"case "$1" in start) $PROG ;; stop) kill -s QUIT $(cat $PIDF) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 (start|stop|restart|reload)" exit 1esacexit 0' > /etc/init.d/nginxif [ $? = 0 ];thenecho "Nginx 执行程序,已经添加"chmod +x /etc/init.d/nginxchkconfig --add nginxchkconfig nginx onchkconfig nginx --listsleep 3elseexitsleep 3echo "Nginx 执行程序,添加失败"fiNginx="/usr/local/nginx/conf/nginx.conf"sed -i 's/#user/user/' $Nginxsed -i '/nobody/ s/nobody/nginx nginx/' $Nginxsed -i '6d' $Nginx #开启notice级别的日志,可根据自己的喜好来(日志界别分为debug/info/notice/warn/error/crit)sed -i '6i error_log logs/error.log notice;' $Nginx #此日志不一定在地6行,所以要cat /usr/local/nginx/conf/nginx.conf 里面的配置,如果不在此行请别执行这条脚本语言sed -i '13i use epoll;' $Nginx #定制nginx的工作模式,一般情况下都是用epoll高效sed -i '/worker_connectons/ s/1024/20000/' $Nginx #此段哟用于定义nginx每个进程的最大连接数,默认是1024,如果修改可根据服务器的CPU内核进行修改,列如CPU是4核的话那就1024*4,以此类推sed -i '/#log_format/ s/#// ' $Nginxsed -i '/$status $body_bytes_sent/ s/#// ' $Nginxsed -i '/$http_user_agent/ s/#// ' $Nginxsed -i '/#access_log/ s/#//' $Nginx #支持文件发送下载sed -i '/server_name/ s/localhost/www.cheshi.com/' $Nginx #定义web服务器的域名sed -i 's/koi8-r/utf-8/' $Nginx #定义字符集sed -i '/#charset/ s/#// ' $Nginxsed -i '48i location ~/status { ' $Nginx #访问位置为/statussed -i '49i stub_status on; ' $Nginx #打开统计状态sed -i '50i access_log off; ' $Nginx #关闭位置日志记录sed -i '51i }' $Nginxif [ $? = 0 ];thenecho "Nginx 配置文件成功" service nginx restartsleep 3elsenginx -tservice nginx restartfiecho '****************************安装MySQL*********************************'cd /ruanjianbao/rzif [ $? = 0 ];thenecho "Mysql 上传成功"sleep 3elsesleep 3echo "Mysql 上传失败"ficd /ruanjianbaotar zxf mysql-5.1.55.tar.gzcd mysql-5.1.55./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312 ; make ; make installif [ $? = 0 ];thenecho "Mysql 正确配置编译安装"elseecho "Mysql 错误配置编译安装"sleep 3exitficd /ruanjianbao/mysql-5.1.55cp support-files/my-medium.cnf /etc/my.cnfcp support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqldln -s /usr/local/mysql/bin/* /usr/local/bin/ln -s /usr/local/mysql/lib/mysql/* /usr/libln -s /usr/local/mysql/include/mysql/* /usr/include/useradd -M -u 27 -s /sbin/nologin mysqlcd /usr/local/mysql/bin/./mysql_install_db --user=mysqlif [ $? = 0 ];thensleep 3echo "Mysql 格式化成功"elseecho "Mysql 格式化失败"sleep 3exitfichown -R root:mysql /usr/local/mysql/chown -R mysql /usr/local/mysql/var//etc/init.d/mysqld restartif [ $? = 0 ];thenecho "Mysql is up"sleep 3elseecho "Mysql is down"sleep 3exitfiecho '*****************************安装php***************************'cd /ruanjianbao/rzif [ $? = 0 ];thenecho "Php 上传成功"sleep 3elseexitsleep 3echo "Php 上传失败"ficd /ruanjianbao/tar zxf php-5.3.6.tar.gzcd php-5.3.6./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm ; make ; make installif [ $? =0 ];thenecho "Php 正确配置编译安装"sleep 3elseecho "Php 错误配置编译安装"exitsleep 3ficd /ruanjianbao/php-5.3.6cp php.ini-development /usr/local/php5/php.iniln -s /usr/local/php5/bin/* /usr/local/bin/ln -s /usr/local/php5/sbin/* /usr/local/sbin/echo '*************************************安装ZendGuardLoader优化模块**************************'cd /ruanjianbao/rzif [ $? = 0 ];thenecho "ZendGuardLoader 上传成功"sleep 3elseecho "ZendGuardLoader 上传失败"sleep 3exitfitar zxf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gzcd ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/cp ZendGuardLoader.so /usr/local/php5/lib/php/echo 'zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.sozend_loader.enable=1' >> /usr/local/php5/php.inicd /usr/local/php5/etc/cp php-fpm.conf.default php-fpm.confPHP="php-fpm.conf"sed -i 's/;pid/pid/' $PHP #确认pid文件位置sed -i '/user = / s/nobody/nginx/' $PHP #程序用户sed -i '/group = / s/nobody/nginx/' $PHP #程序组sed -i 's/;pm.start/pm.start/' $PHP #临时开机的进程数sed -i 's/;pm.min/pm.min/' $PHP #确认空闲进程数sed -i 's/;pm.max_spare_server/pm.max_spare_server/' $PHP #最多空闲进程/usr/local/sbin/php-fpmnetstat -anpt | grep php-fpmsleep 3if [ $? = 0 ];thenecho "php配置文件OK"elseecho "php配置文件NO"sleep 3exitfiecho '#!/bin/bash# chkconfig: 2345 99 20# description: Nginx Server Control ScriptPROG="/usr/local/nginx/sbin/nginx"PIDF="/usr/local/nginx/logs/nginx.pid"PROG_FPM="/usr/local/sbin/php-fpm"PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"case "$1" in start) $PROG $PROG_FPM ;; stop) kill -s QUIT $(cat $PIDF) kill -s QUIT $(cat $PIDF_FPM) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 (start|stop|restart|reload)" exit 1esacexit 0' > /etc/init.d/nginxmkdir -p /var/www/golegnginx='/usr/local/nginx/conf/nginx.conf'sed -i '/server_name/ s/www.cheshi.com/www.goleg.com/' $nginxsed -i '/root/ s#html#/var/www/goleg#' $nginx sed -i '48d' $nginxsed -i '49d' $nginxsed -i '50d' $nginxsed -i '51d' $nginxsed -i '/index/ s/index.html/index.html index.php/ ' $nginxsed -i '48i error_page 500 502 503 504 /50x.html;' $nginxsed -i '49i location = /50x.html { ' $nginxsed -i '50i root html;' $nginxsed -i '51i }' $nginxsed -i '52i location ~ /.php$ { ' $nginxsed -i '53i root /var/www/goleg; ' $nginx sed -i '54i fastcgi_pass 127.0.0.1:9000;' $nginxsed -i '55i fastcgi_index index.php;' $nginxsed -i '56i include fastcgi.conf;' $nginxsed -i '57i } ' $nginxsed -i '58i }' $nginxsed -i '59,$d' $nginxnginx -t slepp 5service nginx restartif [ $? = 0 ];thenecho "Nginx支持PHP配置成功"sleep 3elsecd echo "Nginx支持PHP配置失败"sleep 3exitifmkdir -p /var/www/golegecho '************************添加网站模块***************************'cd /ruanjianbao/rzif [ $? = 0 ];thenecho "模块上传成功"sleep 3elseecho "模块上传失败"sleep 3exitficd /ruanjianbao/tar jxf SKYUC_3.2.2_Free_For_PHP5.3.tar.bz2mv SKYUC_3.2.2_Free_For_PHP5.3/wwwroot /var/www/goleg/skyucmysqladmin -uroot passWord lei1998echo 'CREATE DATABASE goleg;GRANT all ON goleg.* TO 'lei'@'localhost' IDENTIFIED BY '123'; ' > /root/mysqlmysql -uroot -plei1998 < /root/mysqlif [ $? = 0 ];thenecho "Mysql dtatbase,GRANT is ok"rm -rf /root/mysqlecho "Mysql dtatbase,GRANT is no"sleep 3exitficd /var/www/goleg/skyuc/chown -R nginx:nginx admincp/ data/ templates/ upload/if [ $? = 0 ];thenecho "LEMP Server is OK!"sleep 3elseecho "LEMP Server in ON!"sleep 3exitfi###修手动清除55p,和以下的所有字符 #2015.06.20
新闻热点
疑难解答