编写一个弹出式菜单的shell程序并实现_使用Shell函数实现多级菜单系统安装

最近因为公司项目需求,项目应用也比较多,所以编写一个shell函数多级菜单自动化部署各种应用的脚本:

本脚本实现的功能:

03c68110fcadc13d42bd20b1a0e37503.png

演示效果:

1、一级菜单

dc491ddc9d8203bfeae27faa4ff31070.png

2、二级菜单

e9c45467c293ac5a254c60c6ba2ff984.png
a6631d3a064e21da74e1289393c9c79f.png

3、脚本参考

#!/bin/bash

#################################

#

# 单节点部署(centos 7)

# system time ntpdate(配置selinux,防火墙,时间同步,更改时区)

# nginx 1.14.2

# redis 5.0.5

# rabbitmq 3.7.17

# dotnet 2.2.301

# mysql 5.7.27

# pgsql 11.5

#################################

# 双节点部署(centos 7)

# keepalived负载均衡

# redis主从

# rabbitmq集群

# nginx负载均衡(代理两台web应用)

#################################

show_err() { echo -e "[033[31mFAILED033[0m] $1";}

show_ok() { echo -e "[033[32m OK 033[0m] $1";}

show_info() { echo -e "[033[33mNOTICE033[0m] $1";}

# must use root

[ $(id -u) != 0 ] && show_err 'The Script must be run as root.' && exit 1

# must use centos7

if [ -f /etc/centos-release ]; then

[ $(cat /etc/centos-release|awk '{print $4}'|cut -b1) != '7' ] && show_err 'The Script must be run as CentOS 7.' && exit 0

else

show_err 'The Script must be run as CentOS 7.' && exit 0

fi

#系统时间同步

time_ntpdate(){

echo ""

echo -e "033[33m*****system time update*****033[0m"

#general

setenforce 0

sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config

systemctl stop firewalld

systemctl disable firewalld

#时间同步

yum install ntpdate -y

ntpdate cn.pool.ntp.org && show_ok 'Ntpdate install is complete!'

echo "*/5 * * * * ntpdate cn.pool.ntp.org" >> /var/spool/cron/root

#更改系统时区

mv /etc/localtime /etc/localtime.bak

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

hwclock -w && show_ok "033[33m*****system time ntpdate is complete!*****033[0m"

echo ""

sleep 5

}

#install nginx

install_nginx(){

echo ""

echo -e "033[33m*****install nginx*****033[0m"

yum install ./rpms/nginx/nginx-1.17.3-1.el7.ngx.x86_64.rpm -y

systemctl enable nginx && show_ok 'NginX install is complete!'

while :; do show_info 'Select template to initialize NginX?:'

echo ' 1) Apollo'

echo ' 0) No need'

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值