breeze配置K8S deploy机的shell自动化脚本

由于按照睿云智和的breeze图形化部署K8S仍然需要准备配置deploy机,所以细化了一下脚本直接完成deploy机器的自动化配置:

使用cobbler或者kickstart安装一台纯净的minimal的deploy机器步骤省略,直接贴deploy机器的配置;

个人懒得写注释了,这是一个母版雏形,可以直接使用,但是不含任何变量,东西都是写死的,所以可以适当扩展增加变量使脚本变得更灵活,例如把版本或者ansible配置都变成传参,在此就不再深入些了,亲测有效:

#!/bin/sh

#Firewall & selinux preparation
#Pdf provides
setenforce 0
sed -ri '/SELINUX=/c\SELINUX=disabled' /etc/selinux/config
firewall-cmd --set-default-zone=trusted
firewall-cmd --complete-reload


#Install docker-compose
if [ -e /usr/local/bin/docker-compose ];then
    echo "docker-compose exists~"
else
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
fi

#Install docker
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine -y

yum install -y yum-utils device-mapper-persistent-data lvm2 && yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && yum install docker-ce docker-ce-cli containerd.io -y

systemctl enable docker && systemctl start docker

#Config Daocloud accelarate
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io && systemctl restart docker

#Install ansible
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
yum -y install epel-release && yum -y install ansible

cat >> /etc/ansible/hosts <<-EOF
[k8s]           #change into the name you wanna change
192.168.25.10 ansible_ssh_user="root" ansible_ssh_pass="root" ansible_ssh_port=22
192.168.25.11 ansible_ssh_user="root" ansible_ssh_pass="root" ansible_ssh_port=22 
192.168.25.12 ansible_ssh_user="root" ansible_ssh_pass="root" ansible_ssh_port=22 
192.168.25.20 ansible_ssh_user="root" ansible_ssh_pass="root" ansible_ssh_port=22
EOF

sed -ri '/^#host/c\host_key_checking = False' /etc/ansible/ansible.cfg

ansible k8s -m authorized_key -a "user=root key='{{ lookup('file','/root/.ssh/id_rsa.pub') }}'"

#Download breeze and install
yum -y install wget && wget -nc https://github.com/wise2c-devops/breeze/archive/v1.13.4.tar.gz && tar -xf v1.13.4.tar.gz && cd breeze-1.13.4 && docker-compose up -d

#Checking status after install
docker ps -a

最后上传部署后的日志:

setenforce: SELinux is disabled
Warning: ZONE_ALREADY_SET: trusted
success
success
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    435      0 --:--:--  0:00:01 --:--:--   435
100 10.3M  100 10.3M    0     0   105k      0  0:01:40  0:01:40 --:--:--  108k
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.huaweicloud.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.huaweicloud.com
Package yum-utils-1.1.31-50.el7.noarch already installed and latest version
Package device-mapper-persistent-data-0.7.3-3.el7.x86_64 already installed and latest version
Package 7:lvm2-2.02.180-10.el7_6.3.x86_64 already installed and latest version
Nothing to do
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.huaweicloud.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.huaweicloud.com
Package 3:docker-ce-18.09.4-3.el7.x86_64 already installed and latest version
Package 1:docker-ce-cli-18.09.4-3.el7.x86_64 already installed and latest version
Package containerd.io-1.2.5-3.1.el7.x86_64 already installed and latest version
Nothing to do
docker version >= 1.12
{"registry-mirrors": ["http://f1361db2.m.daocloud.io"]}
Success.
You need to restart docker to take effect: sudo systemctl restart docker 
Generating public/private rsa key pair.
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? n
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.huaweicloud.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.huaweicloud.com
Package epel-release-7-11.noarch already installed and latest version
Nothing to do
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.huaweicloud.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.huaweicloud.com
Package ansible-2.7.9-1.el7.noarch already installed and latest version
Nothing to do
192.168.25.20 | SUCCESS => {
    "changed": false, 
    "comment": null, 
    "exclusive": false, 
    "follow": false, 
    "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuBxVR5S5usDFsahBsN8nsfgZprQSr+73kxoE6HNs9tqAYzFf9RdsF5J1WkOORWahFbq0gW6oAwlbfvtwwa/td+9SgFr0zeoZdilzvfNsYJN2GqmrY9yNkBHXlQmoj2kZkYSIR9hJpUqY2FGugQBUa7dJEO9+Go9BMJc1Pxtj7ijn7t7PpEn+EhCl2ZxY/xazqzZ+FEOP6z4P5+KB0+j80Ks2xaHGvlu/1S8jMyGFgbrKntjQbpREDweW8/CvssSBkJqpuif66Oaw75hqLVvlaWuwk6GNOc7l7tTGc06MxS9O8kFo47U+41YmNU00Grx2TiuKp/SNYDbY5b8G6AYyr root@deploy", 
    "key_options": null, 
    "keyfile": "/root/.ssh/authorized_keys", 
    "manage_dir": true, 
    "path": null, 
    "state": "present", 
    "unique": false, 
    "user": "root", 
    "validate_certs": true
}
192.168.25.10 | SUCCESS => {
    "changed": false, 
    "comment": null, 
    "exclusive": false, 
    "follow": false, 
    "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuBxVR5S5usDFsahBsN8nsfgZprQSr+73kxoE6HNs9tqAYzFf9RdsF5J1WkOORWahFbq0gW6oAwlbfvtwwa/td+9SgFr0zeoZdilzvfNsYJN2GqmrY9yNkBHXlQmoj2kZkYSIR9hJpUqY2FGugQBUa7dJEO9+Go9BMJc1Pxtj7ijn7t7PpEn+EhCl2ZxY/xazqzZ+FEOP6z4P5+KB0+j80Ks2xaHGvlu/1S8jMyGFgbrKntjQbpREDweW8/CvssSBkJqpuif66Oaw75hqLVvlaWuwk6GNOc7l7tTGc06MxS9O8kFo47U+41YmNU00Grx2TiuKp/SNYDbY5b8G6AYyr root@deploy", 
    "key_options": null, 
    "keyfile": "/root/.ssh/authorized_keys", 
    "manage_dir": true, 
    "path": null, 
    "state": "present", 
    "unique": false, 
    "user": "root", 
    "validate_certs": true
}
192.168.25.12 | SUCCESS => {
    "changed": false, 
    "comment": null, 
    "exclusive": false, 
    "follow": false, 
    "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuBxVR5S5usDFsahBsN8nsfgZprQSr+73kxoE6HNs9tqAYzFf9RdsF5J1WkOORWahFbq0gW6oAwlbfvtwwa/td+9SgFr0zeoZdilzvfNsYJN2GqmrY9yNkBHXlQmoj2kZkYSIR9hJpUqY2FGugQBUa7dJEO9+Go9BMJc1Pxtj7ijn7t7PpEn+EhCl2ZxY/xazqzZ+FEOP6z4P5+KB0+j80Ks2xaHGvlu/1S8jMyGFgbrKntjQbpREDweW8/CvssSBkJqpuif66Oaw75hqLVvlaWuwk6GNOc7l7tTGc06MxS9O8kFo47U+41YmNU00Grx2TiuKp/SNYDbY5b8G6AYyr root@deploy", 
    "key_options": null, 
    "keyfile": "/root/.ssh/authorized_keys", 
    "manage_dir": true, 
    "path": null, 
    "state": "present", 
    "unique": false, 
    "user": "root", 
    "validate_certs": true
}
192.168.25.11 | SUCCESS => {
    "changed": false, 
    "comment": null, 
    "exclusive": false, 
    "follow": false, 
    "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuBxVR5S5usDFsahBsN8nsfgZprQSr+73kxoE6HNs9tqAYzFf9RdsF5J1WkOORWahFbq0gW6oAwlbfvtwwa/td+9SgFr0zeoZdilzvfNsYJN2GqmrY9yNkBHXlQmoj2kZkYSIR9hJpUqY2FGugQBUa7dJEO9+Go9BMJc1Pxtj7ijn7t7PpEn+EhCl2ZxY/xazqzZ+FEOP6z4P5+KB0+j80Ks2xaHGvlu/1S8jMyGFgbrKntjQbpREDweW8/CvssSBkJqpuif66Oaw75hqLVvlaWuwk6GNOc7l7tTGc06MxS9O8kFo47U+41YmNU00Grx2TiuKp/SNYDbY5b8G6AYyr root@deploy", 
    "key_options": null, 
    "keyfile": "/root/.ssh/authorized_keys", 
    "manage_dir": true, 
    "path": null, 
    "state": "present", 
    "unique": false, 
    "user": "root", 
    "validate_certs": true
}
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.huaweicloud.com
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.huaweicloud.com
Package wget-1.14-18.el7.x86_64 already installed and latest version
Nothing to do
File ‘v1.13.4.tar.gz’ already there; not retrieving.

Creating network "breeze-1134_default" with the default driver
Creating volume "breeze-1134_playbook" with default driver
Pulling playbook (wise2c/playbook:v1.13.4)...
v1.13.4: Pulling from wise2c/playbook
697743189b6d: Pull complete
87e261fa033b: Pull complete
c77709860ed9: Pull complete
5f25f28b376f: Pull complete
144e5fd29828: Pull complete
362e7d141286: Pull complete
aa4d63553217: Pull complete
418cbcb23cc6: Pull complete
4783dd8b6f55: Pull complete
6e9fa4e95c6f: Pull complete
Digest: sha256:582bf48cfe007ef38270c4d09c60b0e0cbb1722c530c013d6942f2833d02800e
Status: Downloaded newer image for wise2c/playbook:v1.13.4
Pulling deploy (wise2c/pagoda:v1.1)...
v1.1: Pulling from wise2c/pagoda
a0e0ef996968: Pull complete
9b3014edd871: Pull complete
c5eded658159: Pull complete
c45a1c0c2455: Pull complete
46399003276c: Pull complete
ccac9c54f668: Pull complete
57fd101ecf1c: Pull complete
0f5ba6f34d40: Pull complete
b116f6ac6348: Pull complete
145e9a179549: Pull complete
2209be18dc9e: Pull complete
abc4297bec89: Pull complete
c0c294b79d8d: Pull complete
81b136d4261f: Pull complete
a949dbc55c9b: Pull complete
3936d68676c6: Pull complete
Digest: sha256:7d7c37b80182e3d97e7fb4de339430d5f3f52d64a375e1ced01d28e9bfa72314
Status: Downloaded newer image for wise2c/pagoda:v1.1
Pulling ui (wise2c/deploy-ui:v1.3)...
v1.3: Pulling from wise2c/deploy-ui
407ea412d82c: Pull complete
f1e1d8e69297: Pull complete
8dbb80bd9ddf: Pull complete
189c76f3a269: Pull complete
a772b0dbfb38: Pull complete
28da0ef10bfe: Pull complete
Digest: sha256:a199d1d25b135294ea884d25d4c04dfeb14a3a317a115a384a7b55746dee4045
Status: Downloaded newer image for wise2c/deploy-ui:v1.3
Pulling yum-repo (wise2c/yum-repo:v1.13.4)...
v1.13.4: Pulling from wise2c/yum-repo
6c40cc604d8e: Pull complete
fe449da6d669: Pull complete
bf1473f11cd8: Pull complete
06b03b3b4e39: Pull complete
70c1bbe94218: Pull complete
89aa2d966173: Pull complete
af02dc3cc578: Pull complete
0362d6b0e18e: Pull complete
Digest: sha256:9039a04697bed3e09b20320a481d5731192063ea18b4476689d7fb3fb301ad44
Status: Downloaded newer image for wise2c/yum-repo:v1.13.4
Creating deploy-playbook ... done
Creating deploy-yumrepo  ... done
Creating deploy-main     ... done
Creating deploy-ui       ... done

CONTAINER ID        IMAGE                     COMMAND                  CREATED                  STATUS                    PORTS                                        NAMES
4a7447fce196        wise2c/deploy-ui:v1.3     "/root/entrypoint.sh"    Less than a second ago   Up Less than a second                                                  deploy-ui
feed3a63a121        wise2c/pagoda:v1.1        "sh -c '/root/pagoda…"   1 second ago             Up Less than a second     0.0.0.0:88->80/tcp, 0.0.0.0:8088->8080/tcp   deploy-main
bbc97623a7d0        wise2c/yum-repo:v1.13.4   "nginx -g 'daemon of…"   4 seconds ago            Up 2 seconds              80/tcp, 0.0.0.0:2009->2009/tcp               deploy-yumrepo
248a4e66149b        wise2c/playbook:v1.13.4   "sh"                     4 seconds ago            Exited (0) 1 second ago                                                deploy-playbook

你可能感兴趣的:(breeze配置K8S deploy机的shell自动化脚本)