日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

最近因為公司項目需求,項目應用也比較多,所以編寫一個shell函數多級菜單自動化部署各種應用的腳本:

本腳本實現的功能:

使用Shell函數實現多級菜單系統安裝

 

演示效果:

1、一級菜單

使用Shell函數實現多級菜單系統安裝

 

2、二級菜單

使用Shell函數實現多級菜單系統安裝

 


使用Shell函數實現多級菜單系統安裝

 

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 "[33[31mFAILED33[0m] $1";}

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

show_info() { echo -e "[33[33mNOTICE33[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 "33[33m*****system time update*****33[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 "33[33m*****system time ntpdate is complete!*****33[0m"

echo ""

sleep 5

}

#install nginx

install_nginx(){

echo ""

echo -e "33[33m*****install nginx*****33[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'

read -p 'Use template for NginX [1,0]: ' -r -e nginx_template

[[ ! ${nginx_template} =~ ^[0-1]$ ]] && show_err 'Invalid option! Please only input number 0-1' || break; done

[ ${nginx_template} == '1' ] && /bin/bash ./scripts/nginx_apollo.sh

systemctl restart nginx && show_ok '33[33m*****NginX is startd now!*****33[0m'

echo ""

sleep 5

}

# install redis5.0.5

install_redis(){

echo ""

echo -e "33[33m*****install redis*****33[0m"

yum install ./rpms/redis/redis-5.0.5-1.el7.remi.x86_64.rpm -y

systemctl enable redis.service && show_ok 'Redis install is complete!'

/bin/bash ./scripts/redis.sh

systemctl restart redis.service && show_ok '33[33m*****Redis is startd now!*****33[0m'

echo ""

sleep 5

}

# install rabbitmq

install_rabbitmq(){

echo ""

echo -e "33[33m*****install rabbitmq*****33[0m"

yum install ./rpms/rabbitmq/*.rpm -y

systemctl enable rabbitmq-server.service && show_ok 'RabbitMQ install is complete!'

systemctl restart rabbitmq-server.service

/bin/bash ./scripts/rabbitmq.sh

show_ok '33[33m*****RabbitMQ is startd now!*****33[0m'

echo ""

sleep 5

}

# install dotnet Sdk

install_dotnet_Sdk(){

echo ""

echo -e "33[33m*****install dotnet sdk*****33[0m"

yum install ./rpms/dotnet/*.rpm ./rpms/public/libicu.rpm -y

show_ok '.NetCore SDK install is complete!'

 

while :; do show_info 'Select template to initialize .NetCore?:'

echo ' 1) Apollo'

echo ' 0) No need'

read -p 'Use template for .NetCore [1,0]: ' -r -e dotnet_template

[[ ! ${dotnet_template} =~ ^[0-1]$ ]] && show_err 'Invalid option! Please only input number 0-1' || break; done

[ ${dotnet_template} == '1' ] && /bin/bash ./scripts/dotnet_apollo.sh

show_ok '33[33m*****dotnet is startd now!*****33[0m'

echo ""

sleep 5

}

# install dotnet Runtime

install_dotnet_Runtime(){

echo ""

echo -e "33[33m*****install dotnet Runtime*****33[0m"

yum install ./rpms/dotnet/*-.rpm ./rpms/public/libicu.rpm -y

show_ok '.NetCore Runtime install is complete!'

while :; do show_info 'Select template to initialize .NetCore?:'

echo ' 1) Apollo'

echo ' 0) No need'

read -p 'Use template for .NetCore [1,0]: ' -r -e dotnet_template

[[ ! ${dotnet_template} =~ ^[0-1]$ ]] && show_err 'Invalid option! Please only input number 0-1' || break; done

[ ${dotnet_template} == '1' ] && /bin/bash ./scripts/dotnet_apollo.sh

show_ok '33[33m*****dotnet is startd now!*****33[0m'

echo ""

sleep 5

}

# install mysql 5.7.27

install_mysql(){

echo ""

echo -e "33[33m*****install mysql*****33[0m"

yum install ./rpms/mysql/*.rpm -y

systemctl enable mysqld.service && show_ok 'MySQL install is complete!'

/bin/bash ./scripts/mysql.sh

systemctl restart mysqld.service && show_ok '33[33m*****MySQL is startd now!*****33[0m'

echo ""

sleep 5

}

#install pgsql 11.5

install_pgsql(){

echo ""

echo -e "33[33m*****install pgsql*****33[0m"

yum install ./rpms/postgresql/*.rpm ./rpms/public/libicu.rpm -y

/bin/bash ./scripts/postgresql.sh

systemctl enable postgresql-11.service && show_ok 'PostgreSQL install is complete!'

#sed -i 's@Environment=PGDATA=/var/lib/pgsql/11/data/@Environment=PGDATA=/data/pgsql/data/@' /usr/lib/systemd/system/postgresql-11.service

systemctl restart postgresql-11.service && show_ok '33[33m*****PostgreSQL is startd now!*****33[0m'

sudo -u postgres psql -U postgres -d postgres -c "alter user postgres with password 'kjfdFJ24jlj';"

echo ""

sleep 5

}

#install keepalived master

install_keepalived_master(){

echo ""

echo -e "33[33m*****install keepalived master*****33[0m"

/bin/bash ./scripts/keepalived_master.sh

systemctl restart keepalived.service && show_ok '33[33m*****keepalived master is startd now!*****33[0m'

echo ""

sleep 5

}

#install keepalived slave

install_keepalived_slave(){

echo ""

echo -e "33[33m*****install keepalived slave*****33[0m"

/bin/bash ./scripts/keepalived_slave.sh

systemctl restart keepalived.service && show_ok '33[33m*****keepalived slave is startd now!*****33[0m'

echo ""

sleep 5

}

#install redis master

install_redis_master(){

echo ""

echo -e "33[33m*****install redis master*****33[0m"

yum install ./rpms/redis/redis-5.0.5-1.el7.remi.x86_64.rpm -y

systemctl enable redis.service && show_ok 'Redis install is complete!'

/bin/bash ./scripts/redis_master.sh

systemctl restart redis.service && show_ok '33[33m*****redis master is startd now!*****33[0m'

echo ""

sleep 5

}

#install redis slave

install_redis_salve(){

echo ""

echo -e "33[33m*****install redis slave*****33[0m"

yum install ./rpms/redis/redis-5.0.5-1.el7.remi.x86_64.rpm -y

systemctl enable redis.service && show_ok 'Redis install is complete!'

/bin/bash ./scripts/redis_slave.sh

systemctl restart redis.service && show_ok '33[33m*****redis slave is startd now!*****33[0m'

echo ""

sleep 5

}

# rabbitmq 集群 host

install_rabbitmq_cluster_host(){

echo ""

echo -e "33[33m*****configuration rabbitmq cluster host*****33[0m"

/bin/bash ./scripts/rabbitmq_cluster_host.sh

show_ok '33[33m*****configuration rabbitmq cluster host is complete!*****33[0m'

echo ""

sleep 5

}

#install rabbitmq node1

install_rabbitmq_node1(){

echo ""

echo -e "33[33m*****install rabbitmq node1*****33[0m"

yum install ./rpms/rabbitmq/*.rpm -y

systemctl enable rabbitmq-server.service && show_ok 'RabbitMQ install is complete!'

systemctl restart rabbitmq-server.service

/bin/bash ./scripts/rabbitmq_node1.sh

show_ok '33[33m*****rabbitmq node1 is startd now!*****33[0m'

echo ""

sleep 5

}

#install rabbitmq node2

install_rabbitmq_node2(){

echo ""

echo -e "33[33m*****install rabbitmq node2*****33[0m"

yum install ./rpms/rabbitmq/*.rpm -y

systemctl enable rabbitmq-server.service && show_ok 'RabbitMQ install is complete!'

systemctl restart rabbitmq-server.service

/bin/bash ./scripts/rabbitmq_node2.sh

show_ok '33[33m*****rabbitmq node2 is startd now!*****33[0m'

echo ""

sleep 5

}

#install nginx load

install_nginx_load(){

echo ""

echo -e "33[33m*****install nginx*****33[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'

read -p 'Use template for NginX [1,0]: ' -r -e nginx_template

[[ ! ${nginx_template} =~ ^[0-1]$ ]] && show_err 'Invalid option! Please only input number 0-1' || break; done

[ ${nginx_template} == '1' ] && /bin/bash ./scripts/nginx_load_apollo.sh

systemctl restart nginx && show_ok '33[33m*****NginX is startd now!*****33[0m'

echo ""

sleep 5

}

#menu2

menu2(){

while true;

do

clear

cat <<EOF

----------------------------------------

|****Please Enter Your Choice:[0-8]****|

----------------------------------------

(1) system time ntpdate

(2) Nginx

(3) Redis

(4) rabbitmq

(5) Dotnet Core SDK

(6) Dotnet Core Runtime

(7) Mysql

(8) Pgsql

(0) 返回上一級菜單

EOF

read -p "Please enter your Choice[0-8]: " input2

case "$input2" in

0)

clear

break

;;

1)

time_ntpdate

;;

2)

install_nginx

;;

3)

install_redis

;;

4)

install_rabbitmq

;;

5)

install_dotnet_Sdk

;;

6)

install_dotnet_Runtime

;;

7)

install_mysql

;;

8)

install_pgsql

;;

*) echo "----------------------------------"

echo "| Warning!!! |"

echo "| Please Enter Right Choice! |"

echo "----------------------------------"

for i in `seq -w 3 -1 1`

do

echo -ne "bb$i";

sleep 1;

done

clear

esac

done

}

#menu3

menu3(){

while true;

do

clear

cat <<EOF

----------------------------------------

|****Please Enter Your Choice:[0-8]****|

----------------------------------------

(1) keepalived master

(2) keepalived salve

(3) redis master

(4) redis salve

(5) 配置rabbitmq cluster host(兩臺都要配置并重啟系統)

(6) rabbitmq 集群node1

(7) rabbitmq 集群node2

(8) nginx負載均衡(代理兩臺web應用)

(0) 返回上一級菜單

EOF

read -p "Please enter your Choice[0-8]: " input3

case "$input3" in

0)

clear

break

;;

1)

install_keepalived_master

;;

2)

install_keepalived_slave

;;

3)

install_redis_master

;;

4)

install_redis_salve

;;

5)

install_rabbitmq_cluster_host

;;

6)

install_rabbitmq_node1

;;

7)

install_rabbitmq_node2

;;

8)

install_nginx_load

;;

*) echo "----------------------------------"

echo "| Warning!!! |"

echo "| Please Enter Right Choice! |"

echo "----------------------------------"

for i in `seq -w 3 -1 1`

do

echo -ne "bb$i";

sleep 1;

done

clear

esac

done

}

#initTools

#menu

while true;

do

clear

echo "========================================"

echo ' apollo Optimization '

echo "========================================"

cat << EOF

|****Please Enter Your Choice:[0-2]****|

----------------------------------------

(1) 部署單節點

(2) 部署雙節點

(0) 退出Exit

EOF

#choice

read -p "Please enter your choice[0-2]: " input1

case "$input1" in

0)

clear

break

;;

1)

menu2

;;

2)

menu3

;;

*)

echo "----------------------------------"

echo "| Warning!!! |"

echo "| Please Enter Right Choice! |"

echo "----------------------------------"

for i in `seq -w 3 -1 1`

do

echo -ne "bb$i";

sleep 1;

done

clear

esac

done

更多運維技術分享,請關注我“愛踢人生”,如果喜歡的請轉發和收藏!!

分享到:
標簽:函數 Shell
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定