2022-07-12 19:23:38 +00:00
|
|
|
|
#### 安装
|
2022-06-14 13:23:25 +00:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 使用yum部署consul
|
|
|
|
|
yum install -y yum-utils
|
|
|
|
|
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
|
|
|
|
|
yum -y install consul
|
2022-11-14 21:10:50 +00:00
|
|
|
|
# 如果yum下载失败,可以直接下载RPM包安装
|
2022-11-14 21:09:16 +00:00
|
|
|
|
wget https://rpm.releases.hashicorp.com/RHEL/7/x86_64/stable/consul-1.13.3-1.x86_64.rpm
|
|
|
|
|
rpm -ivh ./consul-1.13.3-1.x86_64.rpm
|
2022-07-07 04:06:51 +00:00
|
|
|
|
```
|
2022-06-14 13:23:25 +00:00
|
|
|
|
|
2022-07-12 19:23:38 +00:00
|
|
|
|
#### 配置
|
2022-06-14 13:23:25 +00:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
vi /etc/consul.d/consul.hcl
|
2022-07-06 07:40:25 +00:00
|
|
|
|
log_level = "ERROR" #日志级别,日志太多可以只打印error日志,不需要可以去掉这行。
|
2022-07-12 19:23:38 +00:00
|
|
|
|
advertise_addr = "192.168.x.x" #填写你的网卡IP,如果启动或运行有报错,可以尝试去掉这行。
|
2022-06-14 13:23:25 +00:00
|
|
|
|
data_dir = "/opt/consul"
|
|
|
|
|
client_addr = "0.0.0.0"
|
|
|
|
|
ui_config{
|
|
|
|
|
enabled = true
|
|
|
|
|
}
|
|
|
|
|
server = true
|
|
|
|
|
bootstrap = true
|
|
|
|
|
acl = {
|
|
|
|
|
enabled = true
|
|
|
|
|
default_policy = "deny"
|
|
|
|
|
enable_token_persistence = true
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-07-12 19:23:38 +00:00
|
|
|
|
#### 启动服务
|
2022-06-14 13:23:25 +00:00
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
chown -R consul:consul /opt/consul #注意下数据目录的权限。
|
|
|
|
|
systemctl enable consul.service
|
|
|
|
|
systemctl start consul.service
|
2022-07-12 19:23:38 +00:00
|
|
|
|
```
|
2022-06-14 13:23:25 +00:00
|
|
|
|
|
2022-11-14 21:11:52 +00:00
|
|
|
|
### 安装后首次获取登录Token(记录SecretID,即为Consul登录的Token)
|
2022-07-12 19:23:38 +00:00
|
|
|
|
```bash
|
2022-11-14 21:11:52 +00:00
|
|
|
|
consul acl bootstrap|grep SecretID
|
2022-06-14 13:23:25 +00:00
|
|
|
|
```
|
2022-11-14 13:15:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 忘记global-management Token,重新生成
|
|
|
|
|
```
|
2022-11-14 18:55:28 +00:00
|
|
|
|
# 记录最后的reset index: xx
|
2022-11-14 13:15:24 +00:00
|
|
|
|
consul acl bootstrap
|
|
|
|
|
|
|
|
|
|
# 进入consul数据目录执行
|
|
|
|
|
echo 13 > acl-bootstrap-reset
|
|
|
|
|
|
|
|
|
|
# 重新创建一个global-management Token
|
|
|
|
|
consul acl bootstrap
|
|
|
|
|
```
|
2022-11-14 21:05:52 +00:00
|
|
|
|
|
|
|
|
|
### consul kv 备份还原
|
|
|
|
|
```
|
|
|
|
|
consul kv export --http-addr=http://127.0.0.1:8500 -token=admin-token '' > consul_kv_bak.json
|
|
|
|
|
consul kv import --http-addr=http://127.0.0.1:8500 -token=admin-token @consul_kv_bak.json
|
|
|
|
|
```
|