LEMP安装脚本

#!/bin/bash
#LEMP Server
umount /dev/cdrom
mount /dev/cdrom /media
IOS="/etc/yum.repos.d/rhel-debuginfo.repo"
if [ $? = 0 ];then
sed -i '3d' $IOS
sed -i '3i baseurl=file:///media/Server' $IOS
sed -i '4d' $IOS
sed -i '4i enabled=1' $IOS
else
echo "Yum is no"
sleep 3
fi
yum -y install pcre-devel zilb-devel
if [ $? = 0 ];then
echo "YUM 仓库配置成功"
sleep 3
else
exit
echo "YUM 仓库配置错误"
cat $IOS
fi
useradd -M -s /sbin/nologin nginx
mkdir /ruanjianbao
cd /ruanjianbao
rz
sleep 3
if [ $? = 0 ];then
echo "Nginx    软件包已经上传"
else
echo "Nginx    软件包没有上传"
fi
cd /ruanjianbao
tar zxf nginx-1.0.8.tar.gz
cd nginx-1.0.8
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module  ; make  ; make install
if [ $? = 0 ];then
echo "Nginx 正确配置编译安装"
else
echo "Nginx错误配置编译安装"
exit
sleep 3
fi
ulimit -n 65535
echo "ulimit -n 65535" >> /etc/rc.d/rc.local
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
ls -l /usr/local/sbin/nginx
sleep 3
cd ~
nginx        #启动Nginx
if [ $? = 0 ];then
netstat -anpt | grep "nginx"    #查看Nginx服务是否开启
sleep 3
else
echo "NO!,Nginx Server is down"
fi
killall -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 Script
PROG="/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 1
esac
exit 0' > /etc/init.d/nginx
if [ $? = 0 ];then
echo "Nginx 执行程序,已经添加"
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
chkconfig nginx --list
sleep 3
else
exit
sleep 3
echo "Nginx 执行程序,添加失败"
fi
Nginx="/usr/local/nginx/conf/nginx.conf"
sed -i 's/#user/user/'                 $Nginx
sed -i '/nobody/ s/nobody/nginx nginx/'        $Nginx
sed -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/#//  '          $Nginx
sed -i '/$status $body_bytes_sent/ s/#// '    $Nginx
sed -i '/$http_user_agent/ s/#// '        $Nginx
sed -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/#// '            $Nginx
sed -i '48i location ~/status { '        $Nginx        #访问位置为/status
sed -i '49i stub_status    on; '            $Nginx        #打开统计状态
sed -i '50i access_log off; '            $Nginx        #关闭位置日志记录
sed -i '51i }'                    $Nginx
if [ $? = 0 ];then
echo "Nginx 配置文件成功"  
service nginx restart
sleep 3
else
nginx -t
service nginx restart
fi
echo '****************************安装Mysql*********************************'
cd /ruanjianbao/
rz
if [ $? = 0 ];then
echo "Mysql 上传成功"
sleep 3
else
sleep 3
echo "Mysql 上传失败"
fi
cd /ruanjianbao
tar zxf  mysql-5.1.55.tar.gz
cd mysql-5.1.55
./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312 ; make ; make install
if [ $? = 0 ];then
echo "Mysql 正确配置编译安装"
else
echo "Mysql 错误配置编译安装"
sleep 3
exit
fi
cd /ruanjianbao/mysql-5.1.55
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
ln -s /usr/local/mysql/bin/* /usr/local/bin/
ln -s /usr/local/mysql/lib/mysql/* /usr/lib
ln -s /usr/local/mysql/include/mysql/* /usr/include/
useradd -M -u 27 -s /sbin/nologin mysql
cd /usr/local/mysql/bin/
./mysql_install_db --user=mysql
if [ $? = 0 ];then
sleep 3
echo "Mysql 格式化成功"
else
echo "Mysql 格式化失败"
sleep 3
exit
fi
chown -R root:mysql /usr/local/mysql/
chown -R mysql /usr/local/mysql/var/
/etc/init.d/mysqld restart
if [ $? = 0 ];then
echo "Mysql is up"
sleep 3
else
echo "Mysql is down"
sleep 3
exit
fi
echo '*****************************安装Php***************************'
cd /ruanjianbao/
rz
if [ $? = 0 ];then
echo "Php 上传成功"
sleep 3
else
exit
sleep 3
echo "Php 上传失败"
fi
cd /ruanjianbao/
tar zxf  php-5.3.6.tar.gz
cd 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 install
if [ $? =0 ];then
echo "Php 正确配置编译安装"
sleep 3
else
echo "Php 错误配置编译安装"
exit
sleep 3
fi
cd /ruanjianbao/php-5.3.6
cp php.ini-development /usr/local/php5/php.ini
ln -s /usr/local/php5/bin/* /usr/local/bin/
ln -s /usr/local/php5/sbin/* /usr/local/sbin/
echo '*************************************安装ZendGuardLoader优化模块**************************'
cd /ruanjianbao/
rz
if [ $? = 0 ];then
echo "ZendGuardLoader 上传成功"
sleep 3
else
echo "ZendGuardLoader 上传失败"
sleep 3
exit
fi
tar zxf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
cd 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.so
zend_loader.enable=1' >> /usr/local/php5/php.ini
cd /usr/local/php5/etc/
cp php-fpm.conf.default php-fpm.conf
PHP="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-fpm
netstat -anpt | grep php-fpm
sleep 3
if [ $? = 0 ];then
echo "php配置文件OK"
else
echo "php配置文件NO"
sleep 3
exit
fi
echo '#!/bin/bash
# chkconfig: 2345 99 20
# description: Nginx Server Control Script
PROG="/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 1
esac
exit 0' > /etc/init.d/nginx
mkdir -p /var/www/goleg
nginx='/usr/local/nginx/conf/nginx.conf'
sed -i '/server_name/ s/www.cheshi.com/www.goleg.com/' $nginx
sed -i '/root/ s#html#/var/www/goleg#'        $nginx    
sed -i '48d' $nginx
sed -i '49d' $nginx
sed -i '50d' $nginx
sed -i '51d' $nginx
sed -i '/index/ s/index.html/index.html index.php/ ' $nginx
sed -i '48i         error_page   500 502 503 504  /50x.html;' $nginx
sed -i '49i        location = /50x.html { '    $nginx
sed -i '50i         root   html;'  $nginx
sed -i '51i         }'    $nginx
sed -i '52i   location ~ \.php$ { ' $nginx
sed -i '53i         root    /var/www/goleg; '  $nginx   
sed -i '54i        fastcgi_pass    127.0.0.1:9000;' $nginx
sed -i '55i            fastcgi_index   index.php;' $nginx
sed -i '56i            include         fastcgi.conf;' $nginx
sed -i '57i        } ' $nginx
sed -i '58i }'        $nginx
sed -i '59,$d'        $nginx
nginx -t
slepp 5
service nginx restart
if [ $? = 0 ];then
echo "Nginx支持PHP配置成功"
sleep 3
elsecd
echo "Nginx支持PHP配置失败"
sleep 3
exit
if
mkdir -p /var/www/goleg
echo '************************添加网站模块***************************'
cd /ruanjianbao/
rz
if [ $? = 0 ];then
echo "模块上传成功"
sleep 3
else
echo "模块上传失败"
sleep 3
exit
fi
cd /ruanjianbao/
tar jxf SKYUC_3.2.2_Free_For_PHP5.3.tar.bz2
mv SKYUC_3.2.2_Free_For_PHP5.3/wwwroot  /var/www/goleg/skyuc
mysqladmin -uroot password lei1998
echo 'CREATE DATABASE goleg;
GRANT all ON goleg.* TO 'lei'@'localhost' IDENTIFIED BY  '123'; ' >  /root/mysql
mysql -uroot -plei1998 < /root/mysql
if [ $? = 0 ];then
echo "Mysql dtatbase,GRANT is ok"
rm -rf /root/mysql
echo "Mysql dtatbase,GRANT is no"
sleep 3
exit
fi
cd /var/www/goleg/skyuc/
chown -R nginx:nginx admincp/ data/ templates/ upload/
if [ $? = 0 ];then
echo "LEMP Server is OK!"
sleep 3
else
echo "LEMP Server in ON!"
sleep 3
exit
fi
###修手动清除55p,和以下的所有字符
                                        #2015.06.20

你可能感兴趣的:(脚本)