码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP平台搭建脚本

时间:2016-07-21 11:11:04      阅读:391      评论:0      收藏:0      [点我收藏+]

标签:lnmp脚本


#!/bin/bash

#auto make install LNMP

#by authors zhang 2016


#Nginx define path variable

N_FILES=nginx-1.6.0.tar.gz

N_FILES_DIR=nginx-1.6.0

N_PREFIX=/usr/local/nginx/


#mysql define path variable

M_FILES=mysql-5.5.22.tar.gz

M_FILES_DIR=mysql-5.5.22

M_PREFIX=/usr/local/mysql/



#php define path variable


P_FILES1=libmcrypt-2.5.8.tar.gz

P_FILES_DIR1=libmcrypt-2.5.8

P_PREFIX1=/usr/local/lib/


P_FILES2=mhash-0.9.9.9.tar.gz

P_FILES_DIR2=mhash-0.9.9.9

P_PREFIX2=/usr/local/lib/


P_FILES3=mcrypt-2.6.8.tar.gz

P_FILES_DIR3=mcrypt-2.6.8

P_PREFIX3=/usr/local/lib/


P_FILES4=php-5.3.28.tar.gz

P_FILES_DIR4=php-5.3.28

P_PREFIX4=/usr/local/php/



####################################################

#####编写导航菜单

if [ -z "$1" ];then

        echo -e "\033[36m请选择下面选项:\033[0m"

echo -e "\033[32m1)编译安装Nginx\033[1m"

echo "2)编译安装MySQL"

        echo "3)编译安装PHP"

        echo "4)部署天空网络电影系统"

        echo -e "\033[31m使用: { /bin/sh $0 1|2|3|4|help}\033[0m"

        exit

fi


#auto install Nginx

if [ $1 -eq 1 ];then

        yum -y install pcre-devel zlib-devel

        useradd -M -s /sbin/nologin nginx

        tar -zxvf $N_FILES -C /usr/src/ && cd /usr/src/$N_FILES_DIR && ./configure --prefix=$N_PREFIX --user=nginx --group=nginx --with-http_stub_status_module

        if [ $? -eq 0 ];then

                make &&make install

                echo -e "\033[32mNginx编译安装成功!\033[0m"

        else

                echo -e "\033[31mNginx编译安装失败!\033[0m"

                exit

        fi

#######路径优化

        ln -s $N_PREFIX/sbin/nginx /usr/local/sbin/

        ls -l /usr/local/sbin/nginx

        if [ $? -eq 0 ];then

                echo -e "\033[32m路径优化完成!\033[0m"

        else

                echo -e "\033[31m路径优化失败!\033[0m"

        fi

fi


#auto install Mysql

if [ $1 -eq 2 ];then

        rpm -e mysql-server mysql --nodeps

        yum -y install ncurses-devel

        tar -zxvf cmake-2.8.6.tar.gz -C /usr/src/ && cd /usr/src/cmake-2.8.6/;./configure

        if [ $? -eq 0 ];then

                  gmake &&gmake install

                echo -e "\033[32mThe cmake Server Install successfully!(cmake编译安装完成!)\033[0m"

        else

                echo -e "\033[31mThe cmake Server Install failed,please check...\033[0m"

                exit

        fi

        useradd -M -u 27 -s /sbin/nologin mysql

        cd /root

        tar -zxvf $M_FILES -C /usr/src/;cd /usr/src/$M_FILES_DIR && cmake -DCMAKE_INSTALL_PREFIX=$M_PREFIX -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all

        if [ $? -eq 0 ];then

                make &&make install

                echo -e "\033[32mThe mysql $M_FILES_DIR Install successfully!(MySQL服务安装已完成!)\033[0m"

        else

                echo -e "\033[31mThe mysql $M_FILES_DIR Install failed,please check...\033[0m"

                exit

        fi

        chown -R mysql:mysql /usr/local/mysql/

        cd /usr/src/$M_FILES_DIR

cp support-files/my-medium.cnf /etc/my.cnf

        $M_PREFIX/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

        cd /usr/src/$M_FILES_DIR

        ln -s /usr/local/mysql/bin/* /usr/local/bin/

        cp support-files/mysql.server /etc/init.d/mysqld

        chmod +x /etc/rc.d/init.d/mysqld

        chkconfig --add mysqld

        chkconfig mysqld on

        service mysqld stop

        service mysqld start

        netstat -anpt | grep 3306

        echo -e "\033[32mMysql服务优化完成,已经开启\033[0m"

        mysqladmin -u root password ‘123.com‘

        if [ $? -eq 0 ];then

                echo -e "\033[32mMysql root密码创建成功,密码为123.com\033[0m"

        else

                echo -e "\033[31mMysql root密码创建失败!\033[0m"

        fi

fi




#PHP define path variable


if [ $1 -eq 3 ];then

        tar -zxvf $P_FILES1 -C /usr/src/;cd /usr/src/$P_FILES_DIR1/ && ./configure && make && make install && ln -s /$P_PREFIX1/libmcrypt.* /usr/lib/

        cd /root/

tar -zxvf $P_FILES2 -C /usr/src/;cd /usr/src/$P_FILES_DIR2/ && ./configure && make && make install && ln -s /$P_PREFIX2/libmhash* /usr/lib/

        cd /root/

        tar -zxvf $P_FILES3 -C /usr/src/;cd /usr/src/$P_FILES_DIR3/ && export LD_LIBRARY_PATH=/$P_PREFIX3:$LD_LIBRARY_PATH && ./configure && make && make install

        cd /root/

        tar -zxvf $P_FILES4 -C /usr/src/;cd /usr/src/$P_FILES_DIR4/ && ./configure --prefix=$P_PREFIX4 --with-gd --with-zlib --with-mysql=$M_PREFIX --with-config-file-path=$P_PREFIX4 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib

        if [ $? -eq 0 ];then

                make &&make install

                echo -e "\033[32mThe $P_FILES_DIR4 Server Install successfully!(PHP安装已完成!)\033[0m"

        else

                echo -e "\033[31mThe $P_FILES_DIR4 Server Install failed,please check...\033[0m"

                exit

        fi

        cp /usr/src/$P_FILES_DIR4/php.ini-development $PREFIX4/php.ini

        ln -s $PREFIX4/bin/* /usr/local/bin/

        ln -s $PREFIX4/sbin/* /usr/local/sbin/


#创建php-fpm.conf

useradd -M -u 40 -s /sbin/nologin php

cd /usr/local/php/etc/

cp php-fpm.conf.default php-fpm.conf

sed -i s‘@;pid = run/php-fpm.pid@pid = run/php-fpm.pid@‘ php-fpm.conf

sed -i s‘@user = nobody@user = php@‘ php-fpm.conf

sed -i s‘@group = nobody@group = php@‘ php-fpm.conf

sed -i s‘@pm.max_children = 5@pm.max_children = 50@‘ php-fpm.conf

sed -i s‘@pm.start_servers = 2@pm.start_servers = 20@‘ php-fpm.conf

sed -i s‘@pm.min_spare_servers = 1@pm.min_spare_servers = 5@‘ php-fpm.conf

sed -i s‘@pm.max_spare_servers = 3@pm.max_spare_servers = 35@‘ php-fpm.conf

/usr/local/sbin/php-fpm

netstat -anpt | grep php-fpm

cp /usr/src/php-5.3.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

service php-fpm stop

service php-fpm start

chkconfig --add php-fpm

chkconfig php-fpm on

        if [ $? -eq 0 ];then

                echo -e "\033[32mphp-fpm进程已启动\033[0m"

        else

                echo -e "\033[31mphp-fpm进程启动失败\033[0m"

        fi


sed -i ‘s/#charset koi8-r;/charset utf-8;/g‘ /usr/local/nginx/conf/nginx.conf

sed -i s‘@index  index.html@index  index.php@‘ /usr/local/nginx/conf/nginx.conf

sed -i ‘65s@#location@location@‘ /usr/local/nginx/conf/nginx.conf

sed -i ‘s@#    root           html;@  root  html;@‘ /usr/local/nginx/conf/nginx.conf

sed -i ‘s@#    fastcgi_pass   127.0.0.1:9000;@    fastcgi_pass   127.0.0.1:9000;@‘ /usr/local/nginx/conf/nginx.conf

sed -i ‘s@#    fastcgi_index  index.php;@    fastcgi_index  index.php;@‘ /usr/local/nginx/conf/nginx.conf

sed -i ‘s@#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;@   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;@‘ /usr/local/nginx/conf/nginx.conf

sed -i ‘70s@#    include        fastcgi_params;@    include        fastcgi.conf;@‘ /usr/local/nginx/conf/nginx.conf

sed -i ‘71s/#}/}/‘ /usr/local/nginx/conf/nginx.conf

service nginx stop

echo -e "\033[31mNginx服务已关闭\033[0m"

service nginx start

echo -e "\033[32mNginx服务已启动\033[0m"

netstat -anpt | grep 80


#########验证PHP与Nginx

IP=`ifconfig eth0|grep "Bcast"|awk ‘{print $2}‘|cut -d: -f2`

cat >$N_PREFIX/html/index1.php <<EOF

<?php

phpinfo();

?>

EOF

        if [ $? -eq 0 ];then

                echo -e "\033[32mPHP页面已经准备好,请输入firefox http://$IP/index1.php 进行验证\033[0m"

        else

                echo -e "\033[31mPHP页面载入失败!\033[0m"

        fi

##########验证PHP与Mysql

echo "<?php

\$link=mysql_connect(‘localhost‘,‘root‘,‘123.com‘);

if(\$link) echo ‘恭喜你,数据库连接成功啦!!‘;

mysql_close();

?>" > /usr/local/nginx/html/index2.php

        if [ $? -eq 0 ];then

                echo -e "\033[32mMysql页面已经准备好,请输入firefox http://$IP/index2.php 进行验证\033[0m"

        else

                echo -e "\033[31mMsql页面载入失败!\033[0m"

        fi


fi

######################################################

######部署天空网络电影服务

#############设置SKYUC网站

if [ $1 -eq 4 ];then

yum -y install unzip

unzip SKYUC.v3.4.2.SOURCE.zip

cp -r SKYUC.v3.4.2.SOURCE/wwwroot/ /usr/local/nginx/html/skyuc

chown -R php:php /usr/local/nginx/html/skyuc/admincp/

chown -R php:php /usr/local/nginx/html/skyuc/data/

chown -R php:php /usr/local/nginx/html/skyuc/upload/

chown -R php:php /usr/local/nginx/html/skyuc/templates/

#######创建数据库

mysql -u root -p123.com

fi

##########################################

#为保证安全性,数据库需要自己进行创建

#create database skyucdb;

#grant all on skyucdb.* to ‘admin‘@‘localhost‘ identified by ‘123.com‘;

#quit

########安装界面:firefox http://192.168.1.1/skyuc/install/index.php &

#重启Nginx

#killall -s QUIT nginx

#nginx


本文出自 “光速蜗牛” 博客,转载请与作者联系!

LNMP平台搭建脚本

标签:lnmp脚本

原文地址:http://zhangjianghua.blog.51cto.com/11506932/1828223

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!