2019-02-28-rancher HA 部署

2019-02-28  本文已影响0人  ihujian

参考:Rancher Server HA的高可用部署实验

概述

本次部署使用了三台机器:

  1. Rancher_HA1: 8C32G、Ubuntu 16.04、Docker ce 17.02
  2. Rancher_HA2: 8C32G、Ubuntu 16.04、Docker ce 17.02
  3. Haproxy: 4C16G、Ubuntu 16.04
  4. 远程mysql 数据库

Docker 安装

sudo apt-get update

sudo apt-get -y install \
  apt-transport-https \
  ca-certificates \
   curl \
  software-properties-common
   
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

sudo apt-get update

apt-cache madison docker-ce

sudo apt-get -y install docker-ce=17.03.2~ce-0~ubuntu-xenial

sudo usermod -aG docker ubuntu

sudo systemctl stop docker

echo '{
   "registry-mirrors": ["https://registry.docker-cn.com"],
   "insecure-registries" : [ "" ],
   "graph": "/home/ubuntu/opt/docker"
}' | sudo tee --append /etc/docker/daemon.json

sudo gpasswd -a ${USER} docker

sudo systemctl start docker

启动rancher server

  1. 启动之前需要 在远程mysql 创建好rancher 数据库,以下是官方给出的建库命令:
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';
  1. 分别在两台HA 主机上启动rancher server
    Rancher HA1
sudo docker run -d --restart=unless-stopped --name RancherHA1 -p 8080:8080  -p 9345:9345 rancher/server:v1.6.21 --db-host <mysql_host_ip> --db-port <mysql_host_port> --db-user <mysql_user> --db-pass <mysql_password> --db-name <mysql_db_name> --advertise-address <Rancher_HA1_IP>

Rancher HA2

sudo docker run -d --restart=unless-stopped --name RancherHA2 -p 8080:8080  -p 9345:9345 rancher/server:v1.6.21 --db-host <mysql_host_ip> --db-port <mysql_host_port> --db-user <mysql_user> --db-pass <mysql_password> --db-name <mysql_db_name> --advertise-address <Rancher_HA2_IP>
  1. 访问8080端口即可以主机的rancher server ,9345端口是用来 rancher server 主机之间 进行通信

Haproxy 安装

  1. 进入Haproxy 主机中安装
sudo apt-get install haproxy
  1. 编写Haproxy配置文件:/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 http
  #bind *:443 ssl crt /etc/haproxy/certificate.pem
  bind *:8080
  default_backend rancher_servers
  # Add headers for SSL offloading
  http-request set-header X-Forwarded-Proto https if { ssl_fc }
  http-request set-header X-Forwarded-Ssl on if { ssl_fc }
  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 <rancher_server_HA1_IP>:8080 weight 1 maxconn 1024
  server websrv2 <rancher_server_HA2_IP>:8080 weight 1 maxconn 1024
  server websrv3 <rancher_server_HA3_IP>:8080 weight 1 maxconn 1024
  1. 启动 Haproxy
#启动HAProxy服务
haproxy -f /etc/haproxy/haproxy.cfg &

#查看8080端口是否已经在监听中
netstat -antlp |grep 8080

#通过HAProxy的IP:8080端口登录到RancherServer
http://<HAProxy_IP>:8080
上一篇 下一篇

猜你喜欢

热点阅读