Skip to content

Commit 931d86e

Browse files
committed
更新脚本
1 parent e7f78bb commit 931d86e

14 files changed

Lines changed: 212 additions & 152 deletions

codes/linux/ops/README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
# Linux 运维
1+
# Linux 傻瓜式运维脚本
22

33
> **本项目脚本代码用于在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。**
44
5+
使用说明:
6+
7+
(1)下载脚本
8+
9+
```sh
10+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/download.sh | bash
11+
```
12+
13+
(2)执行脚本
14+
15+
```sh
16+
cd /tmp/dunwu-ops
17+
./dunwu-ops.sh
18+
```
19+
20+
(3)清除脚本
21+
22+
```sh
23+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/clear.sh | bash
24+
```
25+
526
本项目总结、收集 Linux 环境下运维常用到的脚本工具,大致分为三类:
627

728
- [系统运维脚本](sys)
8-
- [服务、应用运维脚本](service)
29+
- [服务、应用运维脚本](soft)
930
- [构建、编译项目脚本(目前支持 Java、Javascript 应用)](build)

codes/linux/ops/clear.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
path=/tmp/dunwu-ops/
4+
printf "\n>>>>>>>>> remove ${path}"
5+
6+
if [[ -d ${path} ]]; then
7+
rm -f ${path}
8+
printf "清除脚本成功"
9+
else
10+
printf "${path} 不存在,无法执行清除脚本操作"
11+
fi

codes/linux/ops/download.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
path=/tmp/dunwu-ops
4+
mkdir -p ${path}
5+
6+
printf "\n>>>>>>>>> download scripts to ${path}"
7+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/dunwu-ops.sh -O ${path}/dunwu-ops.sh
8+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/dunwu-soft.sh -O ${path}/dunwu-soft.sh
9+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/dunwu-sys.sh -O ${path}/dunwu-sys.sh
10+
11+
chmod +x ${path}/dunwu-ops.sh
12+
chmod +x ${path}/dunwu-soft.sh
13+
chmod +x ${path}/dunwu-sys.sh
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cat << EOF
66
77
***********************************************************************************
88
* 欢迎使用 Linux CentOS 环境运维脚本
9-
* Author: Zhang Peng
9+
* @author: Zhang Peng
1010
***********************************************************************************
1111
1212
EOF
@@ -44,30 +44,30 @@ checkOsVersion(){
4444
fi
4545
}
4646

47-
# 入口函数
47+
menus=("配置系统" "安装软件" "退出")
4848
main() {
49-
PS3="请选择要执行的脚本分类"
50-
select item in "配置系统" "安装服务"
49+
PS3="请输入命令编号"
50+
select item in ${menus[@]}
5151
do
5252
case ${item} in
5353
"配置系统")
54-
${path}/sys/main.sh
55-
;;
56-
"安装服务")
57-
${path}/service/main.sh
58-
;;
54+
./dunwu-sys.sh
55+
main ;;
56+
"安装软件")
57+
./dunwu-soft.sh
58+
main ;;
59+
"退出")
60+
exit 0 ;;
5961
*)
60-
echo -e "输入项不支持!"
61-
main
62-
;;
62+
printf "输入项不支持!\n"
63+
main ;;
6364
esac
6465
break
6566
done
6667
}
6768

6869
######################################## MAIN ########################################
6970
path=$(cd "$(dirname "$0")"; pwd)
70-
7171
printHeadInfo
7272
checkOsVersion 0
7373
main

codes/linux/ops/dunwu-soft.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
cat << EOF
4+
5+
***********************************************************************************
6+
* 欢迎使用 Linux CentOS 软件安装配置脚本
7+
* @author: Zhang Peng
8+
***********************************************************************************
9+
10+
EOF
11+
12+
menus=("git" "zsh" "jdk8" "maven" "nodejs" "mongodb" "redis" "tomcat8" "kafka" "rocketmq" "zookeeper")
13+
printMenu() {
14+
for i in "${!menus[@]}"; do
15+
index=`expr ${i} + 1`
16+
val=`expr ${index} % 2`
17+
printf "(%02d) %-20s" "${index}" "${menus[$i]}"
18+
if [[ ${val} -eq 0 ]]; then
19+
printf "\n"
20+
fi
21+
done
22+
printf "\n请输入需要安装的软件编号:\n"
23+
}
24+
25+
26+
main() {
27+
read -t 30 index
28+
if [[ -n $index ]]; then
29+
no=`expr ${index} - 1`
30+
len=${#menus[*]}
31+
if [[ ${index} -gt ${len} ]]; then
32+
echo "输入项不支持!"
33+
exit -1
34+
fi
35+
key=${menus[$no]}
36+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/${key}-install.sh | bash
37+
else
38+
echo "输入项不支持!"
39+
exit -1
40+
fi
41+
42+
}
43+
44+
######################################## MAIN ########################################
45+
printMenu
46+
main

codes/linux/ops/dunwu-sys.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
cat << EOF
4+
5+
###################################################################################
6+
# Linux CentOS 环境初始化脚本(设置环境配置、安装基本的命令工具)
7+
# @author: Zhang Peng
8+
###################################################################################
9+
10+
EOF
11+
12+
menus=("替换yum镜像" "安装基本的命令工具" "安装常用libs" "系统配置" "全部执行" "退出")
13+
main() {
14+
PS3="请输入命令编号:"
15+
select item in ${menus[@]}
16+
do
17+
case ${item} in
18+
"替换yum镜像")
19+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/change-yum-repo.sh | bash
20+
main ;;
21+
"安装基本的命令工具")
22+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-tools.sh | bash
23+
main ;;
24+
"安装常用libs")
25+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-libs.sh | bash
26+
main ;;
27+
"系统配置")
28+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/sys-settings.sh | bash
29+
main ;;
30+
"全部执行")
31+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/change-yum-repo.sh | bash
32+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-tools | bash
33+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-libs.sh | bash
34+
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/sys-settings.sh | bash
35+
printf "执行完毕,退出。\n" ;;
36+
"退出")
37+
exit 0 ;;
38+
*)
39+
printf "输入项不支持!\n"
40+
main ;;
41+
esac
42+
break
43+
done
44+
}
45+
46+
######################################## MAIN ########################################
47+
main

codes/linux/ops/soft/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,39 @@ curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/lin
7676
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash
7777
```
7878

79-
## Redis 安装
79+
## Redis 安装配置
8080

8181
说明:
8282

83-
下载 redis `5.0.4` 并解压安装到 `/opt/redis` 路径下。
83+
- 下载 redis `5.0.4` 并解压安装到 `/opt/redis` 路径下。
84+
- 替换配置,使得 Redis 可以远程访问,并设置默认密码为 123456。
85+
- 注册 redis 服务,并设置为开机自启动
8486

8587
使用方法:
8688

87-
执行以下任意命令即可执行安装脚本
89+
执行以下任意命令即可按照默认配置安装脚本
8890

8991
```sh
9092
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash
9193
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash
9294
```
9395

96+
定制化配置
97+
98+
```sh
99+
# 下载脚本到本地
100+
wget https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh
101+
chmod +x redis-install.sh
102+
./redis-install.sh 5.0.4 /opt/redis 6379 123456
103+
```
104+
105+
说明:
106+
107+
- 第一个参数是 redis 版本号;
108+
- 第二个参数是 redis 安装路径;
109+
- 第三个参数是 redis 服务端口号;
110+
- 第四个参数是访问密码
111+
94112
## Tomcat8 安装
95113

96114
说明:

codes/linux/ops/soft/main.sh

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

codes/linux/ops/soft/redis-config.sh

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

codes/linux/ops/soft/redis-install.sh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ if [[ -n $2 ]]; then
2020
root=$2
2121
fi
2222

23+
port=6379
24+
if [[ -n $3 ]]; then
25+
port=$3
26+
fi
27+
28+
password=123456
29+
if [[ -n $4 ]]; then
30+
path=$4
31+
fi
32+
2333
echo -e "\n>>>>>>>>> install libs"
2434
yum install -y zlib zlib-devel gcc-c++ libtool openssl openssl-devel tcl
2535

@@ -28,7 +38,28 @@ mkdir -p ${root}
2838
wget -O ${root}/redis-${version}.tar.gz http://download.redis.io/releases/redis-${version}.tar.gz
2939

3040
echo -e "\n>>>>>>>>> install redis"
41+
path=${root}/redis-${version}
3142
tar zxf ${root}/redis-${version}.tar.gz -C ${root}
32-
cd ${root}/redis-${version}
43+
cd ${path}
3344
make && make install
3445
cd -
46+
47+
echo -e "\n>>>>>>>>> config redis"
48+
cp ${path}/redis.conf ${path}/redis.conf.default
49+
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/config/redis-remote-access.conf -O ${path}/redis.conf
50+
cp ${path}/redis.conf /etc/redis/${port}.conf
51+
sed -i "s/^port 6379/port ${port}/g" /etc/redis/${port}.conf
52+
sed -i "s/^requirepass 123456/requirepass ${password}/g" /etc/redis/${port}.conf
53+
54+
echo -e "\n>>>>>>>>> add firewall port"
55+
firewall-cmd --zone=public --add-port=${port}/tcp --permanent
56+
firewall-cmd --reload
57+
58+
echo -e "\n>>>>>>>>> add redis service"
59+
# 注册 redis 服务,并设置开机自启动
60+
cp ${path}/utils/redis_init_script /etc/init.d/redis_${port}
61+
sed -i "s/^REDISPORT=.*/REDISPORT=${port}/g" /etc/init.d/redis_${port}
62+
chmod +x /etc/init.d/redis_${port}
63+
chkconfig --add redis_${port}
64+
service redis_${port} start
65+

0 commit comments

Comments
 (0)