shell脚本安装-LNMP环境

运行系统:CentOS-7

一、安装LNMP环境:

  1 #!/bin/bash
  2 #####################################################
  3 #Create date 2018.4.10
  4 #Author: wansheng
  5 #Function: shell script install LNMP
  6 #Email: 1447646759@qq.com 
  7 #system: Linux CentOS-7
  8 #####################################################
  9 
 10 ####################################以下是nginx安装配置####################################################
 11 if [ $UID -ne 0 ];then
 12         please use root user running script!!
 13         exit 1
 14 fi
 15 #下载安装包
 16 zlib_name="https://jaist.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz"
 17 nginx_name="http://nginx.org/download/nginx-1.13.10.tar.gz"
 18 pcre_name="https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz"
 19 openssl_name="https://www.openssl.org/source/openssl-1.1.1-pre3.tar.gz"
 20 #安装包目录定义
 21 nginx_dir=`echo $nginx_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 22 zlib_dir=`echo $zlib_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 23 pcre_dir=`echo $pcre_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2}'`
 24 openssl_dir=`echo $openssl_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 25 ##################################安装目录及服务目录##############################
 26 
 27 nginx_install_dir=/server/application/${nginx_dir}
 28 nginx_server_dir=/usr/local/nginx
 29 nginx_user_add=`cat /etc/passwd|grep nginx|wc -l`
 30 [ ! -d /root/soft ] && mkdir -p /root/soft
 31 [ ! -d /server/application ] && mkdir -p /server/application
 32 if [ $nginx_user_add -eq 0 ];then
 33     groupadd nginx
 34     useradd -M -g nginx -s /sbin/nologin nginx
 35 fi
 36 ##########################################################################
 37 #依赖包数组定义
 38 package=(
 39 wget
 40 curl
 41 gcc
 42 gcc-c++
 43 libxml2-devel
 44 gd-devel
 45 GeoIP
 46 GeoIP-devel
 47 perl
 48 perl-devel
 49 perl-ExtUtils-Embed
 50 libxslt
 51 libxslt-devel
 52 lsof
 53 make
 54 tree
 55 lrzsz
 56 )
 57 #安装包
 58 software=(
 59 $zlib_name
 60 $nginx_name
 61 $pcre_name
 62 $openssl_name
 63 )
 64 #############################################################################
 65 function check(){
 66 if [ $? -ne 0 ];then
 67         exit 2
 68 fi
 69 }
 70 ###########################安装依赖包和下载依赖包#####################################
 71 function package_install(){
 72 cd /root/soft
 73 yum -y groupinstall "Development Tools"
 74 for i in ${package[*]}
 75 do
 76     yum -y install $i
 77     check
 78 done
 79 for soft in ${software[*]}
 80 do
 81     tar_ls=`echo $soft |awk -F"[/]" '{print $NF}'`
 82     if [ -f $tar_ls ];then
 83         tar zxvf $tar_ls
 84     else
 85         wget $soft
 86         tar zxvf $tar_ls
 87     fi
 88     check
 89 done
 90 }
 91 ###########################安装nginx服务########################################
 92 
 93 function nginx_install(){
 94 
 95 cd /root/soft/$nginx_dir
 96 ./configure --prefix=/server/application/$nginx_dir --user=nginx --group=nginx --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_xslt_module=dynamic --with-http_image_filter_module --with-http_image_filter_module=dynamic --with-http_geoip_module --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-pcre=/root/soft/${pcre_dir} --with-zlib=/root/soft/${zlib_dir} --with-openssl=/root/soft/${openssl_dir}
 97 check
 98 make
 99 check
100 make install
101 check
102 }
103 ############################优化nginx配置##########################################
104 function nginx_optimize(){
105     ln -s ${nginx_install_dir} ${nginx_server_dir}
106     ln -s ${nginx_server_dir}/sbin/* /usr/local/bin/
107     ln -s ${nginx_server_dir}/sbin/* /etc/init.d/nginxd
108     processor=`cat /proc/cpuinfo | grep "processor" | wc -l`
109     sed -i "s/^w.*;$/worker_processes  ${processor};/g" ${nginx_server_dir}/conf/nginx.conf
110 }
111 ###########################启动nginx服务#############################################
112 function nginx_run(){
113     cd ${nginx_server_dir}/sbin/
114     ./nginx
115     check
116     lsof -i:80
117     curl -I -s --connect-timeout 10 http://127.0.0.1
118     check
119     tree ${nginx_server_dir}
120     echo -e "33[32;1m 恭喜您,nginx安装成功33[0m"
121 }
122 
123 ##################################################################################
124 
125 ##################################以下是php5.6安装配置############################
126 
127 php_name="http://cn2.php.net/distributions/php-5.6.35.tar.gz"
128 libiconv_name="http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz"
129 
130 php_dir=`echo $php_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
131 libiconv_dir=`echo $libiconv_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
132 php_install_dir="/server/application/${php_dir}"
133 
134 [ ! -d /root/soft ] && mkdir -p /root/soft
135 [ ! -d /server/application ] && mkdir -p /server/application
136 php_peckage=(
137 zlib-devel
138 libxml2-devel
139 libjpeg-devel
140 libjpeg-turbo-devel
141 freetype-devel
142 libpng-devel
143 gd-devel
144 libcurl-devel
145 libxslt-devel
146 openssl
147 openssl-devel
148 wget
149 )
150 php_software=(
151 $php_name
152 $libiconv_name
153 )
154 ############################################################
155 function php_check(){
156 if [ $? -ne 0 ];then
157         echo $_
158         exit 2
159 fi
160 }
161 
162 function php_install_peckage(){
163 
164 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
165 cd /root/soft
166 yum -y groupinstall "Development Tools"
167 if [ `cat /etc/passwd |grep www | grep -v grep|wc -l` -ne 1 ];then
168     useradd www
169 fi
170 for php_i in ${php_peckage[*]}
171 do
172     echo $php_i
173     yum -y install ${php_i}
174 done
175 for php_s in ${php_software[*]}
176 do
177 echo $php_s    
178     tar_l=`echo $php_s |awk -F"[/]" '{print $NF}'`
179     if [ -f $tar_l ];then
180         tar zxvf $tar_l
181     else
182                  wget $php_s
183                  tar zxvf $tar_l
184 
185     fi
186     echo $tar_l
187 
188 done
189 }
190 ###########################php5.6安装###############################
191 function php_install(){
192 cd /root/soft/$php_dir
193 ./configure 
194 --prefix=$php_install_dir 
195 --with-pdo-mysql=mysqlnd 
196 --with-mysqli=mysqlnd 
197 --with-mysql=mysqlnd 
198 --with-jpeg-dir 
199 --with-png-dir 
200 --with-zlib 
201 --enable-xml 
202 --with-libxml-dir 
203 --with-curl 
204 --enable-bcmath 
205 --enable-shmop 
206 --enable-wddx 
207 --enable-sysvsem 
208 --enable-sysvshm 
209 --enable-inline-optimization 
210 --enable-mbregex 
211 --with-openssl 
212 --enable-mbstring 
213 --with-gd 
214 --enable-gd-native-ttf 
215 --with-freetype-dir=/usr/lib64 
216 --with-gettext=/usr/lib64 
217 --enable-sockets 
218 --with-xmlrpc 
219 --enable-zip 
220 --enable-soap 
221 --disable-debug 
222 --enable-opcache 
223 --enable-zip 
224 --with-config-file-path=${php_install_dir}/etc 
225 --enable-fpm 
226 --with-fpm-user=www 
227 --with-fpm-group=www 
228 --with-tsrm-pthreads 
229 --with-iconv-dir=/root/soft/libiconv-1.15
230 php_check
231 make
232 php_check
233 make install
234 php_check
235 }
236 ###########################php优化配置#############################
237 function php_optimize(){
238 ln -s /server/application/php-5.6.35 /usr/local/php5
239 cp /root/soft/php-5.6.35/php.ini-development /usr/local/php5/etc/php.ini
240 cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
241 /usr/local/php5/sbin/php-fpm
242 ps -ef|grep php
243 ss -tunl|grep 9000
244 echo -e "33[32;1m 恭喜您,php5.6安装成功33[0m"
245 }
246 #####################################################################################
247 ################Mysql5.7安装
248 ######################################################################################
249 mysql_download="wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.16.tar.gz"
250 mysql_name=`echo $mysql_download |awk -F"[/]" '{print $NF}'`
251 mysql_dir="mysql-5.7.16"
252 mysql_data_dir="/data/mysql"
253 echo "$mysql_name"
254 mysql_install_dir="/server/application/$mysql_dir"
255 [ ! -d /root/soft ] && mkdir -p /root/soft
256 [ ! -d /mysql/data ] && mkdir -p /mysql/data
257 mysql_peckage=(
258 gcc
259 gcc-c++
260 ncurses
261 ncurses-devel
262 cmake
263 )
264 function check(){
265 if [ $? -ne 0 ];then
266     echo $_
267     exit 1
268 fi
269 }
270 function mysql_peckage_install(){
271 if [ `cat /etc/passwd |grep -v grep |grep mysql|wc -l` -ne 1 ];then
272     useradd -M -s /sbin/nologin mysql
273 fi
274 for mysql_i in ${mysql_peckage[*]}
275 do
276     echo $mysql_i
277     yum -y install $mysql_i
278 done
279 cd /root/soft
280 if [ ! -f ${mysql_name} ];then
281     wget $mysql_download
282     tar zxvf $mysql_name
283     cd /root/soft/$mysql_dir
284     echo 111
285 else
286     rm -fr $mysql_dir
287     tar zxvf $mysql_name
288     cd /root/soft/$mysql_dir
289     echo 222
290 fi
291 }
292 function mysql_install (){
293 cd /root/soft/mysql-5.7.16
294 cmake -DCMAKE_INSTALL_PREFIX=/server/application/$mysql_dir 
295 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock 
296 -DMYSQL_DATADIR=/mysql/data 
297 -DSYSCONFDIR=/etc/ 
298 -DWITH_MYISAM_STORAGE_ENGINE=1 
299 -DWITH_INNOBASE_STORAGE_ENGINE=1 
300 -DWITH_MEMORY_STORAGE_ENGINE=1 
301 -DWITH_READLINE=1 
302 -DMYSQL_TCP_PORT=3306 
303 -DENABLED_LOCAL_INFILE=1 
304 -DWITH_PARTITION_STORAGE_ENGINE=1 
305 -DEXTRA_CHARSETS=all 
306 -DDEFAULT_CHARSET=utf8 
307 -DDEFAULT_COLLATION=utf8_general_ci 
308 -DMYSQL_USER=mysql 
309 -DWITH_BOOST=/root/soft/mysql-5.7.16/boost/boost_1_59_0
310 check
311 make
312 check
313 make install
314 }
315 function mysql_config(){
316 ln -s /server/application/$mysql_dir /usr/local/mysql
317 chown mysql.mysql /usr/local/mysql -R
318 cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
319 echo >> "export PATH=/usr/local/mysql/bin:$PATH" /etc/profile
320 source /etc/profile
321 /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/mysql/data/
322 cd /usr/local/mysql/support-files
323 ./mysql.server start
324 ss -tunl |grep 3306
325 }
326 ###############################php安装函数######################
327 php_main (){
328 php_install_peckage
329 php_install
330 php_optimize
331 }
332 #php_main
333 #########################nginx安装函数#########################
334 nginx_main (){
335     package_install
336     check
337     nginx_install
338     check
339     nginx_optimize
340     check
341     nginx_run
342 }
343 #nginx_main
344 ###########################mysql安装函数###############################
345 mysql_main(){
346 mysql_peckage_install
347 mysql_install
348 mysql_config
349 }
350 #mysql_main
351 ########################################################################
352 echo -e "[1] running install php5.6 serveirs
353 [2] running install nginx1.13 servers
354 [3] running install mysql5.7 servers
355 [all] running install all servers
356 "
357 read -p "please input install servers[1]|[2]|[3]|[all]:" server_s
358 case $server_s in
359     1)
360     read -p "Please confirm your input [yes]:" confirm
361         case $confirm in
362             yes|YES|YEs|yEs|yeE)
363                 php_main
364                     ;;
365                     *)
366                     exit
367         esac
368     ;;
369     2)
370     read -p "Please confirm your input [yes]:" confirm
371                case $confirm in
372                         yes|YES|YEs|yEs|yeE)
373                                nginx_main
374                                         ;;
375                                         *)
376                                         exit
377         esac
378     ;;
379     3)
380      read -p "Please confirm your input [yes]:" confirm
381                 case $confirm in
382                         yes|YES|YEs|yEs|yeE)
383                                mysql_main
384                                         ;;
385                                         *)
386                                         exit
387         esac
388 
389     ;;
390     all|ALL)
391             read -p "Please confirm your input [yes]:" confirm
392                 case $confirm in
393                         yes|YES|YEs|yEs|yeE)
394                                nginx_main
395                 php_main
396                 mysql_main
397                                         ;;
398                                         *)
399                                         exit
400         esac
401     ;;
402     *)
403     echo -e "33[32;1m please input install servers[ 1 | 2 | 3 | all ]!!!33[0m"
404     exit
405 esac
LNMP-install

二、shell-Apache安装

  1 #!/bin/bash
  2 #####################################################
  3 #Create date 2018.4.10
  4 #Author: wansheng
  5 #Function: shell script install Apache2.4
  6 #Email: 1447646759@qq.com 
  7 #system: Linux CentOS-7
  8 #####################################################
  9 if [ $UID -ne 0 ];then
 10         please use root user running script!!
 11         exit 1
 12 fi
 13 #下载安装包
 14 apache_name="https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.33.tar.gz"
 15 zlib_name="https://jaist.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz"
 16 apr_name="https://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz"
 17 apr_util_name="https://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz"
 18 pcre_name="https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz"
 19 openssl_name="https://www.openssl.org/source/openssl-1.1.1-pre3.tar.gz"
 20 libxml2_name="http://distfiles.macports.org/libxml2/libxml2-2.9.7.tar.gz"
 21 #安装包目录定义
 22 apache_dir=`echo $apache_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 23 zlib_dir=`echo $zlib_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 24 pcre_dir=`echo $pcre_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2}'`
 25 openssl_dir=`echo $openssl_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 26 libxml2_dir=`echo $libxml2_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 27 apr_dir=`echo $apr_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 28 apr_util_dir=`echo $apr_util_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 29 
 30 ##################################安装目录及服务目录##############################
 31 
 32 apache_install_dir=/server/application/${nginx_dir}
 33 apache_server_dir=/usr/local/apche
 34 [ ! -d /root/soft ] && mkdir -p /root/soft
 35 [ ! -d /server/application ] && mkdir -p /server/application
 36 
 37 package=(
 38 wget
 39 curl
 40 gcc
 41 gcc-c++
 42 libxml2-devel
 43 gd-devel
 44 GeoIP
 45 GeoIP-devel
 46 perl
 47 perl-devel
 48 perl-ExtUtils-Embed
 49 libxslt
 50 libxslt-devel
 51 lsof
 52 make
 53 tree
 54 lrzsz
 55 expat
 56 expat-devel
 57 lua
 58 lua-devel
 59 openssl
 60 openssl-devel
 61 )
 62 #安装包
 63 software=(
 64 $zlib_name
 65 $apache_name
 66 $pcre_name
 67 $openssl_name
 68 $libxml2_name
 69 $apr_name
 70 $apr_util_name
 71 )
 72 ############################################################################
 73 
 74 function apache_check(){
 75 if [ $? -ne 0 ];then
 76         echo $_
 77     echo "please check error!!!!!"
 78         exit 2
 79 fi
 80 }
 81 
 82 #########################################################
 83 function package_install(){
 84 yum -y groupinstall "Development Tools"
 85 for package_i in ${package[*]}
 86 do    
 87     rpm -ql $package_i
 88     if [ $? -ne 0 ];then
 89         yum -y install $package_i
 90         echo $package_i
 91     else
 92         continue    
 93     fi
 94 done
 95 cd /root/soft
 96 for software_i in ${software[*]}
 97 do
 98     echo $software_i
 99     software_ls=`echo $software_i |awk -F"[/]" '{print $NF}'`
100         if [ -f $software_ls ];then
101                 tar zxvf $software_ls
102         else
103                 wget $software_i
104                 tar zxvf $software_ls
105         fi
106 done
107 }
108 #########################################################
109 function apr_install(){
110 if [ ! -d /usr/local/apr ];then
111     cd /root/soft/$apr_dir
112     ./configure --prefix=/usr/local/apr
113     apache_check
114     make
115     apache_check
116     make install
117     apache_check
118     cd /root/soft/$apr_util_dir
119     ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-crypto
120     apache_check
121     make
122     apache_check
123     make install
124     apache_check
125     echo 2222
126 else
127     echo 111
128 fi
129 }
130 function pcre_install(){
131 if [ ! -d /usr/local/pcre ];then
132         cd /root/soft/$pcre_dir
133         ./configure --prefix=/usr/local/pcre --enable-utf8
134         apache_check
135         make
136         apache_check
137         make install
138         apache_check
139     echo 2222
140 else
141     echo 111
142 fi
143 }
144 function apache_install(){
145 cd /root/soft/$apache_dir
146 ./configure 
147 --prefix=/server/application/apache-2.4 
148 --with-apr=/usr/local/apr 
149 --with-apr-util=/usr/local/apr-util 
150 --with-pcre=/usr/local/pcre 
151 --with-z=/root/soft/zlib-1.2.11 
152 --with-libxml2=/root/soft/libxml2-2.9.7 
153 --with-ssl 
154 --with-curl 
155 --with-mpm=prefork 
156 --enable-so 
157 --enable-authnz-fcgi 
158 --enable-file-cache 
159 --enable-cache 
160 --enable-cache-disk 
161 --enable-cache-socache 
162 --enable-cgi 
163 --enable-rewrite 
164 --enable-mpms-shared 
165 --enable-proxy 
166 --enable-proxy-connect 
167 --enable-proxy-ftp 
168 --enable-proxy-http 
169 --enable-proxy-fcgi 
170 --enable-proxy-scgi 
171 --enable-proxy-express 
172 --enable-proxy-hcheck 
173 --enable-slotmem-shm 
174 --enable-slotmem-plain 
175 --enable-ssl 
176 --enable-ssl-staticlib-deps 
177 --enable-static-support 
178 --enable-static-htpasswd 
179 --enable-static-htdigest 
180 --enable-static-htdbm 
181 --enable-static-ab 
182 --enable-static-logresolve 
183 --enable-unixd 
184 --enable-expires 
185 --enable-authn-dbm 
186 --enable-lua 
187 --enable-luajit 
188 --libdir=/usr/lib64
189 apache_check
190 make
191 apache_check
192 make install
193 apache_check
194 }
195 function apache_optimize(){
196 ln -s /server/application/apache-2.4 /usr/local/apache
197 sed -i 's/#Server.*80/ServerName localhost:80/g' /server/application/apache-2.4/conf/httpd.conf
198 /usr/local/apache/bin/apachectl -k start
199 apache_check
200 ss -tunl|grep 80
201 curl -I -s http://127.0.0.1|awk NR==1
202 apache_check
203 echo -e "33[32;1m 恭喜您,Apache-2.4安装成功33[0m"
204 }
205 main(){
206 package_install
207 apr_install
208 pcre_install
209 apache_install
210 apache_optimize
211 }
212 main
Apache-install

三、shell-NGINX安装

  1 #!/bin/bash
  2 #####################################################
  3 #Create date 2018.4.10
  4 #Author: wansheng
  5 #Function: shell script install nginx-1.13.10
  6 #Email: 1447646759@qq.com 
  7 #System: Linux CentOS-7
  8 #####################################################
  9 if [ $UID -ne 0 ];then
 10         please use root user running script!!
 11         exit 1
 12 fi
 13 #下载安装包
 14 zlib_name="https://jaist.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz"
 15 nginx_name="http://nginx.org/download/nginx-1.13.10.tar.gz"
 16 pcre_name="https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz"
 17 openssl_name="https://www.openssl.org/source/openssl-1.1.1-pre3.tar.gz"
 18 #安装包目录定义
 19 nginx_dir=`echo $nginx_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 20 zlib_dir=`echo $zlib_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 21 pcre_dir=`echo $pcre_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2}'`
 22 openssl_dir=`echo $openssl_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 23 ##################################安装目录及服务目录##############################
 24 
 25 nginx_install_dir=/server/application/${nginx_dir}
 26 nginx_server_dir=/usr/local/nginx
 27 nginx_user_add=`cat /etc/passwd|grep nginx|wc -l`
 28 [ ! -d /root/soft ] && mkdir -p /root/soft
 29 [ ! -d /server/application ] && mkdir -p /server/application
 30 if [ $nginx_user_add -eq 0 ];then
 31     groupadd nginx
 32     useradd -M -g nginx -s /sbin/nologin nginx
 33 fi
 34 ##########################################################################
 35 #依赖包数组定义
 36 package=(
 37 wget
 38 curl
 39 gcc
 40 gcc-c++
 41 libxml2-devel
 42 gd-devel
 43 GeoIP
 44 GeoIP-devel
 45 perl
 46 perl-devel
 47 perl-ExtUtils-Embed
 48 libxslt
 49 libxslt-devel
 50 lsof
 51 make
 52 tree
 53 lrzsz
 54 )
 55 #安装包
 56 software=(
 57 $zlib_name
 58 $nginx_name
 59 $pcre_name
 60 $openssl_name
 61 )
 62 #############################################################################
 63 function check(){
 64 if [ $? -ne 0 ];then
 65         exit 2
 66 fi
 67 }
 68 #######################################################################
 69 function package_install(){
 70 cd /root/soft
 71 yum -y groupinstall "Development Tools"
 72 for i in ${package[*]}
 73 do
 74     yum -y install $i
 75     check
 76 done
 77 for soft in ${software[*]}
 78 do
 79     tar_ls=`echo $soft |awk -F"[/]" '{print $NF}'`
 80     if [ -f $tar_ls ];then
 81         tar zxvf $tar_ls
 82     else
 83         wget $soft
 84         tar zxvf $tar_ls
 85     fi
 86     check
 87 done
 88 }
 89 #################################################################################
 90 
 91 function nginx_install(){
 92 
 93 cd /root/soft/$nginx_dir
 94 ./configure 
 95 --prefix=/server/application/$nginx_dir 
 96 --user=nginx 
 97 --group=nginx 
 98 --with-select_module 
 99 --with-poll_module 
100 --with-threads 
101 --with-file-aio 
102 --with-http_ssl_module 
103 --with-http_v2_module 
104 --with-http_realip_module 
105 --with-http_addition_module 
106 --with-http_xslt_module 
107 --with-http_xslt_module=dynamic 
108 --with-http_image_filter_module 
109 --with-http_image_filter_module=dynamic 
110 --with-http_geoip_module 
111 --with-http_geoip_module=dynamic 
112 --with-http_sub_module 
113 --with-http_dav_module 
114 --with-http_flv_module 
115 --with-http_mp4_module 
116 --with-http_gunzip_module 
117 --with-http_gzip_static_module 
118 --with-http_auth_request_module 
119 --with-http_random_index_module 
120 --with-http_secure_link_module 
121 --with-http_degradation_module 
122 --with-http_slice_module 
123 --with-http_stub_status_module 
124 --with-http_perl_module 
125 --with-mail=dynamic 
126 --with-mail_ssl_module 
127 --with-stream=dynamic 
128 --with-stream_ssl_module 
129 --with-stream_realip_module 
130 --with-stream_geoip_module 
131 --with-stream_geoip_module=dynamic 
132 --with-stream_ssl_preread_module 
133 --with-pcre=/root/soft/${pcre_dir} 
134 --with-zlib=/root/soft/${zlib_dir} 
135 --with-openssl=/root/soft/${openssl_dir}
136 check
137 make
138 check
139 make install
140 check
141 }
142 #################################################################################
143 function nginx_optimize(){
144     ln -s ${nginx_install_dir} ${nginx_server_dir}
145     ln -s ${nginx_server_dir}/sbin/* /usr/local/bin/
146     ln -s ${nginx_server_dir}/sbin/* /etc/init.d/nginxd
147     processor=`cat /proc/cpuinfo | grep "processor" | wc -l`
148     sed -i "s/^w.*;$/worker_processes  ${processor};/g" ${nginx_server_dir}/conf/nginx.conf
149 }
150 function nginx_run(){
151     cd ${nginx_server_dir}/sbin/
152     ./nginx
153     check
154     lsof -i:80
155     curl -I -s --connect-timeout 10 http://127.0.0.1
156     check
157     tree ${nginx_server_dir}
158     echo -e "33[32;1m 恭喜您,nginx安装成功33[0m"
159 }
160 
161 ##################################################################################
162 main (){
163     package_install
164     check
165     nginx_install
166     check
167     nginx_optimize
168     check
169     nginx_run
170 }
171 main
NGINX-install

四、shell-MySQL安装

 1 #!/bin/bash
 2 #####################################################
 3 #Create date 2018.4.10
 4 #Author: wansheng
 5 #Function: shell script install mysql-5.7.16 
 6 #Email: 1447646759@qq.com 
 7 #System: Linux CentOS-7
 8 #####################################################
 9 if [ $UID -ne 0 ];then
10         please use root user running script!!
11         exit 1
12 fi
13 mysql_download="wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.16.tar.gz"
14 mysql_name=`echo $mysql_download |awk -F"[/]" '{print $NF}'`
15 mysql_dir="mysql-5.7.16"
16 mysql_data_dir="/data/mysql"
17 echo "$mysql_name"
18 mysql_install_dir="/server/application/$mysql_dir"
19 [ ! -d /root/soft ] && mkdir -p /root/soft
20 [ ! -d /mysql/data ] && mkdir -p /mysql/data
21 mysql_peckage=(
22 gcc
23 gcc-c++
24 ncurses
25 ncurses-devel
26 cmake
27 )
28 function check(){
29 if [ $? -ne 0 ];then
30     exit 1
31 fi
32 }
33 function mysql_peckage_install(){
34 if [ `cat /etc/passwd |grep -v grep |grep mysql|wc -l` -ne 1 ];then
35     useradd -M -s /sbin/nologin mysql
36 fi
37 for mysql_i in ${mysql_peckage[*]}
38 do
39     echo $mysql_i
40     yum -y install $mysql_i
41 done
42 cd /root/soft
43 if [ ! -f ${mysql_name} ];then
44     wget $mysql_download
45     tar zxvf $mysql_name
46     cd /root/soft/$mysql_dir
47     echo 111
48 else
49     rm -fr ./$mysql_dir
50     tar zxvf $mysql_name
51     cd /root/soft/$mysql_dir
52     echo 222
53 fi
54 }
55 function mysql_install (){
56 cd /root/soft/mysql-5.7.16
57 cmake -DCMAKE_INSTALL_PREFIX=/server/application/$mysql_dir 
58 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock 
59 -DMYSQL_DATADIR=/mysql/data 
60 -DSYSCONFDIR=/etc/ 
61 -DWITH_MYISAM_STORAGE_ENGINE=1 
62 -DWITH_INNOBASE_STORAGE_ENGINE=1 
63 -DWITH_MEMORY_STORAGE_ENGINE=1 
64 -DWITH_READLINE=1 
65 -DMYSQL_TCP_PORT=3306 
66 -DENABLED_LOCAL_INFILE=1 
67 -DWITH_PARTITION_STORAGE_ENGINE=1 
68 -DEXTRA_CHARSETS=all 
69 -DDEFAULT_CHARSET=utf8 
70 -DDEFAULT_COLLATION=utf8_general_ci 
71 -DMYSQL_USER=mysql 
72 -DWITH_BOOST=/root/soft/mysql-5.7.16/boost/boost_1_59_0
73 check
74 make
75 check
76 make install
77 }
78 function mysql_config(){
79 ln -s /server/application/$mysql_dir /usr/local/mysql
80 chown mysql.mysql /usr/local/mysql -R
81 cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
82 echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
83 source /etc/profile
84 /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/mysql/data
85 cd /usr/local/mysql/support-files
86 ./mysql.server start
87 ss -tunl |grep 3306
88 check
89 echo -e "33[32;1m 恭喜您,mysql安装成功33[0m"
90 }
91 
92 main(){
93 mysql_peckage_install
94 mysql_install
95 mysql_config
96 }
97 main
MySQL-install

五、shell-PHP-5安装

#!/bin/bash
#####################################################
#Create date 2018.4.10
#Author: wansheng
#Function: shell script install php-5.6.35
#Email: 1447646759@qq.com 
#System: Linux CentOS-7
#####################################################
if [ $UID -ne 0 ];then
        please use root user running script!!
        exit 1
fi
php_name="http://cn2.php.net/distributions/php-5.6.35.tar.gz"
libiconv_name="http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz"

php_dir=`echo $php_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
libiconv_dir=`echo $libiconv_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
php_install_dir="/server/application/${php_dir}"

[ ! -d /root/soft ] && mkdir -p /root/soft
[ ! -d /server/application ] && mkdir -p /server/application
php_peckage=(
zlib-devel
libxml2-devel
libjpeg-devel
libjpeg-turbo-devel
freetype-devel
libpng-devel
gd-devel
libcurl-devel
libxslt-devel
openssl
openssl-devel
wget
)
php_software=(
$php_name
$libiconv_name
)
############################################################
function php_check(){
if [ $? -ne 0 ];then
        exit 2
fi
}

function php_install_peckage(){

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
cd /root/soft
yum -y groupinstall "Development Tools"
if [ `cat /etc/passwd |grep www | grep -v grep|wc -l` -ne 1 ];then
    useradd www
fi
for php_i in ${php_peckage[*]}
do
    echo $php_i
    yum -y install ${php_i}
done
for php_s in ${php_software[*]}
do
echo $php_s    
    tar_l=`echo $php_s |awk -F"[/]" '{print $NF}'`
    if [ -f $tar_l ];then
        tar zxvf $tar_l
    else
                 wget $php_s
                 tar zxvf $tar_l

    fi
    echo $tar_l

done
}
###########################php5.6安装###############################
function php_install(){
cd /root/soft/$php_dir
./configure 
--prefix=$php_install_dir 
--with-pdo-mysql=mysqlnd 
--with-mysqli=mysqlnd 
--with-mysql=mysqlnd 
--enable-mysqlnd 
--with-jpeg-dir 
--with-png-dir 
--with-zlib 
--enable-xml 
--with-libxml-dir 
--with-curl 
--enable-bcmath 
--enable-shmop 
--enable-wddx 
--enable-sysvsem 
--enable-sysvshm 
--enable-inline-optimization 
--enable-mbregex 
--with-openssl 
--enable-mbstring 
--with-gd 
--enable-gd-native-ttf 
--with-freetype-dir=/usr/lib64 
--with-gettext=/usr/lib64 
--enable-sockets 
--with-xmlrpc 
--enable-zip 
--enable-soap 
--disable-debug 
--enable-opcache 
--enable-zip 
--with-config-file-path=${php_install_dir}/etc 
--enable-fpm 
--with-fpm-user=www 
--with-fpm-group=www 
--with-tsrm-pthreads 
--with-iconv-dir=/root/soft/libiconv-1.15
php_check
make
php_check
make install
php_check
}
###########################php优化配置#############################
function php_optimize(){
ln -s /server/application/php-5.6.35 /usr/local/php5
cp /root/soft/php-5.6.35/php.ini-development /usr/local/php5/etc/php.ini
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
ps -ef|grep -v grep|grep "php-fpm"|awk '{print "kill -9",$2}'|bash
/usr/local/php5/sbin/php-fpm
ps -ef|grep php
ss -tunl|grep 9000
echo -e "33[32;1m 恭喜您,php5.6安装成功33[0m"
}
main (){
php_install_peckage
php_install
php_optimize
}
main
PHP-5-install

六、shell-PHP-7安装

  1 #!/bin/bash
  2 #####################################################
  3 #Create date 2018.4.10
  4 #Author: wansheng
  5 #Function: shell script install php-5.6.35
  6 #Email: 1447646759@qq.com 
  7 #System: Linux CentOS-7
  8 #####################################################
  9 if [ $UID -ne 0 ];then
 10         please use root user running script!!
 11         exit 1
 12 fi
 13 php_name="http://cn2.php.net/distributions/php-7.2.4.tar.gz"
 14 libiconv_name="http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz"
 15 
 16 php_dir=`echo $php_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 17 libiconv_dir=`echo $libiconv_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'`
 18 php_install_dir="/server/application/${php_dir}"
 19 
 20 [ ! -d /root/soft ] && mkdir -p /root/soft
 21 [ ! -d /server/application ] && mkdir -p /server/application
 22 php_peckage=(
 23 zlib-devel
 24 libxml2-devel
 25 libjpeg-devel
 26 libjpeg-turbo-devel
 27 freetype-devel
 28 libpng-devel
 29 gd-devel
 30 libcurl-devel
 31 libxslt-devel
 32 openssl
 33 openssl-devel
 34 wget
 35 libmcrypt-devel
 36 libmcrypt
 37 libacl
 38 libacl-devel
 39 postgresql-devel
 40 )
 41 php_software=(
 42 $php_name
 43 $libiconv_name
 44 )
 45 ############################################################
 46 function php_check(){
 47 if [ $? -ne 0 ];then
 48         exit 2
 49 fi
 50 }
 51 
 52 function php_install_peckage(){
 53 
 54 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
 55 cd /root/soft
 56 yum -y groupinstall "Development Tools"
 57 if [ `cat /etc/passwd |grep www | grep -v grep|wc -l` -ne 1 ];then
 58     useradd www
 59 fi
 60 for php_i in ${php_peckage[*]}
 61 do
 62     echo $php_i
 63     yum -y install ${php_i}
 64 done
 65 for php_s in ${php_software[*]}
 66 do
 67 echo $php_s    
 68     tar_l=`echo $php_s |awk -F"[/]" '{print $NF}'`
 69     if [ -f $tar_l ];then
 70         tar zxvf $tar_l
 71     else
 72                  wget $php_s
 73                  tar zxvf $tar_l
 74 
 75     fi
 76     echo $tar_l
 77 
 78 done
 79 }
 80 ###########################php5.6安装###############################
 81 function php_install(){
 82 cd /root/soft/$php_dir
 83 ./configure 
 84 --prefix=/server/application/php-7.2.4 
 85 --with-apxs2=/server/application/apache-2.4/bin/apxs 
 86 --enable-fpm 
 87 --with-fpm-user=www 
 88 --with-fpm-group=www 
 89 --enable-sysvmsg 
 90 --enable-sysvsem 
 91 --enable-sysvshm 
 92 --enable-bcmath 
 93 --enable-exif 
 94 --enable-ftp 
 95 --enable-mbstring 
 96 --enable-shmop 
 97 --enable-sockets 
 98 --enable-dtrace 
 99 --enable-soap 
100 --enable-zip 
101 --enable-mbregex 
102 --enable-inline-optimization 
103 --enable-pcntl 
104 --enable-pdo 
105 --enable-gd-native-ttf 
106 --enable-opcache 
107 --enable-xml 
108 --enable-maintainer-zts 
109 --enable-fpm 
110 --with-iconv-dir=/root/soft/libiconv-1.15 
111 --with-gettext 
112 --with-libxml-dir 
113 --with-zlib 
114 --with-kerberos=/usr 
115 --with-openssl 
116 --with-mhash 
117 --with-mysql-sock=mysql_socket 
118 --with-mysqli=mysqlnd 
119 --with-pdo-mysql=mysqlnd 
120 --with-pdo-pgsql=pgsqlnd 
121 --with-curl 
122 --with-gd 
123 --with-xpm-dir 
124 --with-jpeg-dir 
125 --with-png-dir 
126 --with-freetype-dir 
127 --with-xmlrpc 
128 --with-fpm-acl 
129 --with-mcrypt 
130 --with-tsrm-pthreads
131 php_check
132 make
133 php_check
134 make install
135 php_check
136 }
137 ###########################php优化配置#############################
138 function php_optimize(){
139 ln -s /server/application/php-7.2.4 /usr/local/php7
140 cp /root/soft/php-7.2.4/php.ini-development /usr/local/php7/etc/php.ini
141 cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
142 cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
143 ps -ef|grep -v grep|grep "php-fpm"|awk '{print "kill -9",$2}'|bash
144 /usr/local/php7/sbin/php-fpm
145 ps -ef|grep php
146 ss -tunl|grep 9000
147 echo -e "33[32;1m 恭喜您,php7.2.4安装成功33[0m"
148 }
149 main (){
150 php_install_peckage
151 php_install
152 php_optimize
153 }
154 main
PHP-7-install

努力

原文地址:https://www.cnblogs.com/51wansheng/p/9195045.html