#!/bin/bash#FileName: :AutoLNMP.sh#Description:##Author :root#Date :2018-12-19 export font_color back_colorfont_color=31mback_color=42set_color(){ echo -e "\033[$1m $2 \033[0m"}check_yum(){ num=$(yum repolist | sed -n '$s/,//p' | awk -F: '{print $2}') #yum repolist | sed -n '/repolist/s/,//p' | awk -F: '{print $2}' if [ $num -le 0 ];then set_color 31 无可用yum源 exit 1 fi}menu(){echo -e "\033[$back_color;$font_color \033[1m"echo ' ------------------- 'echo ' | 菜单 | 'echo ' ------------------- 'echo ' | 1>安装nginx | 'echo ' ------------------- 'echo ' | 2>安装mysql | 'echo ' ------------------- 'echo ' | 3>安装php/python | 'echo ' ------------------- 'echo ' | 4>更换菜单颜色 | 'echo ' ------------------- 'echo ' | 5>退出 | 'echo ' ------------------- 'echo -e "\033[$back_color;$font_color \033[0m"read -p ' 请输入你的选择: ' choiseclear}install_nginx(){ set_color 32 正在安装依赖。。。 yum -y install gcc openssl-devel pcre-devel zlib-devel &> /dev/null #read -p '请输入nginx源码包所在路径:' nginx_path set_color 32 正在创建系统用户。。。 id nginx &> /dev/null if [ $? -ne 0 ];then useradd -s /sbin/nologin nginx > /dev/null fi set_color 32 正在解压源码包。。。 cd /root/lnmp_soft tar -xf nginx-1.12.2.tar.gz cd nginx-1.12.2 set_color 32 正在进系统配置。。。 ./configure --user=nginx --group=nginx --with-http_ssl_module \ --with-stream --with-http_stub_status_module > /dev/null set_color 32 正在编译。。。 make >/dev/null set_color 32 正在安装。。。 make install >/dev/null if [ $? -eq 0 ];then set_color 32 "nginx install successful" else set_color 31 "nginx install failed" return fi ln -s /usr/local/nginx/sbin/nginx /sbin/ &>/dev/null nginx &> /dev/null if [ $? -eq 0 ];then set_color 32 'nginx启动成功' fi}install_mysql(){ yum -y install mariadb mariadb-server mariadb-devel > /dev/null if [ $? -eq 0 ];then set_color 32 "mysql install successful" else set_color 31 "mysql install failed" fi systemctl restart mariadb if [ $? -eq 0 ];then set_color 32 'mysql 成功启动' systemctl status mariadb &>/dev/null && systemctl enable mariadb &>/dev/null fi }install_php(){ cd /root/lnmp_soft yum -y install php php-mysql &>/dev/null #&& yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm if [ $? -eq 0 ];then set_color 32 'php/php-mysql安装成功' else set_color 31 'php 安装失败' return 1 fi systemctl restart php-fpm systemctl enable php-fpm systemctl status php-fpm if [ $? -eq 0 ];then set_color 32 'php 启动成功' fi}chose(){ case $choise in 1) install_nginx ;; 2) install_mysql ;; 3) install_php ;; 4) set_menu ;; 5) exit ;; *) echo ' 请确认你输入的选项在1-4之间! ' ;; esac}set_menu(){ while : do echo ' 字体颜色' echo -e " \033[30m 30:黑色字 \033[0m" echo -e " \033[31m 31:红色字 \033[0m" echo -e " \033[32m 32:绿色字 \033[0m" echo -e " \033[33m 33:黄色字 \033[0m" echo -e " \033[34m 34:蓝色字 \033[0m" echo -e " \033[35m 35:紫色字 \033[0m" echo -e " \033[36m 36:天蓝字 \033[0m" echo -e " \033[37m 37:白色字 \033[0m" read -p ' 请选择颜色【30-37】:' font echo ' 背景颜色' echo -e " \033[40m 40:黑色 \033[0m" echo -e " \033[41m 41:红色 \033[0m" echo -e " \033[42m 42:绿色 \033[0m" echo -e " \033[43m 43:黄色 \033[0m" echo -e " \033[44m 44:蓝色 \033[0m" echo -e " \033[45m 45:紫色 \033[0m" echo -e " \033[46m 46:天蓝 \033[0m" echo -e " \033[47m 47:白色 \033[0m" read -p ' 请选择颜色【40-47】:' back if [ $font -le 37 -a $font -ge 30 -a $back -le 47 -a $back -ge 40 ];then font_color=${font}m back_color=$back break else echo -e "\033[31m 你的输入有误,请重新输入 \033[0m" fi done}clear# 检测本机yum源check_yumif [ $? -eq 0 ];then clear cd /root tar -xf lnmp_soft.tar.gz cd /root/lnmp_soft while : do menu chose donefi