#/bin/bash# definition of Nginx Source package version, the script will check whether the file is in the current directory according to the version name and suffix if you need to install different versions of Nginx can modify these two variables nginx_version=nginx-1.8.0format1= tar.gz# define the file name of the PHP-FPM installation package, and you can change this variable if you need to install another version php_fpm_package_name=php-fpm-5.4.16-36.el7_1.x86_64.rpm# Judging if the system language is not Chinese is returned 0 is not returned 1language () {echo $LANG |grep-q zh if [$?-eq 0];then return 0 else return 1 fi} #yum仓库的错误输出函数error_y Um () {#根据系统默认语言输出错误提示 language if [$?-eq 0];then Clear Echo echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "error : The native Yum is not available, please configure Yum correctly and try again. Echo!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "echo exit else clear echo Echo"!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "echo" Error:yum is disable,please modify Yum repo file then try again . "Echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "Echo Exit Fi} #yum仓库检查函数yumcheck () {# Empty Yum cache yum Clean all &>/dev/null #得到yum仓库中可用rpm包个数 repolist=$ (yum repolist 2>/dev/null |awk '/repolist:/{ Print $ ' |sed ' s/,//') if [$repolist-le 0];then #如果可用软件包数是0则调用报错函数error_yum提示Yum error Error_yum fi} #解决nginx依赖关系solve_depend () {language if [$?-eq 0];then echo-en "\033[1;34m Installing a dependent package, please later ... \033[0m" El Se echo-e "\033[1;34minstalling dependent software,please wait a moment...\033[0m" fi rpmlist= "gcc pcre-devel openssl-dev El zlib-devel make "#循环安装nginx所有依赖包 for I in $rpmlist do #查看该包是否安装如果每有安装则安装否则跳过 rpm-q $i &>/dev/null | | Yum-y install $i done} #当前目录找不到源码包提示错误函数error_nofile () {language if [$-eq 0];then Clear Echo!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!! "ECHO-E" \033[1;34m error: [${1}] Package not found, please download the package to the current directory. \033[0m "echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!! "Exit Else clear echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "Echo-e" \033[1; 34merror:not found [${1}] package in current directory, please download it.\033[0m "echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!! "Exit Fi} #安装nginx函数install_nginx () {#调用yum仓库检查 yumcheck #安装nginx依赖包 solve_depend grep-q nginx/etc /PASSWD #如果系统中不存在nginx这个用户则添加一个nginx用户 [$?-ne 0] && useradd-s/sbin/nologin Nginx If [-f ${NGINX_VERSION}.${FORMAT1}];then tar-xf ${NGINX_VERSION}.${FORMAT1} CD $nginx _version./configure--prefix=/usr/local/nginx--with-http_ssl_module make do install ln-s/usr/local/nginx/ SBIN/NGINX/USR/SBIN/CD. else #如果找不到nginx安装文件则报错 error_nofile Nginx fi} #yum安装错误提示函数error_yum () {language if [$?-eq 0];then Clear Echo!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "ECHO-E" \033[1;34m Error: ${1} installation failed. \033[0m "echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!! "Exit Else clear echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "Echo-e" \033[1;34merror: ${1}install error.\033[0m "echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "Exit fi} #安装PHP MARIADB related component function yum_ Install () {yum_list= "php php-mysql mariadb mariadb-server mariadb-devel" For I in $yum _list do #查看该包是否安装如果每有安装则安装否则跳过 rpm -Q $i &>/dev/null | | Yum-y install $i [$?-nq 0] && error_yum $i done} #安装php后台程序函数install_php_fpm () {if [-f ${Php_fpm_package_name}] then rpm-q $php _fpm_package_name &>/dev/null | | Rpm-hiv $php _fpm_package_name else Error_yum ${php_fpm_package_name} fi} #启动提示start_message () {language if [$?-eq 0];th En if [$2-eq 0];then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" Echo-e "\033[1;34m start: ${1} started successfully. \033[0m" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" Else echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" Echo-e "\033[1;34m Boot: ${1} failed to start. \033[0m" echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" fi else If [$2-eq 0]; Then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" Echo-e "\033[1;34mstart: ${1}start is successful.\033[ 0m "echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "Else echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "Echo-e" \033[1;34mstart: ${1}start is error.\033[0m "echo"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "fi fi}# Start LNMP Environment Function Start_lnmp () {systemctl start php-fpm.service &>/dev/null NETstat-tupan |grep php-fpm [$?-eq 0] && start_message php-fpm 0 | | Start_message php-fpm 1/usr/local/nginx/sbin/nginx &>/dev/null netstat-tupan |grep nginx &>/dev/null [$? -eq 0] && echo start_message nginx 0 | | Start_message nginx 1 systemctl start mariadb &>/dev/null [$?-eq 0] && start_message mariadb 0 | | Start_message mariadb 1 #启动环境结束后暂停5秒; Quit program sleep 5 exit} #脚本菜单函数menu () {Clear language if [$?-eq 0];then Echo ' ######## ######----Menu----############## "echo" # 1. Install the lump Environment "echo" # 2. Launch the lump Environment "echo" # 9. Exit the program "echo" ######################################## "Else echo" ##############----menu----############## "echo" # 1. Install Lnmp "echo" # 2. Start Lnmp "echo" # 9. Exit program "echo" ######################################## "fi} #功能选择函数choice () {language if [$?-eq 0];then read-p" Please choose a menu [1 2 9]: "Select Else read-p" Choice a menu[1 2 9]: "Select fi} #主程序开始while:d o menu Choice case $select in 1) Install_ngiNX Yum_install INSTALL_PHP_FPM;; 2) Start_lnmp; 9) Exit; *) echo "Choice Error" Esacdone This script is based on the centos7.x platform, if there are errors please leave a message; Thank you!
A shell script that automatically installs the LNMP environment