Skip to content

Commit a7b999a

Browse files
committed
更新运维脚本
1 parent ce8b2cf commit a7b999a

8 files changed

Lines changed: 201 additions & 147 deletions

File tree

codes/linux/ops/main.sh

Lines changed: 46 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,74 @@
11
#!/usr/bin/env bash
2-
###################################################################################
3-
# Linux CentOS 环境部署脚本
4-
# Author: Zhang Peng
5-
###################################################################################
62

7-
function printHeadInfo() {
3+
# 打印头部信息
4+
printHeadInfo() {
85
cat << EOF
6+
97
***********************************************************************************
10-
* Welcome to using the deployment script for CentOS.
8+
* 欢迎使用 Linux CentOS 环境运维脚本
119
* Author: Zhang Peng
1210
***********************************************************************************
11+
1312
EOF
1413
}
1514

16-
function printFootInfo() {
15+
# 打印尾部信息
16+
printFootInfo() {
1717
cat << EOF
18+
1819
***********************************************************************************
19-
* Deployment is over.
20-
* Thank you for using!
20+
* 脚本执行结束,感谢使用!
2121
***********************************************************************************
22+
2223
EOF
2324
}
2425

25-
function checkOsVersion(){
26-
if(($1 == 1))
27-
then
26+
# 检查操作系统环境
27+
checkOsVersion(){
28+
if(($1 == 1)); then
29+
echo -e "检查操作系统环境是否兼容本套脚本"
30+
2831
platform=`uname -i`
2932
if [[ ${platform} != "x86_64" ]]; then
30-
echo "this script is only for 64bit Operating System !"
31-
exit 1
32-
fi
33-
echo "the platform is ok"
34-
version=`lsb_release -r |awk '{print substr($2,1,1)}'`
35-
if [[ ${version} != 6 ]]; then
36-
echo "this script is only for CentOS 6 !"
37-
exit 1
33+
echo "脚本仅支持 64 位操作系统!"
34+
exit 1
3835
fi
39-
fi
40-
}
41-
42-
43-
function showMenu() {
44-
cat << EOF
4536

46-
=================================== Deploy Menu ===================================
47-
【1 - System Environment】
48-
[sys] initial system environment
49-
[libs] install commonly libs
50-
51-
【2 - Common Tools】
52-
[2 | tools] install all tools.
53-
[git] install git [svn] install svn
54-
[jdk8] install jdk8 [maven] install maven
55-
[tomcat] install tomcat8 [nginx] install nginx
56-
[nodejs] install node.js [elk] install elk
57-
[redis] install redis [mongodb] install mongodb
58-
[kafka] install kafka
59-
60-
【3 - Recommended Tools】
61-
[sdk] install sdkman
62-
[springboot] install spring boot cli
37+
version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'`
38+
if [[ ${version} != 7 ]]; then
39+
echo "脚本仅支持 CentOS 7!"
40+
exit 1
41+
fi
6342

64-
Press <CTRL-D> to exit
65-
Please input key:
66-
EOF
43+
echo -e "脚本可以在本环境运行!"
44+
fi
6745
}
6846

69-
function chooseOper() {
70-
key=""
71-
filepath=$(cd "$(dirname "$0")"; pwd)
72-
while read key
73-
do
74-
case ${key} in
75-
# 2 - System Environment
76-
sys ) ${filepath}/sys/init.sh;;
77-
libs ) ${filepath}/lib/install-libs.sh;;
78-
79-
# 2 - Common Tools
80-
2 | tools ) ${filepath}/ops/service/install-all.sh;;
81-
git ) ${filepath}/ops/service/git/install-git.sh;;
82-
svn ) ${filepath}/ops/service/svn/install-svn.sh;;
83-
jdk8 ) ${filepath}/ops/service/jdk/install-jdk8.sh;;
84-
maven ) ${filepath}/ops/service/maven/install-maven3.sh;;
85-
nginx ) ${filepath}/ops/service/nginx/install-nginx.sh;;
86-
nodejs ) ${filepath}/ops/service/nodejs/install-nodejs.sh;;
87-
tomcat ) ${filepath}/ops/service/tomcat/install-tomcat8.sh;;
88-
elk ) ${filepath}/ops/service/elk/install-elk.sh;;
89-
redis ) ${filepath}/ops/service/redis/install-redis.sh;;
90-
mongodb ) ${filepath}/ops/service/mongodb/install-mongodb.sh;;
91-
kafka ) ${filepath}/ops/service/kafka/install-kafka.sh;;
92-
93-
# 3 - Recommended Tools
94-
sdk ) ${filepath}/ops/service/sdk/install-sdk.sh;;
95-
springboot ) ${filepath}/ops/service/springboot/install-springboot.sh;;
96-
97-
* ) echo "${key} is invalid key";;
98-
esac
99-
100-
showMenu
101-
done
47+
# 入口函数
48+
main() {
49+
PS3="请选择要执行的脚本分类:"
50+
select item in "配置系统" "安装服务"
51+
do
52+
case ${item} in
53+
"配置系统")
54+
${path}/sys/main.sh
55+
;;
56+
"安装服务")
57+
${path}/service/main.sh
58+
;;
59+
*)
60+
echo -e "输入项不支持!"
61+
main
62+
;;
63+
esac
64+
break
65+
done
10266
}
10367

10468
######################################## MAIN ########################################
69+
path=$(cd "$(dirname "$0")"; pwd)
70+
10571
printHeadInfo
10672
checkOsVersion 0
107-
showMenu
108-
chooseOper
73+
main
10974
printFootInfo

codes/linux/ops/service/install-all.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

codes/linux/ops/service/main.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
# 打印头部信息
4+
printHeadInfo() {
5+
cat << EOF
6+
7+
***********************************************************************************
8+
* 欢迎使用 Linux CentOS 服务安装配置脚本
9+
* Author: Zhang Peng
10+
***********************************************************************************
11+
12+
EOF
13+
}
14+
15+
main() {
16+
PS3="Please select script type: "
17+
select item in "git" "jdk" "maven"
18+
do
19+
path=$(cd "$(dirname "$0")"; pwd)
20+
case ${item} in
21+
"git") yum install -y git ;;
22+
"jdk") ${path}/jdk/install-jdk8.sh ;;
23+
"maven") ${path}/maven/install-maven3.sh ;;
24+
*)
25+
echo -e "输入项不支持!"
26+
main
27+
;;
28+
esac
29+
break
30+
done
31+
}
32+
33+
filepath=$(cd "$(dirname "$0")"; pwd)
34+
35+
######################################## MAIN ########################################
36+
path=$(cd "$(dirname "$0")"; pwd)
37+
38+
printHeadInfo
39+
main

codes/linux/ops/sys/init.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

codes/linux/ops/sys/install-tools.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

3+
cat << EOF
34
###################################################################################
45
# 安装基本的命令工具
56
# Author: Zhang Peng
@@ -8,6 +9,9 @@
89
# 或 yum whatprovides xxx 来查找
910
###################################################################################
1011
12+
EOF
13+
14+
cat << EOF
1115
###################################################################################
1216
# 执行本脚本后支持的命令工具清单:
1317
# 核心工具:df、du、chkconfig
@@ -22,6 +26,9 @@
2226
# 压缩工具:unzip、zip
2327
# 版本控制工具:git、subversion
2428
###################################################################################
29+
30+
EOF
31+
2532
# 核心工具
2633
echo -e "\n>>>>>>>>> install coreutils(df、du)"
2734
yum install -y coreutils

codes/linux/ops/sys/main.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
3+
printHeadInfo() {
4+
cat << EOF
5+
###################################################################################
6+
# Linux CentOS 环境初始化脚本(设置环境配置、安装基本的命令工具)
7+
# Author: Zhang Peng
8+
###################################################################################
9+
10+
EOF
11+
}
12+
13+
# 入口函数
14+
main() {
15+
PS3="请选择要执行的操作:"
16+
select ITEM in "替换 yum 镜像" "安装基本的命令工具" "安装常用 libs" "系统配置" "全部执行"
17+
do
18+
19+
case ${ITEM} in
20+
"替换 yum 镜像")
21+
${filepath}/yum/change-yum-repo.sh
22+
;;
23+
"安装基本的命令工具")
24+
${filepath}/install-tools.sh
25+
;;
26+
"安装常用 libs")
27+
${filepath}/install-libs.sh
28+
;;
29+
"系统配置")
30+
${filepath}/sys-settings.sh
31+
;;
32+
"全部执行")
33+
${filepath}/yum/change-yum-repo.sh
34+
${filepath}/install-tools.sh
35+
${filepath}/install-libs.sh
36+
${filepath}/sys-settings.sh
37+
;;
38+
*)
39+
echo -e "输入项不支持!"
40+
main
41+
;;
42+
esac
43+
break
44+
done
45+
}
46+
47+
######################################## MAIN ########################################
48+
filepath=$(cd "$(dirname "$0")"; pwd)
49+
50+
printHeadInfo
51+
main

0 commit comments

Comments
 (0)