lnmp环境安装sh脚本

  闲来无事自己写了个LNMP环境的安装脚本。

  该脚本可以单独安装nginx,mysql,php,也可以一步到位直接安装所有软件。其中,nginx安装完,需根据具体环境修改配置文件,再启动服务。mysql,php安装完服务自动启动。

  

  环境:

     软件安装路径:/opt/apps/

     数据存放目录:/opt/data/

     安装包下载目录:/opt/src/


  具体软件版本如下:

             nginx-1.10.1

             mysql-5.6.32

             php-7.0.10

  脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# more lnmp_install.sh
#!/bin/sh
##############################defind functions that install lnmp....######################
#######nginx##########################
Install_nginx ()
{
echo  -e  "\033[33m Install nginx....\033[0m"
if  [ -d  /opt/apps/nginx/  ];  then
   echo  -e  "\033[31m Nginx already exists in your system......\033[0m"
   exit
fi
   echo  -e  "\033[33m Install base environment of nginx......\033[0m" 
   yum -y  install  pcre* openssl*
   echo  -e  "\033[33m Download nginx(1.10.1)......\033[0m"
   if  [ ! -f  /opt/src/nginx-1 .10.1. tar .gz ];
   then
    wget http: //nginx .org /download/nginx-1 .10.1. tar .gz  -P  /opt/src
   fi
   cd  /opt/src/
   tar  -zxvf nginx-1.10.1. tar .gz
   cd  nginx-1.10.1
   echo  -e  "\033[33m Compose nginx......\033[0m" 
  . /configure  --prefix= /opt/apps/nginx   --conf-path= /opt/conf/nginx/nginx .conf  --error-log-path= /opt/logs/nginx/error .log --http-log-path= /opt/logs/nginx/access .log --with-http_stub_status_module --with-http_gzip_static_module --with-ht
tp_flv_module --with-http_ssl_module --with-http_realip_module --http-client-body-temp-path= /opt/apps/nginx/client_body_temp  --http-fastcgi-temp-path= /opt/apps/nginx/fastcgi_temp  --http-proxy-temp-path= /opt/apps/nginx/proxy_temp  --http-
uwsgi-temp-path= /opt/apps/nginx/uwsgi_temp  --http-scgi-temp-path= /opt/apps/nginx/scgi_temp
   make  &&  make  install
   if  [ $? - eq  "0"  ];  then
     echo  -e  "\033[32m Nginx is installed successfully......\033[0m"
     exit
   else
     echo  -e  "\033[31m Something was wrong during installing nginx,please check and try again......\033[0m"
     exit
   fi
}
######mysql############################
Install_mysql ()
{
#Removing default rpm packages of mysql if they have been installed....
if  [ -f  /usr/bin/mysqld_safe  ]; then
   echo  -e  "\033[33m Remove default mysql-server RPM packages......\033[0m" 
   yum -y remove mysql-server
fi
if  [ -f  /usr/bin/mysqldump  ]; then
   echo  -e  "\033[33m Remove default mysql-client RPM packages......\033[0m" 
   yum -y remove mysql 
fi
#Adding mysql's user and group..
if  [ ! -d  /opt/data/mysql ]; then
     mkdir  -p  /opt/data/mysql
fi
echo  -e  "\033[33m Setting Environment variables......\033[0m" 
userdel -r mysql
groupdel -r mysql
groupadd  mysql
useradd  -r -g mysql -s  /sbin/nologin  mysql
#setting the env of mysql......
base_dir= /opt/apps/mysql/
data_dir= /opt/data/mysql/
src_dir= /opt/src/
#Download mysql and install
if  [ ! -d  /opt/src/mysql-5 .6.32/ ]; then
   if  [ ! -f  /opt/src/mysql-5 .6.32. tar .gz ]; then
     wget http: //dev .mysql.com /get/Downloads/MySQL-5 .6 /mysql-5 .6.32. tar .gz -P  /opt/src/
   fi
   cd  /opt/src/
   tar  -zxvf  /opt/src/mysql-5 .6.32. tar .gz
fi 
cd  /opt/src/mysql-5 .6.32
cmake . -DCMAKE_INSTALL_PREFIX=${base_dir} -DMYSQL_DATADIR=${data_dir} -DMYSQL_UNIX_ADDR=${data_dir}mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_g
eneral_ci -DWITH_DEBUG=0
if  "$?"  - ne  "0"  ]; then
     echo  -e  'Configure mysql failure,Please check compile Environment...'
     exit  2
fi
make  -j 3 
if  "$?"  - ne  "0"  ]; then
     echo  'Error,please look config.log for more information...'
     exit  2
fi
make  install
if  "$?"  - eq  "0"  ]; then
     echo  -e  'Mysql install complete done...'
else
     echo  -e  'Something wrong between Installation...'
fi
#Initialization mysql..
echo  -e  'Initialization mysql...'
cd  ${src_dir}mysql-5.6.32
cp  support-files /my-default .cnf ${data_dir} /my .cnf
cp  support-files /mysql .server  /etc/init .d /mysqld
sed  -i -e  '46s/basedir=/basedir=${base_dir}/'  -e  '47s/datadir=/datadir=${data_dir}/'   /etc/init .d /mysqld
chmod  a+x  /etc/init .d /mysqld
chkconfig --add mysqld
sed  -i -e  "s#@HOSTNAME@#hostname#"   . /scripts/mysql_install_db .sh
sh . /scripts/mysql_install_db .sh --user=mysql --basedir=${base_dir} --datadir=${data_dir}   >  /dev/null  2>&1
chown  -R mysql.mysql  /opt/apps/mysql/
chown  -R mysql.mysql  /opt/data/mysql/
#Start mysql...
ulimit  -s unlimited
service mysqld start
}
#######php###########################################################
Install_php ()
{
if  [ ! -f  /opt/src/php-7 .0.10. tar .gz ]; then
   echo  -e  "\033[33m Download php-7.0.10.tar.gz......\033[0m" 
   wget http: //cn2 .php.net /get/php-7 .0.10. tar .gz /from/this/mirror  -P  /opt/src
   cd  /opt/src  &&   mv  mirror php-7.0.10. tar .gz
fi
echo  -e  "\033[33m Complising and installing php-7.0.10 ......\033[0m" 
tar  -zxvf php-7.0.10. tar .gz
cd  php-7.0.10
yum  install  -y php-mcrypt libmcrypt libmcrypt-devel libjpeg-turbo-devel.x86_64   
. /configure  --prefix= /opt/apps/php  --with-config- file -path= /opt/apps/php/etc  --with-mcrypt= /usr/include  --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib -- enable -xml -- enable -bcmath 
-- enable -shmop -- enable -sysvsem -- enable -inline-optimization -- enable -mbregex -- enable -fpm -- enable -mbstring -- enable - ftp  -- enable -gd-native-ttf --with-openssl -- enable -pcntl -- enable -sockets --with-xmlrpc -- enable -zip -- enable -soap --w
ithout-pear --with-gettext -- enable -session --with-curl --with-jpeg- dir  --with-freetype- dir  -- enable -opcache
if  [ $? - eq  "0" ]; then
   echo  -e  "\033[31m Php install faild....Please check and try again....\033[0m"
   exit
fi
make  &&  make  install
cp  php.ini-production  /opt/apps/php/etc/php .ini
cp  sapi /fpm/init .d.php-fpm  /etc/init .d /php7-fpm   
cp  /opt/apps/php/etc/php-fpm .conf.default  /opt/apps/php/etc/php-fpm .conf     
cp  /opt/apps/php/etc/php-fpm .d /www .conf.default  /opt/apps/php/etc/php-fpm .d /www .conf
echo  "zend_extension=/opt/apps/php/lib/php/extensions/no-debug-non-zts-20151012/opcache.so"  >>  /opt/apps/php/etc/php .ini
chmod  775  /etc/init .d /php7-fpm
echo  -e  "\033[33m Starting php7-frm service......\033[0m" 
/etc/init .d /php7-fpm  start
if  [ $? - eq  "0"  ]; then
   echo  -e  "\032[33m PHP installed and started successfully......\033[0m" 
else :
   echo  -e  "\033[31m PHP installed successfully,but start failed,please check the configuration of php......\033[0m" 
fi
}
 
 
###############################Main program######################################
mkdir  -p  /opt/ {apps,conf,src,data}
read  -p  "Which part of lnmp you want to install?(nginx|mysql|php|all):"  softwar
case  ${softwar}  in 
nginx)
  Install_nginx
;;
mysql)
  Install_mysql
;;
php)
Install_php
;;
all)
if  [ -d  /opt/apps/nginx  ]; then
  echo  -e  "\033[33m Nginx was already installed in your system...\033[0m"
else
   Install_nginx
fi
if  [ -d  /opt/apps/mysql  ]; then
  echo  -e  "\033[33m Mysql was already installed in your system...\033[0m"
else
   Install_mysql
fi
if  [ -d  /opt/apps/php  ]; then
  echo  -e  "\033[33m PHP was already installed in your system...\033[0m"
else
  Install_php
fi
;;
*)
echo  -e  "\033[33m Sorry,please input a right choice\033[0m"
esac









本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/1841585,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值