LNMP一键安装脚本
1 #!/bin/bash 2 #auto make install LNMP 3 #by authors zhangjianghua 2016 4 5 #Nginx define path variable 6 N_FILES=nginx-1.6.0.tar.gz 7 N_FILES_DIR=nginx-1.6.0 8 N_PREFIX=/usr/local/nginx/ 9 10 #mysql define path variable 11 M_FILES=mysql-5.5.22.tar.gz 12 M_FILES_DIR=mysql-5.5.22 13 M_PREFIX=/usr/local/mysql/ 14 15 16 #php define path variable 17 18 P_FILES1=libmcrypt-2.5.8.tar.gz 19 P_FILES_DIR1=libmcrypt-2.5.8 20 P_PREFIX1=/usr/local/lib/ 21 22 P_FILES2=mhash-0.9.9.9.tar.gz 23 P_FILES_DIR2=mhash-0.9.9.9 24 P_PREFIX2=/usr/local/lib/ 25 26 P_FILES3=mcrypt-2.6.8.tar.gz 27 P_FILES_DIR3=mcrypt-2.6.8 28 P_PREFIX3=/usr/local/lib/ 29 30 P_FILES4=php-5.3.28.tar.gz 31 P_FILES_DIR4=php-5.3.28 32 P_PREFIX4=/usr/local/php/ 33 34 35 #################################################### 36 #####编写导航菜单 37 if [ -z "$1" ];then 38 echo -e "\033[36m请选择下面选项:\033[0m" 39 echo -e "\033[32m1)编译安装Nginx\033[1m" 40 echo "2)编译安装MySQL" 41 echo "3)编译安装PHP" 42 echo "4)部署天空网络电影系统" 43 echo -e "\033[31m使用: { /bin/sh $0 1|2|3|4|help}\033[0m" 44 exit 45 fi 46 47 #auto install Nginx 48 if [ $1 -eq 1 ];then 49 yum -y install pcre-devel zlib-devel 50 useradd -M -s /sbin/nologin nginx 51 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 52 if [ $? -eq 0 ];then 53 make &&make install 54 echo -e "\033[32mNginx编译安装成功!\033[0m" 55 else 56 echo -e "\033[31mNginx编译安装失败!\033[0m" 57 exit 58 fi 59 #######路径优化 60 ln -s $N_PREFIX/sbin/nginx /usr/local/sbin/ 61 ls -l /usr/local/sbin/nginx 62 if [ $? -eq 0 ];then 63 echo -e "\033[32m路径优化完成!\033[0m" 64 else 65 echo -e "\033[31m路径优化失败!\033[0m" 66 fi 67 fi 68 69 #auto install Mysql 70 if [ $1 -eq 2 ];then 71 rpm -e mysql-server mysql --nodeps 72 yum -y install ncurses-devel 73 tar -zxvf cmake-2.8.6.tar.gz -C /usr/src/ && cd /usr/src/cmake-2.8.6/;./configure 74 if [ $? -eq 0 ];then 75 gmake &&gmake install 76 echo -e "\033[32mThe cmake Server Install successfully!(cmake编译安装完成!)\033[0m" 77 else 78 echo -e "\033[31mThe cmake Server Install failed,please check...\033[0m" 79 exit 80 fi 81 useradd -M -u 27 -s /sbin/nologin mysql 82 cd /root 83 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 84 if [ $? -eq 0 ];then 85 make &&make install 86 echo -e "\033[32mThe mysql $M_FILES_DIR Install successfully!(MySQL服务安装已完成!)\033[0m" 87 else 88 echo -e "\033[31mThe mysql $M_FILES_DIR Install failed,please check...\033[0m" 89 exit 90 fi 91 chown -R mysql:mysql /usr/local/mysql/ 92 cd /usr/src/$M_FILES_DIR 93 cp support-files/my-medium.cnf /etc/my.cnf 94 $M_PREFIX/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 95 cd /usr/src/$M_FILES_DIR 96 ln -s /usr/local/mysql/bin/* /usr/local/bin/ 97 cp support-files/mysql.server /etc/init.d/mysqld 98 chmod +x /etc/rc.d/init.d/mysqld 99 chkconfig --add mysqld 100 chkconfig mysqld on 101 service mysqld stop 102 service mysqld start 103 netstat -anpt | grep 3306 104 echo -e "\033[32mMysql服务优化完成,已经开启\033[0m" 105 mysqladmin -u root password '123.com' 106 if [ $? -eq 0 ];then 107 echo -e "\033[32mMysql root密码创建成功,密码为123.com\033[0m" 108 else 109 echo -e "\033[31mMysql root密码创建失败!\033[0m" 110 fi 111 fi 112 113 114 115 #PHP define path variable 116 117 if [ $1 -eq 3 ];then 118 tar -zxvf $P_FILES1 -C /usr/src/;cd /usr/src/$P_FILES_DIR1/ && ./configure && make && make install && ln -s /$P_PREFIX1/libmcrypt.* /usr/lib/ 119 cd /root/ 120 tar -zxvf $P_FILES2 -C /usr/src/;cd /usr/src/$P_FILES_DIR2/ && ./configure && make && make install && ln -s /$P_PREFIX2/libmhash* /usr/lib/ 121 cd /root/ 122 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 123 cd /root/ 124 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 125 if [ $? -eq 0 ];then 126 make &&make install 127 echo -e "\033[32mThe $P_FILES_DIR4 Server Install successfully!(PHP安装已完成!)\033[0m" 128 else 129 echo -e "\033[31mThe $P_FILES_DIR4 Server Install failed,please check...\033[0m" 130 exit 131 fi 132 cp /usr/src/$P_FILES_DIR4/php.ini-development $PREFIX4/php.ini 133 ln -s $PREFIX4/bin/* /usr/local/bin/ 134 ln -s $PREFIX4/sbin/* /usr/local/sbin/ 135 136 #创建php-fpm.conf 137 useradd -M -u 40 -s /sbin/nologin php 138 cd /usr/local/php/etc/ 139 cp php-fpm.conf.default php-fpm.conf 140 sed -i s'@;pid = run/php-fpm.pid@pid = run/php-fpm.pid@' php-fpm.conf 141 sed -i s'@user = nobody@user = php@' php-fpm.conf 142 sed -i s'@group = nobody@group = php@' php-fpm.conf 143 sed -i s'@pm.max_children = 5@pm.max_children = 50@' php-fpm.conf 144 sed -i s'@pm.start_servers = 2@pm.start_servers = 20@' php-fpm.conf 145 sed -i s'@pm.min_spare_servers = 1@pm.min_spare_servers = 5@' php-fpm.conf 146 sed -i s'@pm.max_spare_servers = 3@pm.max_spare_servers = 35@' php-fpm.conf 147 /usr/local/sbin/php-fpm 148 netstat -anpt | grep php-fpm 149 cp /usr/src/php-5.3.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 150 chmod +x /etc/init.d/php-fpm 151 service php-fpm stop 152 service php-fpm start 153 chkconfig --add php-fpm 154 chkconfig php-fpm on 155 if [ $? -eq 0 ];then 156 echo -e "\033[32mphp-fpm进程已启动\033[0m" 157 else 158 echo -e "\033[31mphp-fpm进程启动失败\033[0m" 159 fi 160 161 sed -i 's/#charset koi8-r;/charset utf-8;/g' /usr/local/nginx/conf/nginx.conf 162 sed -i s'@index index.html@index index.php@' /usr/local/nginx/conf/nginx.conf 163 sed -i '65s@#location@location@' /usr/local/nginx/conf/nginx.conf 164 sed -i 's@# root html;@ root html;@' /usr/local/nginx/conf/nginx.conf 165 sed -i 's@# fastcgi_pass 127.0.0.1:9000;@ fastcgi_pass 127.0.0.1:9000;@' /usr/local/nginx/conf/nginx.conf 166 sed -i 's@# fastcgi_index index.php;@ fastcgi_index index.php;@' /usr/local/nginx/conf/nginx.conf 167 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 168 sed -i '70s@# include fastcgi_params;@ include fastcgi.conf;@' /usr/local/nginx/conf/nginx.conf 169 sed -i '71s/#}/}/' /usr/local/nginx/conf/nginx.conf 170 service nginx stop 171 echo -e "\033[31mNginx服务已关闭\033[0m" 172 service nginx start 173 echo -e "\033[32mNginx服务已启动\033[0m" 174 netstat -anpt | grep 80 175 176 #########验证PHP与Nginx 177 IP=`ifconfig eth0|grep "Bcast"|awk '{print $2}'|cut -d: -f2` 178 cat >$N_PREFIX/html/index1.php <<EOF 179 <?php 180 phpinfo(); 181 ?> 182 EOF 183 if [ $? -eq 0 ];then 184 echo -e "\033[32mPHP页面已经准备好,请输入firefox http://$IP/index1.php 进行验证\033[0m" 185 else 186 echo -e "\033[31mPHP页面载入失败!\033[0m" 187 fi 188 ##########验证PHP与Mysql 189 echo "<?php 190 \$link=mysql_connect('localhost','root','123.com'); 191 if(\$link) echo '恭喜你,数据库连接成功啦!!'; 192 mysql_close(); 193 ?>" > /usr/local/nginx/html/index2.php 194 if [ $? -eq 0 ];then 195 echo -e "\033[32mMysql页面已经准备好,请输入firefox http://$IP/index2.php 进行验证\033[0m" 196 else 197 echo -e "\033[31mMsql页面载入失败!\033[0m" 198 fi 199 200 fi 201 ###################################################### 202 ######部署天空网络电影服务 203 #############设置SKYUC网站 204 if [ $1 -eq 4 ];then 205 yum -y install unzip 206 unzip SKYUC.v3.4.2.SOURCE.zip 207 cp -r SKYUC.v3.4.2.SOURCE/wwwroot/ /usr/local/nginx/html/skyuc 208 chown -R php:php /usr/local/nginx/html/skyuc/admincp/ 209 chown -R php:php /usr/local/nginx/html/skyuc/data/ 210 chown -R php:php /usr/local/nginx/html/skyuc/upload/ 211 chown -R php:php /usr/local/nginx/html/skyuc/templates/ 212 #######创建数据库 213 mysql -u root -p123.com 214 fi 215 ########################################## 216 #create database skyucdb; 217 #grant all on skyucdb.* to 'admin'@'localhost' identified by '123.com'; 218 #quit 219 ########安装界面:firefox http://192.168.1.1/skyuc/install/index.php & 220 #重启Nginx 221 #killall -s QUIT nginx 222 #nginx
个人备忘,欢迎阅读