自动运维 - 自动化脚本
自动化脚本整理记录
# 安装expect
$ apt-get -f install expect
1
# 1. 获取root权限
- 编辑
su.exp
脚本文件
#!/usr/bin/expect
set timeout 1
spawn su
expect ":"
send "kb123789\n"
interact
1
2
3
4
5
6
2
3
4
5
6
# 2. 安装openJDK
- 编辑
openjdk-8.exp
脚本文件
#!/usr/bin/expect
set timeout 5
spawn apt-get install openjdk-8-jdk
expect "Y/n"
send "y\n"
interact
1
2
3
4
5
6
7
2
3
4
5
6
7
# 3. 安装git
- 编辑
git.exp
脚本文件
#!/usr/bin/expect
set timeout 5
spawn apt-get install git
expect "Y/n"
send "y\n"
interact
1
2
3
4
5
6
7
2
3
4
5
6
7
# 4. 安装maven
- 编辑
maven.exp
脚本文件
#!/usr/bin/expect
set timeout 5
spawn apt-get install maven
expect "Y/n"
send "y\n"
interact
1
2
3
4
5
6
7
2
3
4
5
6
7
# 5. 安装Jenkins
- 编辑
jenkins.sh
脚本
#!/bin/bash
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | apt-key add -
sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
echo "添加Jenkins源完成"
apt-get update
echo "更新apt源完成"
expect jenkins.exp
echo "安装Jenkins完成"
gpasswd -a jenkins root
sed -i 's/JENKINS_USER=$NAME/JENKINS_USER=root/g' /etc/default/jenkins
sed -i 's/JENKINS_GROUP=$NAME/JENKINS_GROUP=root/g' /etc/default/jenkins
service jenkins restart
echo "设置Jenkins为root权限完成"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
- 编辑
jenkins.exp
脚本
#!/usr/bin/expect
set timeout 5
spawn apt-get install jenkins
expect "Y/n"
send "y\n"
interact
1
2
3
4
5
6
7
2
3
4
5
6
7
# 6. 安装docker
- 编写
docker_dep.exp
脚本
#!/usr/bin/expect
set timeout 5
spawn apt install apt-transport-https ca-certificates software-properties-common curl
expect "Y/n"
send "y\n"
interact
1
2
3
4
5
6
7
2
3
4
5
6
7
- 编辑
docker.sh
脚本
#!/bin/bash
expect docker_dep.exp
echo "安装docker基本依赖完成"
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | apt-key add -
echo "添加docker gpg key完成"
add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian stretch stable"
echo "添加docker源完成"
apt update
echo "更新apt源完成"
expect docker.exp
echo "安装docker-ce完成"
echo "{
\"registry-mirrors\": [\"https://exmmtkzp.mirror.aliyuncs.com\"]
}" > /etc/docker/daemon.json
systemctl restart docker
echo "更新docker镜像为阿里云完成"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
- 编辑
docker.exp
脚本
#!/usr/bin/expect
set timeout 5
spawn apt-get install docker-ce
expect "Y/n"
send "y\n"
interact
1
2
3
4
5
6
7
2
3
4
5
6
7
- 执行
docker.sh
脚本
上次更新: 2020/08/05, 09:08:00