Skip to content

Consul 0.7.2 on ubuntu 14.04

Published: at 00:00
说明
Cousul 集群在Ubuntu环境上的部署
本份文档是当时基于旧的0.7.2的版本进行记录的
环境介绍
consul-server-1: 10.211.55.56
consul-server-2: 10.211.55.57
consul-server-3: 10.211.55.58
consul-client-1: 10.211.55.59
安装openssh
apt-get install openssh-server
上传公钥
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
修改主机名
sudo vim /etc/hostname
sudo vim /etc/hosts
sudo reboot
登录更新源&自行更改主机名
sudo wget -O /etc/apt/sources.list http://mirrors.163.com/.help/sources.list.trusty
sudo apt-get update
安装
sudo apt-get install unzip -y
wget https://releases.hashicorp.com/consul/0.7.2/consul_0.7.2_linux_amd64.zip
unzip consul_0.7.2_linux_amd64.zip
sudo cp ./consul /usr/local/bin/
生成key
consul keygen
配置 bootstrap
sudo mkdir -p /etc/consul.d/bootstrap
sudo mkdir -p /data/consul
sudo vim /etc/consul.d/bootstrap/config.json

{
    "bootstrap": true,
    "node_name": "consul-bootstrap",
    "client_addr": "0.0.0.0",
    "server": true,
    "datacenter": "dc1",
    "data_dir": "/data/consul",
    "encrypt": "AUBQHT4nvRvrYXGAS79Suw==",
    "log_level": "INFO",
    "enable_syslog": true
}
配置 server
sudo mkdir -p /etc/consul.d/server
sudo mkdir -p /data/consul
sudo vim /etc/consul.d/server/config.json

start_join 加入其它两台的server
{
    "bootstrap": false,
    "server": true,
    "datacenter": "dc1",
    "node_name": "consul-server-2",
    "client_addr": "0.0.0.0",
    "data_dir": "/data/consul",
    "encrypt": "AUBQHT4nvRvrYXGAS79Suw==",
    "log_level": "INFO",
    "enable_syslog": true,
    "start_join": ["10.211.55.56", "10.211.55.58"]

}

配置 client
sudo mkdir -p /etc/consul.d/client
sudo mkdir -p /data/consul

其中 ui 在client节点安装
sudo mkdir -p /data/consul-ui
cd /data/consul-ui
sudo wget https://releases.hashicorp.com/consul/0.7.2/consul_0.7.2_web_ui.zip
sudo unzip ./consul_0.7.2_web_ui.zip

sudo vim /etc/consul.d/client/config.json
{
    "server": false,
    "datacenter": "dc1",
    "node_name": "consul-client-1",
    "client_addr": "0.0.0.0",
    "data_dir": "/data/consul",
    "ui_dir": "/data/consul-ui",
    "encrypt": "AUBQHT4nvRvrYXGAS79Suw==",
    "log_level": "INFO",
    "enable_syslog": true,
    "start_join": ["10.211.55.56", "10.211.55.57", "10.211.55.58"]
}
启动
1、bootstrap
sudo consul agent -config-dir /etc/consul.d/bootstrap
sudo nohup consul agent -config-dir /etc/consul.d/bootstrap &

2、server
sudo consul agent -config-dir /etc/consul.d/server
sudo nohup consul agent -config-dir /etc/consul.d/server &

3、client
sudo consul agent -config-dir /etc/consul.d/client
sudo nohup consul agent -config-dir /etc/consul.d/client &
查看members
consul members
ui
just 访问 http://10.211.55.59:8500