Rancher Server 高可用搭建

测试环境

系统使用的是CentOS-7-x86_64-DVD-2003.iso
下载地址:http://mirrors.aliyun.com/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-DVD-2003.iso

节点IP地址
rancher-server 1192.168.1.10
rancher-server 2192.168.1.20
haproxy 负载均衡器192.168.1.30

所有节点提前关闭防火墙以及selinux

搭建过程如下

时间同步服务的配置
rancher-server 1作为时间服务器
rancher-server 2 和 haproxy 作为客户端来进行同步

rancher-server 1 的配置

先编辑hosts文件
[root@rancher1 ~]# vi /etc/hosts 
192.168.1.10    rancher-server1
192.168.1.20    rancher-server2
192.168.1.30    haproxy

然后将修改好的文件发送到其他两个节点
[root@rancher1 ~]# scp /etc/hosts root@rancher-server2:/etc/hosts
[root@rancher1 ~]# scp /etc/hosts root@haproxy:/etc/hosts

安装时间同步工具以及时间同步服务器
[root@rancher1 ~]# yum install -y ntp ntpdate 
[root@rancher1 ~]# ntpdate ntp1.aliyun.com    //同步阿里云的时间服务器
15 Nov 22:07:32 ntpdate[15175]: adjust time server 120.25.115.20 offset 0.011641 sec
[root@rancher1 ~]# clock -w 
[root@rancher1 ~]# vi /etc/ntp.conf   //编辑配置文件
 17 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap    //取消前面的注释
 18 server 127.127.1.0   //添加一行这个
 21 #server 0.centos.pool.ntp.org iburst  (注释以server开头的行)
 22 #server 1.centos.pool.ntp.org iburst
 23 #server 2.centos.pool.ntp.org iburst
 24 #server 3.centos.pool.ntp.org iburst
[root@rancher1 ~]# systemctl start ntpd   //启动时间服务器
[root@rancher1 ~]# systemctl enable ntpd 

rancher-server 2haproxy 同步时间(两个操作一致)
[root@rancher2 ~]# yum install -y ntpdate 
[root@rancher2 ~]# ntpdate rancher-server1   //同步节点一
15 Nov 22:14:38 ntpdate[21462]: adjust time server 192.168.1.10 offset 0.037389 sec
[root@rancher2 ~]# crontab -e   //编写周期计划
 */1 * * * * /usr/sbin/ntpdate rancher-server1 >> /var/log/ntpdate.log
[root@rancher2 ~]# systemctl restart crond 
[root@rancher2 ~]# systemctl enable crond 

rancher-server 1 和rancher-server 2 的配置
(两个搭建私有仓库相同,分别对应不同的私有仓库)
registry 私有仓库的搭建

registry 私有仓库的搭建

[root@rancher1 ~]# yum install -y docker   //安装docker
[root@rancher1 ~]# vi /etc/sysconfig/docker   //编辑配置文件
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry 192.168.1.10:5000'  //添加一个参数以 --insecure开头的
ADD_REGISTRY='--add-registry 192.168.1.10:5000'  //增加一条这个
[root@rancher1 ~]# systemctl start docker    //启动docker容器
[root@rancher1 ~]# systemctl enable docker 
[root@rancher1 ~]# docker pull docker.io/registry   //下载registry镜像
[root@rancher1 ~]# docker tag 2d4f4b5309b1 192.168.1.10:5000/registry:latest    //然后对下载好的进行打标
[root@rancher1 ~]# docker run -itd --name=registry -p 5000:5000 --restart=always 192.168.1.10:5000/registry:latest       //然后启动即可
[root@rancher1 ~]# docker push 192.168.1.10:5000/registry:latest    //之后将镜像推到仓库 里面去
[root@rancher1 ~]# curl 192.168.1.10:5000/v2/_catalog   //查看上传是否成功
{"repositories":["registry"]}
[root@rancher1 ~]# docker pull docker.io/rancher/server 
//下载rancher镜像
[root@rancher1 ~]# docker tag 98d8bb571885  192.168.1.10:5000/rancher/server:latest  //然后进行打标
[root@rancher1 ~]# docker push 192.168.1.10:5000/rancher/server:latest   //上传至私有仓库

rancher-server1登录数据库创建表以及相关用户

[root@rancher1 ~]# yum install -y mariadb mariadb-server   //数据库
[root@rancher1 ~]# systemctl start mariadb 
[root@rancher1 ~]# systemctl enable mariadb 
[root@rancher1 ~]# mysql_secure_installation 
[root@rancher1 ~]# mysql -uroot -p123
MariaDB [(none)]> create database if not exists cattle collate='utf8_general_ci' character set='utf8';
Query OK, 1 row affected (0.00 sec)   //创建的数据库名称是固定的cattle 这个需要这个需要支持utf-8字符
MariaDB [(none)]> grant all on cattle.* to 'cattle'@'localhost' identified by 'cattle';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on cattle.* to 'cattle'@'%' identified by 'cattle';
Query OK, 0 rows affected (0.01 sec)

以上创建了以后,会自动同步到rancher-server2

rancher-server1启动rancher服务器

[root@rancher1 ~]# docker run -itd --name=rancher1 --restart=unless-stopped -p 8080:8080 -p 9345:9345 192.168.1.10:5000/rancher/server:v1.6.5 --db-host 192.168.1.10 --db-port 3306 --db-user cattle --db-pass cattle --db-name cattle --advertise-address 192.168.1.10    
WARNING: IPv4 forwarding is disabled. Networking will not work.
278dfdf394e8c442b650849d97197c3e4e8acf275174b033c8014688a58dfd37

这里出现了两个端口号
-p 8080:8080  这个是容器的端口号
-p 9345:9345 这个是高可用的端口号  固定
--db-host 指定数据库的地址
--db-name 指定名称
--db-user  指定数据库的用户
--db-pass  指定用户的密码
--advertise-address 指定节点的IP地址

查看启动是否成功
[root@rancher1 ~]# docker ps
CONTAINER ID        IMAGE                                     COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
278dfdf394e8        192.168.1.10:5000/rancher/server:v1.6.5   "/usr/bin/entry --..."   2 minutes ago       Up 2 minutes        0.0.0.0:8080->8080/tcp, 3306/tcp, 0.0.0.0:9345->9345/tcp   rancher1

浏览器访问测试
在这里插入图片描述
rancher-server2 启动rancher服务即可(第二台不需要安装mariadb数据库)

rancher-server2服务器也需要搭建一个私有仓库
然后我们执行以下命令来启动rancher服务器
docker run -d --restart=unless-stopped -p 8080:8080 -p 9345:9345 192.168.1.20:5000/rancher/server:v1.6.5 --db-host 192.168.1.10 --db-port 3306 --db-user cattle --db-pass cattle --db-name cattle --advertise-address 192.168.1.20

浏览器查看是否加入成功
在这里插入图片描述
haproxy 负载均衡器的配置

[root@haproxy ~]# yum install -y haproxy   //下载haproxy软件
[root@haproxy ~]# vi /etc/haproxy/haproxy.cfg    //编辑配置文件
把里面的内容全部清除,写入如下内容即可
global
  maxconn 4096
  ssl-server-verify none

defaults
  mode http
  balance roundrobin
  option redispatch
  option forwardfor

 timeout connect 5s
  timeout queue 5s
  timeout client 36000s
  timeout server 36000s

frontend http-in
  mode tcp
  #bind *:443 ssl crt /etc/haproxy/certificate.pem
  bind *:80   //将后端服务器都代理到这个端口进行对外处理
  default_backend rancher_servers

  acl is_websocket hdr(Upgrade) -i WebSocket
  acl is_websocket hdr_beg(Host) -i ws
  use_backend rancher_servers if is_websocket

backend rancher_servers
  server websrv1 192.168.1.10:8080 weight 1 maxconn 1024 
  server websrv2 192.168.1.20:8080 weight 1 maxconn 1024 

[root@haproxy ~]# systemctl start haproxy    //启动服务
[root@haproxy ~]# systemctl enable haproxy 

浏览器输入haproxy的IP地址访问测试
在这里插入图片描述
高可用性测试

rancher-server1上停止掉rancher 服务
[root@rancher1 /]# docker ps 
CONTAINER ID        IMAGE                                     COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
120d4d5caf59        192.168.1.10:5000/rancher/server:v1.6.5   "/usr/bin/entry --..."   About an hour ago   Up About an hour    0.0.0.0:8080->8080/tcp, 3306/tcp, 0.0.0.0:9345->9345/tcp   hungry_galileo
[root@rancher1 /]# docker stop 120d4d5caf59   

然后我们在访问测试
在这里插入图片描述
成功访问!!!即是down掉rancher-server1也可以成功访问rancher 服务器,这样就实现了高可用

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ball-4444

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值