一.Docker部署
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce
service docker start
vim /usr/lib/systemd/system/docker.service
#添加
--graph /data/docker --storage-driver=overlay
systemctl daemon-reload
service docker restart
二.Docker-swarm集羣的搭建
1. 挑選一個節點做爲管理節點
[root@jenkins-master ~]#docker swarm init --advertise-addr 192.168.0.46
docker swarm join-token worker命令是查看使用主節點的token添加節點到集羣的命令
[root@jenkins-master ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-5vzw37ummd0h863jddbig798pbq3jpgoepf95g4uenodwhtc7v-543arzx838nj0pgo2yujyfko4 \
192.168.0.46:2377
[root@jenkins47~]# docker swarm join --token SWMTKN-1-5vzw37ummd0h863jddbig798pbq3jpgoepf95g4uenodwhtc7v-543arzx838nj0pgo2yujyfko4 192.168.0.46:2377
[root@jenkins-master ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
5s0spx5wonjgsl8k63vfybq1v zabbix.xxxx Ready Active
ttfs9upr4bmhyt9ssfxfixkwm jenkins47 Ready Active
uc40c8karvu3pq2eupllyicz8 * jenkins-master Ready Active Leader
三.Docker-swarm內部network,nginx等配置
1. 鏡像倉庫建立
docker run -d --name basic-registry --net=skong -p 5000 -v /data/registry:/var/lib/registry -v /data/web/certs:/certs registry:latest
2. network建立
docker network create -d overlay --subnet=10.0.1.0/24 --attachable sk-net
3. swarm集羣內部nginx容器建立
docker run -d --name nginx --net=sk-net -p 80:80 -p 443:443 -v /data/web/xxxx:/data/conf -v /data/web/certs:/data/ssl basic-registry.xxxx.com/xxx/nginx
須要將nginx的配置文件掛載放在外面以便隨時更改生效
四.swarm 集羣中的service建立使用
1. service建立
docker service create --name sk_resource --hostname sk_resource --network sk-net registry.xxxx.com/sk_runtime:master
在swarm中service的概念有點相似nginx的upstream,能夠配置多個容器同時還有高可用的功能,service name在swarm的network能夠理解成主機名/ip
server {
listen 80;
server_name dev-test.xxxx.com;
access_log /data/nginx/logs/ll.log main;
location / {
proxy_pass http://sk_resource;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_buffering on;
proxy_busy_buffers_size 64k;
proxy_max_temp_file_size 1024m;
}
}
五.Jenkins配合容器集羣更新服務
1. service建立
- ansible 遠程docker master 更新服務鏡像
ansible 192.168.2.10 -m shell -a 'docker service update --image registry.xxxx.com/sk_runtime:beta1.0 sk_resource'