千家信息网

Docker编排工具之Rancher-Server集群部署

发表于:2024-10-11 作者:千家信息网编辑
千家信息网最后更新 2024年10月11日,部署环境:操作系统:CentOS 7安装iptables,禁用firewall,清空iptables规则并保存关闭SELinux升级内核yum -y updateDocker版本:17.03.1-ce
千家信息网最后更新 2024年10月11日Docker编排工具之Rancher-Server集群部署

部署环境:


  1. 操作系统:CentOS 7

    安装iptables,禁用firewall,清空iptables规则并保存

    关闭SELinux

    升级内核yum -y update

  2. Docker版本:17.03.1-ce

    Docker其它版本下载源

支持的Docker版本


在开始部署Rancher之前需要确定以上环境没有问题

开始部署:

  • 部署MySQL(安装过程省略)推荐使用.5.6.x版本

创建库

CREATE DATABASE IF NOT EXISTS cattle COLLATE = 'utf8_general_ci' CHARACTER SET = 'utf8';

创建数据库授权

GRANT ALL ON cattle.* TO 'cattle'@'%' IDENTIFIED BY 'cattle';GRANT ALL ON cattle.* TO 'cattle'@'localhost' IDENTIFIED BY 'cattle';

部署Rancher-Server(部署集群模式)

在A服务器上面执行

sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server --db-host myhost.example.com --db-port 3306 --db-user username --db-pass password --db-name cattle

--db-host 指定MySQL服务器的连接地址

--db-port 连接端口

--db-user 连接用户

--db-pass 连接密码

--db-name 连接库名


在B服务器上面执行(与A服务器一样,如果还有其它服务器同样操作)


  • 配置Nginx反向代理

编辑/etc/nginx/conf.d/rancher.conf

注意:location里面配置不可更改,其它根据自己实际环境更改

upstream rancher {    server 192.168.1.31:8080;    server 192.168.1.32:8080;}server {    listen 80;    server_name rancher.aek.com;    location / {        proxy_set_header Host $host;        proxy_set_header X-Forwarded-Proto $scheme;        proxy_set_header X-Forwarded-Port $server_port;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_pass http://rancher;        proxy_http_version 1.1;        proxy_set_header Upgrade $http_upgrade;        proxy_set_header Connection "Upgrade";        # This allows the ability for the execute shell window to remain open for up to 15 minutes. Without this parameter, the default is 1 minute and will automatically close.        proxy_read_timeout 900s;    }}
  • 验证

    Rancher-Server端集群是否部署成功浏览器访问rancher.aek.com,打开以下界面查看如果红色方框出现了AB两台主机的信息,说明集群配置成功


    注意:如果为集群模式,两个Server端的版本要一致升级或降级升级或者降级只需删除原来的Rancher-Server容器,然后启动一个新的容器,照第2步再操作一次即可测试

  • 测试

    停掉一台主机的Rancher-Server容器,是否还能继续访问,操作

  • 说明

    Rancher-Server只是一个管理平台,如果Server端容器停止,其服务器运行的其它容器并不会停止,只是无法使用Rancher-Server管理这些容器配置,比如调度,启动,停止等。当Rancher-Server恢复工作后即可再次进行管理,配置集群主要就是为了防止如果有一个停止后那么就无法进行管理等工作

0