sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://z34wtdhg.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
Docker镜像加速
rancher-server01 172.16.138.126
rancher-server02 172.16.138.127
rancher-mysql和Haproxy 172.16.138.128
1、搭建Mysql数据库(搭建Mysql过程忽略)
搭建要求:
- 至少 1 GB内存
- 每个Rancher Server节点需要50个连接 (例如:3个节点的Rancher则需要至少150个连接)
Mysql创建库和用户
1 CREATE DATABASE IF NOT EXISTS cattle COLLATE = 'utf8_general_ci' CHARACTER SET = 'utf8'; 2 GRANT ALL ON cattle.* TO 'cattle'@'%' IDENTIFIED BY 'cattle'; 3 GRANT ALL ON cattle.* TO 'cattle'@'localhost' IDENTIFIED BY 'cattle';
2、搭建Docker(搭建docker忽略)
搭建要求:
- 对于 RHEL/CentOS, 默认的 storage driver, 例如 devicemapper using loopback, 并不被Docker推荐。 请参考我博客中docker安装优化的Docker的官方文档文档去修改使用其他的storage driver。
9345
,8080
端口需要在各个节点之间能够互相访问- 1GB内存
启动rancher镜像
1 docker run -d --restart=unless-stopped -p 8080:8080 -p 9345:9345 rancher/server:v1.6.2 2 --db-host 172.16.138.128 --db-port 3306 --db-user cattle --db-pass cattle --db-name cattle 3 --advertise-address 172.16.138.127
--db-host指mysqlIP
--db-port指mysql端口
--db-user指用户cattle
--db-pass指用户的密码cattle
--advertise-addresszhi指当前server的IP
3、搭建haproxy
启动haproxy
配置文件
1 global 2 maxconn 4096 3 ssl-server-verify none 4 5 defaults 6 mode http 7 balance roundrobin 8 option redispatch 9 option forwardfor 10 11 timeout connect 5s 12 timeout queue 5s 13 timeout client 36000s 14 timeout server 36000s 15 16 frontend http-in 17 mode http 18 # bind *:443 ssl crt /etc/haproxy/certificate.pem 19 bind *:80 20 default_backend rancher_servers 21 22 # Add headers for SSL offloading 23 # http-request set-header X-Forwarded-Proto https if { ssl_fc } 24 # http-request set-header X-Forwarded-Ssl on if { ssl_fc } 25 26 acl is_websocket hdr(Upgrade) -i WebSocket 27 acl is_websocket hdr_beg(Host) -i ws 28 use_backend rancher_servers if is_websocket 29 30 backend rancher_servers 31 server websrv1 172.16.138.126:8080 weight 1 maxconn 1024 32 server websrv2 172.16.138.127:8080 weight 1 maxconn 1024
启动
nohup haproxy -f /etc/haproxy/haproxy.cfg &