8000 m · mgicode/mgicode-k8s-shell@773cad9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 773cad9

Browse files
committed
m
1 parent 07c7f22 commit 773cad9

File tree

5 files changed

+395
-40
lines changed

5 files changed

+395
-40
lines changed

05k8s(192.168.0.20)/01admin/06ssh.sh

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ for ip in $NODE_IPS ;do
2323

2424
NAME=${NAMES[$i]}
2525
echo "name:$NAME,ip:$ip "
26-
#检测是否开机
26+
#1、检测是否开机
2727
for index1 in {1..255} ; do
2828
ping -c 1 -w 1 $ip &>/dev/null
2929
if [ $? -eq 0 ]; then
@@ -36,7 +36,7 @@ for ip in $NODE_IPS ;do
3636
done
3737
echo "sleep: 10"
3838
sleep 10
39-
# 进行ssh免证登录,如果在本机中已经有117的记录
39+
# 2、进行ssh免证登录,ssh-copy-id到需要免登录的机器上
4040
expect -c "
4141
set timeout 5
4242
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$ip
@@ -54,43 +54,45 @@ for ip in $NODE_IPS ;do
5454
#该时间需要足够长,不然spawn执行的命令的伪线程还没有关闭,那么第二次就会connect refused!
5555
echo "sleep: 10"
5656
sleep 10
57-
#执行相关操作,这里主要改名,改ip并重启
57+
58+
#3、对每台机器进行初始化操作。其操作在/common/init.sh中定义
59+
# 执行相关操作,这里主要改名,改ip并重启
5860
scp /common/init.sh root@$ip:/root/init.sh
5961
#ssh -t -p $port $user@$ip "remote_cmd"
6062
ssh root@$ip "chmod 777 /root/init.sh; cd /root/; ./init.sh; "
6163
let i++
6264

63-
#检测是否$ip是否开机
64-
for index1 in {1..20} ; do
65-
ping -c 1 -w 1 $ip &>/dev/null
66-
if [ $? -eq 0 ]; then
67-
echo "sleep: 40"
68-
sleep 40
69-
echo "$ip $NAME重启完成... "
70-
#初始化$IP认证提示
71-
expect -c "
72-
set timeout 5
73-
spawn ssh root@$ip ""
74-
expect {
75-
"*yes/no" { send "yes\\r"; exp_continue}
76-
"*assword:" { send "${TEMPLATE_NODE_PWD}\\r" }
77-
"*ERROR:" { exp_continue }
78-
"*inet" { exp_continue }
79-
}
80-
expect eof
81-
exit
82-
#expect进程要退出,不然在循环中再次运行报错
83-
"
84-
#该时间需要足够长,不然spawn执行的命令的伪线程还没有关闭,那么第二次就会connect refused!
85-
echo "sleep: 20"
86-
87-
sleep 20
88-
break;
89-
else
90-
echo "$ip正在重启中... "
91-
sleep 15;
92-
fi
93-
done
65+
#4 检测是否$ip是否开机
66+
for index1 in {1..20} ; do
67+
ping -c 1 -w 1 $ip &>/dev/null
68+
if [ $? -eq 0 ]; then
69+
echo "sleep: 40"
70+
sleep 40
71+
echo "$ip $NAME重启完成... "
72+
#初始化$IP认证提示
73+
expect -c "
74+
set timeout 5
75+
spawn ssh root@$ip ""
76+
expect {
77+
"*yes/no" { send "yes\\r"; exp_continue}
78+
"*assword:" { send "${TEMPLATE_NODE_PWD}\\r" }
79+
"*ERROR:" { exp_continue }
80+
"*inet" { exp_continue }
81+
}
82+
expect eof
83+
exit
84+
#expect进程要退出,不然在循环中再次运行报错
85+
"
86+
#该时间需要足够长,不然spawn执行的命令的伪线程还没有关闭,那么第二次就会connect refused!
87+
echo "sleep: 20"
88+
89+
sleep 20
90+
break;
91+
else
92+
echo "$ip正在重启中... "
93+
sleep 15;
94+
fi
95+
done
9496

9597
done
9698

doc/01springboot-docker-starter.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
[Spring boot+docker 半自动化部署(十一)、consul-template的安装](https://github.com/mgicode/mgicode-k8s-shell/blob/master/doc/11springboot-docker-consul-template.md)
4848

49-
5049
[Spring boot+docker 半自动化部署(十二)、测试连通程序的设计](https://github.com/mgicode/mgicode-k8s-shell/blob/master/doc/12springboot-docker-echo-code.md)
5150

5251

doc/04springboot-docker-net-design.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,3 @@ docker作为基础环境,最好每台物理服务器上都安装。
4040

4141

4242

43-
tv:
44-
322 307 516
45-
4317

doc/05springboot-docker-admin-init.md

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,176 @@
44

55
## 初始化环境
66

7+
初始化环境需要安装常用的网络调试及使用工具,关掉防火墙,关于大页内存,也可以有选择关掉。
8+
9+
centos 7 别名了rm等相关指令,删除前需要手动确定,这个对于命令执行很不方便,所以要去掉alias
10+
11+
IPv4 forwarding需要打开,走ipv4的网络不通,特别是keepalive+haproxy做负载均衡或代理时,不打开这样,网络通不过。
12+
13+
```
14+
#安装网络及常用工具
15+
yum install wget -y
16+
yum install -y telnet nmap curl tcping
17+
yum install unzip -y
18+
yum install traceroute -y
19+
yum install mtr -y
20+
21+
#关掉防火墙
22+
systemctl stop firewalld.service
23+
systemctl disable firewalld.service
24+
25+
#关掉selinux enforcing:强制模式 permissive:宽容模式 disabled:关闭
26+
sed -i "s/=enforcing/=disabled/g" /etc/selinux/config
27+
cat /etc/selinux/config
28+
setenforce 0
29+
30+
#关掉大页内存
31+
cat >/etc/rc.local << EOF
32+
#!/bin/bash
33+
touch /var/lock/subsys/local
34+
echo never >/sys/kernel/mm/transparent_hugepage/enabled
35+
echo never >/sys/kernel/mm/transparent_hugepage/defrag
36+
EOF
37+
chmod +x /etc/rc.d/rc.local
38+
cat /etc/rc.local
39+
40+
#去掉alias
41+
sed -i "s/alias/#alias/g" ~/.bashrc
42+
cat ~/.bashrc
43+
44+
#WARNING: IPv4 forwarding is disabled. Networking will not work.
45+
cat >/etc/sysctl.conf <<EOF
46+
net.ipv4.ip_forward=1
47+
EOF
48+
systemctl restart network
49+
#查看
50+
sysctl net.ipv4.ip_forward
51+
752
```
853

54+
## 安装Docker
55+
docker是容器安装的基础环境,这个需要先决条件。必须要求
56+
57+
58+
### 下载解压
59+
因为管理机会管理所有机器的安装,对于每一种安装,要分门别类建立目录,把相关的文件存放在对应的目录中
960

1061
```
62+
# 把下载的好的docker放在上面并安装docker
63+
mkdir /docker/
64+
cd /docker/
65+
wget https://download.docker.com/linux/static/stable/x86_64/docker-17.06.2-ce.tgz
66+
tar -xvf docker-17.06.2-ce.tgz
67+
mkdir /usr/local/bin/
68+
cp -rf docker/docker* /usr/local/bin/
1169
70+
```
1271

72+
### 创建service文件
1373

14-
## 安装Docker
74+
centos7已经默认支持systemd的方式,安装docker采用service安装最佳的方式
1575

76+
```
77+
cat > /docker/docker.service << EOF
78+
[Unit]
79+
Description=Docker Application Container Engine
80+
Documentation=http://docs.docker.io
81+
[Service]
82+
Environment="PATH=/root/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
83+
EnvironmentFile=-/run/flannel/docker
84+
ExecStart=/usr/local/bin/dockerd --log-level=error \$DOCKER_NETWORK_OPTIONS
85+
ExecReload=/bin/kill -s HUP \$MAINPID
86+
Restart=on-failure
87+
RestartSec=5
88+
LimitNOFILE=infinity
89+
LimitNPROC=infinity
90+
LimitCORE=infinity
91+
Delegate=yes
92+
KillMode=process
93+
[Install]
94+
WantedBy=multi-user.target
95+
EOF
96+
97+
sudo iptables -P FORWARD ACCEPT
98+
cat /docker/docker.service
1699
100+
```
17101

102+
### 加速镜像
18103

104+
中国地区下载docker官方很慢,需要加速,需要配置加速镜像,一般现在使用aliyun加速。
105+
另外内网中访问则采用http的方式,docker register 默认采用了https,需要作
106+
http的 insecure-registries的配置
19107

108+
```
109+
mkdir -p /etc/docker/
110+
cat > /etc/docker/daemon.json << EOF
111+
{
112+
"registry-mirrors": ["https://ap1xf0lr.mirror.aliyuncs.com","http://2f02dbc7.m.daocloud.io", "https://docker.mirrors.ustc.edu.cn", "hub-mirror.c.163.com"],
113+
"max-concurrent-downloads": 10,
114+
"insecure-registries":["192.168.0.20:5000","10.1.12.61:5000","10.1.11.60:5000"]
115+
}
116+
EOF
20117
21-
## 安装文件服务器
118+
cat /etc/docker/daemon.json
22119
120+
cp -rf /docker/docker.service /etc/systemd/system/docker.service
23121
122+
```
123+
### 启动服务
24124

125+
```
126+
sudo iptables -F && sudo iptables -X && sudo iptables -F -t nat && sudo iptables -X -t nat
25127
128+
sudo systemctl daemon-reload
129+
sudo systemctl enable docker
130+
sudo systemctl start docker
131+
sudo systemctl status docker
26132
133+
#测试能够下载文件
134+
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/pause-amd64:3.0
135+
docker tag registry.cn-hangzhou.aliyuncs.com/kube_containers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0
136+
docker rmi registry.cn-hangzhou.aliyuncs.com/kube_containers/pause-amd64:3.0
137+
138+
```
139+
140+
## 安装文件服务器
141+
文件服务器主要为了安装过程使用的内部文件下载的服务器,可以采用tomcat、Apache,这样小型的文件服务采用docker的 nginx安装是最方便的。
142+
首先需要在本地建立一个文件夹,把需要的文件放到该文件夹中,然后wget就可以通过http在内部中下载使用,
143+
该文件服务器是安装过程所必须的,如果没有话,批量安装从外网下(能下的话)非常慢。
27144

28145

146+
```
147+
mkdir -p /www/
148+
#把相关的文件放到宿主机的/www中,即可直接访问
149+
docker run -d -v /www:/usr/share/nginx/html --restart=always \
150+
--name nginx-server -p 80:80 nginx:1.7.9
151+
152+
#把docker文件放到文件服务器上去,然后就可以下载
153+
mkdir -p /www/docker/
154+
cp /docker/docker-17.06.2-ce.tgz /www/docker/docker-17.06.2-ce.tgz
155+
#本地测试能不能下载
156+
wget http://192.168.0.20/docker/docker-17.06.2-ce.tgz
29157
158+
接下来就要把自己需要的文件都分门别类地放到/www目录中即可,不用重启nginx
30159
160+
```
31161

32162
## 安装docker镜像库
33163

164+
无论是开发还是生产,无论是高大上还是简单的部署方式,内部镜像库是必不可少,不要被忽悠上传到阿里云,安全不讲,再快的速度也没有内网快和稳定。安装非高可用的docker镜像库与安装文件服务器一样简单。
165+
166+
167+
```
168+
mkdir -p /my_regisitry/
169+
docker run -d -p 5000:5000 --restart=always --name registryV2 \
170+
-v /my_regisitry:/var/lib/registry registry:2
171+
172+
```
173+
174+
镜像文件会映射到/my_regisitry/目录中,可以查看。另外这里最好加--restart=always,有时候服务器重启之后,这个不重启,其访问不了镜像,这个在k8s中特别明显,如果该服务死了,所有的k8s重启时都拉不到镜像,出错一大片,如果应用高可用,这个还是需要做成高可用的。
175+
176+
34177

35178

36179

0 commit comments

Comments
 (0)
0