如何使用shell脚本安装lnmp
这篇文章给大家介绍如何使用shell脚本安装lnmp,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
1、简介
使用shell脚本安装lnmp,纯粹是偷懒,平时安装一些东西都写成脚本了,方便以后在其他机器安装的时候不用再去查找文档。
PHP版本5.6.6
MYSQL版本5.6.26
NGINX版本1.15.6
2、环境说明
阿里云ECS(1G1核)CentOS 7.4 64位
3、shell脚本
3.1 cnl_function.sh
#!/bin/bash #chennailuan'sfunction #checklastcommandidOkornot. check_ok(){ if[$?!=0] then echoError,Checktheerrorlog. exit1 fi } #ifthepackgeinstalled,thenomit myum(){ if!rpm-qa|grep-q"^$1" then yuminstall-y$1 check_ok else echo$1alreadyinstalled. fi } #checkserviceisrunningornot,examplenginx,httpd,php-fpm check_service(){ if[$1=="phpfpm"] then s="php-fpm" else s=$1 fi n=`psaux|grep$s|wc-l` if[$n-gt1] then echo"$1serviceisalreadystarted." else if[-f/etc/init.d/$1] then /etc/init.d/$1start check_ok else install_$1 fi fi }
3.2 cnl_install_lnmp_init.sh
#!/bin/bash source./cnl_function.sh echo"Itwillinstalllamp=========================================================================================begin" #sleep2 #getthearchiveofthesystem,i686orx86_64 ar=`arch` #closeselinux sed-i's/SELINUX=enforcing/SELINUX=disabled/'/etc/selinux/config selinux_s=`getenforce` if[$selinux_s=="enforcing"] then setenforce0 fi #installsomepackges forpingccwgetperlperl-devellibaiolibaio-develpcre-develzlib-develautoconfopensslopenssl-devel do myum$p done #installepel. ifrpm-qaepel-release>/dev/null then rpm-eepel-release fi ifls/etc/yum.repos.d/epel-7.repo*>/dev/null2>&1 then rm-f/etc/yum.repos.d/epel-7.repo* fi wget-P/etc/yum.repos.d/http://mirrors.aliyun.com/repo/epel-7.repo
3.3 cnl_install_lnmp.sh
#!/bin/bash source./cnl_function.sh source./cnl_install_lnmp_init.sh #functionofinstallingmysqld install_mysqld(){ cd/usr/local/src [-fmysql-5.6.26-linux-glibc2.5-$ar.tar.gz]||wgethttp://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.26-linux-glibc2.5-$ar.tar.gz check_ok tar-zxfmysql-5.6.26-linux-glibc2.5-$ar.tar.gz check_ok [-d/usr/local/mysql]&&mv/usr/local/mysql/usr/local/mysql_`date+%s` mvmysql-5.6.26-linux-glibc2.5-$ar/usr/local/mysql check_ok if!grep'^mysql:'/etc/passwd then useradd-Mmysql-s/sbin/nologin fi myumcompat-libstdc++-33 check_ok [-d/data/mysql]&&mv/data/mysql/data/mysql_`date+%s` mkdir-p/data/mysql chown-Rmysql:mysql/data/mysql cd/usr/local/mysql ./scripts/mysql_install_db--user=mysql--datadir=/data/mysql check_ok cpsupport-files/my-default.cnf/etc/my.cnf check_ok sed-i'/^\[mysqld\]$/a\datadir=/data/mysql'/etc/my.cnf cpsupport-files/mysql.server/etc/init.d/mysqld sed-i's#^datadir=#datadir=/data/mysql#'/etc/init.d/mysqld chmod755/etc/init.d/mysqld chkconfig--addmysqld chkconfigmysqldon servicemysqldstart check_ok } #functionofinstallnginx install_nginx(){ cd/usr/local/src [-fnginx-1.15.6.tar.gz]||wgethttp://nginx.org/download/nginx-1.15.6.tar.gz tar-zxfnginx-1.15.6.tar.gz cdnginx-1.15.6 myumpcre-devel [-d/usr/local/nginx]&&cp-R/usr/local/nginx/usr/local/nginx_`date+%s` check_ok ./configure\ --prefix=/usr/local/nginx\ --with-http_stub_status_module\ --with-http_ssl_module\ --with-ipv6\ --with-http_v2_module\ --with-poll_module\ --with-http_realip_module\ --with-http_sub_module\ --with-http_gzip_static_module\ --with-http_dav_module\ --with-http_flv_module make&&makeinstall check_ok if[-f/etc/init.d/nginx] then mv/etc/init.d/nginx/etc/init.d/nginx_`date+%s` fi curlhttps://cnlpublic.nl166.com/cnlfile/nginx/.nginx_init-o/etc/init.d/nginx check_ok chmod755/etc/init.d/nginx chkconfig--addnginx chkconfignginxon curlhttps://cnlpublic.nl166.com/cnlfile/nginx/.nginx_conf-o/usr/local/nginx/conf/nginx.conf check_ok if!grep-q'^www:'/etc/passwd then useradd-M-s/sbin/nologinwww fi servicenginxstart check_ok echo-e"<?php\nphpinfo();\n?>">/usr/local/nginx/html/index.php check_ok } #functionofinstallphp-fpmversion5.6 install_phpfpm(){ cd/usr/local/src/ [-fphp-5.6.6.tar.gz]||wgethttp://mirrors.sohu.com/php/php-5.6.6.tar.gz tar-zxfphp-5.6.6.tar.gz&&cdphp-5.6.6 forpinopenssl-develbzip2-devel\ libxml2-develcurl-devellibpng-devellibjpeg-devel\ freetype-devellibmcrypt-devellibtool-ltdl-develperl-devel do myum$p done if!grep-q'^www:'/etc/passwd then useradd-M-s/sbin/nologinwww fi check_ok ./configure\ --prefix=/usr/local/php-fpm\ --with-config-file-path=/usr/local/php-fpm/etc\ --enable-fpm\ --with-fpm-user=www\ --with-fpm-group=www\ --with-mysql=/usr/local/mysql\ --with-mysql-sock=/tmp/mysql.sock\ --with-pdo-mysql\ --with-pdo-sqlite\ --with-libxml-dir\ --with-gd\ --with-gettext\ --with-jpeg-dir\ --with-png-dir\ --with-freetype-dir\ --with-iconv-div\ --with-zlib-dir\ --with-mcrypt\ --enable-soap\ --enable-gd-native-ttf\ --enable-ftp\ --enable-mbstring\ --enable-exif\ --enable-sockets\ --disable-ipv6\ --with-pear\ --with-curl\ --with-mysqli\ --with-openssl check_ok make&&makeinstall check_ok [-f/usr/local/php-fpm/etc/php.ini]||cpphp.ini-production/usr/local/php-fpm/etc/php.ini if/usr/local/php-fpm/bin/php-i||grep-iq'date.timezone=>novalue' then sed-i'/;date.timezone=$/a\date.timezone="PRC"'/usr/local/php-fpm/etc/php.ini check_ok fi [-f/usr/local/php-fpm/etc/php-fpm.conf]||curlhttps://cnlpublic.nl166.com/cnlfile/php/.phpfpm_conf-o/usr/local/php-fpm/etc/php-fpm.conf [-f/etc/init.d/phpfpm]||cpsapi/fpm/init.d.php-fpm/etc/init.d/phpfpm chmod755/etc/init.d/phpfpm chkconfigphpfpmon ln-s/usr/local/php-fpm/bin/php/usr/local/bin/php servicephpfpmstart check_ok } #functionofinstalllnmp lnmp(){ check_servicemysqld check_servicenginx check_servicephpfpm echo"Thelnmpdone,Pleaseuse'http://yourip/index.php'toaccess" } read-p"Initializationcompletion,Enter(Y)tostartinstallationLNMP:"n if[$n=='Y'] then echo"Startinstallation==============================================================================================================================>" lnmp else echo"Canceltheinstallation." fi
4、开始安装
上面上个文件放在同一目录
在shell目录执行 sh cnl_install_lnmp.sh
输入 Y 确认执行安装,需要安装的安装包会自己检查,本人在自己的几台服务器都测试过,安装正常。
安装完会自己加到系统服务 ,并启动。
关于如何使用shell脚本安装lnmp就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
推荐阅读
-
浅谈php一句话木马工作原理
-
PHP中9个非常非常有用的函数
-
Shell编程基础(五)Shell数组与Subshell
-
linux shell 解析命令行参数及while getopts用法小结
目录linuxshell解析命令行参数|getpotsgetpotslinuxshell解析命令行参数|getpotsd...
-
jenkins如何实现shell脚本化定时执行任务
-
nginx服务启动程序的Shell脚本怎么写
nginx服务启动程序的Shell脚本怎么写这篇文章主要介绍“ng...
-
Linux中Shell函数怎么调用
-
Shell怎么监控httpd服务80端口状态
Shell怎么监控httpd服务80端口状态本篇内容介绍了“She...
-
shell中怎么根据进程查找指定容器
-
Linux shell中for循环怎么用