# Consul Production 配置(docker run 版本) ###### tags: `consul`, `hashicorp` ## 目標 * 運作於 EC2 上 * 每台 VM 跑一個 Consul container * 可以單台運作,也可以多台組 cluster * VM 重開機會自動啟動 Consul container ## Steps ### 前置(每台 VM 都要做) ```bash mkdir -p $HOME/consul/config cat > $HOME/consul/config/consul.json <<EOF { "performance": { "raft_multiplier": 1 } } EOF docker volume create consul_data ``` * Consul config 根據 [Server Performance | Consul by HashiCorp](https://www.consul.io/docs/install/performance) 建議之設定 * 準備 volume 給 Consul container,不掛 host directory 是因為 Consul image 不是用 root 身份跑 entrypoint,掛 host directory 進去會有權限問題 ### 第一台 Consul container ```bash docker run -d --restart unless-stopped \ --name consul \ --net host \ -e CONSUL_BIND_INTERFACE='ens5' \ -v $HOME/consul/config:/consul/config \ -v consul_data:/consul/data \ consul:1.8.0 \ agent \ -server \ -ui \ -client='0.0.0.0' \ -bootstrap \ -node=$(hostname) ``` * `--restart unless-stopped` 讓 VM 重啟後 container 會自動被叫起來 * `--net host` 讓 Consul cluster 可以互 ping * `-e CONSUL_BIND_INTERFACE=` 必須給定 VM 的內網網卡 ### 第二 ~ 第 n 台 Consul container ```bash docker run -d --restart unless-stopped \ --name consul \ --net host \ -e CONSUL_BIND_INTERFACE='ens5' \ -v $HOME/consul/config:/consul/config \ -v consul_data:/consul/data \ consul:1.8.0 \ agent \ -server \ -ui \ --client='0.0.0.0' \ --join='172.31.11.26' \ -node=$(hostname) ``` * `--join=` 設為第一台 Consul 的 VM 內網 IP
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up