421 lines
14 KiB
HCL
421 lines
14 KiB
HCL
job "consul-cluster-kv" {
|
|
datacenters = ["dc1"]
|
|
type = "service"
|
|
|
|
group "consul-master" {
|
|
count = 1
|
|
|
|
constraint {
|
|
attribute = "${node.unique.name}"
|
|
value = "kr-master"
|
|
}
|
|
|
|
network {
|
|
port "http" {
|
|
static = 8500
|
|
}
|
|
port "rpc" {
|
|
static = 8300
|
|
}
|
|
port "serf_lan" {
|
|
static = 8301
|
|
}
|
|
port "serf_wan" {
|
|
static = 8302
|
|
}
|
|
}
|
|
|
|
task "consul" {
|
|
driver = "exec"
|
|
|
|
# 使用模板从Consul KV获取配置
|
|
template {
|
|
data = <<EOF
|
|
# Consul配置文件 - 从KV存储动态获取
|
|
# 遵循 config/{environment}/{provider}/{region_or_service}/{key} 格式
|
|
|
|
# 基础配置
|
|
data_dir = "{{ keyOrDefault `config/dev/consul/cluster/data_dir` `/opt/consul/data` }}"
|
|
raft_dir = "{{ keyOrDefault `config/dev/consul/cluster/raft_dir` `/opt/consul/raft` }}"
|
|
|
|
# 启用UI
|
|
ui_config {
|
|
enabled = {{ keyOrDefault `config/dev/consul/ui/enabled` `true` }}
|
|
}
|
|
|
|
# 数据中心配置
|
|
datacenter = "{{ keyOrDefault `config/dev/consul/cluster/datacenter` `dc1` }}"
|
|
|
|
# 服务器配置
|
|
server = true
|
|
bootstrap_expect = {{ keyOrDefault `config/dev/consul/cluster/bootstrap_expect` `3` }}
|
|
|
|
# 网络配置
|
|
client_addr = "{{ keyOrDefault `config/dev/consul/nodes/master/hostname` `master` }}"
|
|
bind_addr = "{{ keyOrDefault `config/dev/consul/nodes/master/hostname` `master` }}"
|
|
advertise_addr = "{{ keyOrDefault `config/dev/consul/nodes/master/hostname` `master` }}"
|
|
|
|
# 端口配置
|
|
ports {
|
|
dns = {{ keyOrDefault `config/dev/consul/ports/dns` `8600` }}
|
|
http = {{ keyOrDefault `config/dev/consul/ports/http` `8500` }}
|
|
https = {{ keyOrDefault `config/dev/consul/ports/https` `-1` }}
|
|
grpc = {{ keyOrDefault `config/dev/consul/ports/grpc` `8502` }}
|
|
grpc_tls = {{ keyOrDefault `config/dev/consul/ports/grpc_tls` `8503` }}
|
|
serf_lan = {{ keyOrDefault `config/dev/consul/ports/serf_lan` `8301` }}
|
|
serf_wan = {{ keyOrDefault `config/dev/consul/ports/serf_wan` `8302` }}
|
|
server = {{ keyOrDefault `config/dev/consul/ports/server` `8300` }}
|
|
}
|
|
|
|
# 集群连接 - 从KV获取其他节点IP
|
|
retry_join = [
|
|
"{{ keyOrDefault `config/dev/consul/nodes/ash3c/hostname` `ash3c` }}",
|
|
"{{ keyOrDefault `config/dev/consul/nodes/warden/hostname` `warden` }}"
|
|
]
|
|
|
|
# 服务发现
|
|
enable_service_script = {{ keyOrDefault `config/dev/consul/service/enable_service_script` `true` }}
|
|
enable_script_checks = {{ keyOrDefault `config/dev/consul/service/enable_script_checks` `true` }}
|
|
enable_local_script_checks = {{ keyOrDefault `config/dev/consul/service/enable_local_script_checks` `true` }}
|
|
|
|
# 性能调优
|
|
performance {
|
|
raft_multiplier = {{ keyOrDefault `config/dev/consul/performance/raft_multiplier` `1` }}
|
|
}
|
|
|
|
# 日志配置
|
|
log_level = "{{ keyOrDefault `config/dev/consul/cluster/log_level` `INFO` }}"
|
|
enable_syslog = {{ keyOrDefault `config/dev/consul/log/enable_syslog` `false` }}
|
|
log_file = "{{ keyOrDefault `config/dev/consul/log/log_file` `/var/log/consul/consul.log` }}"
|
|
|
|
# 安全配置
|
|
encrypt = "{{ keyOrDefault `config/dev/consul/cluster/encrypt_key` `YourEncryptionKeyHere` }}"
|
|
|
|
# 连接配置
|
|
reconnect_timeout = "{{ keyOrDefault `config/dev/consul/connection/reconnect_timeout` `30s` }}"
|
|
reconnect_timeout_wan = "{{ keyOrDefault `config/dev/consul/connection/reconnect_timeout_wan` `30s` }}"
|
|
session_ttl_min = "{{ keyOrDefault `config/dev/consul/connection/session_ttl_min` `10s` }}"
|
|
|
|
# Autopilot配置
|
|
autopilot {
|
|
cleanup_dead_servers = {{ keyOrDefault `config/dev/consul/autopilot/cleanup_dead_servers` `true` }}
|
|
last_contact_threshold = "{{ keyOrDefault `config/dev/consul/autopilot/last_contact_threshold` `200ms` }}"
|
|
max_trailing_logs = {{ keyOrDefault `config/dev/consul/autopilot/max_trailing_logs` `250` }}
|
|
server_stabilization_time = "{{ keyOrDefault `config/dev/consul/autopilot/server_stabilization_time` `10s` }}
|
|
redundancy_zone_tag = ""
|
|
disable_upgrade_migration = {{ keyOrDefault `config/dev/consul/autopilot/disable_upgrade_migration` `false` }}
|
|
upgrade_version_tag = ""
|
|
}
|
|
|
|
# 快照配置
|
|
snapshot {
|
|
enabled = {{ keyOrDefault `config/dev/consul/snapshot/enabled` `true` }}
|
|
interval = "{{ keyOrDefault `config/dev/consul/snapshot/interval` `24h` }}"
|
|
retain = {{ keyOrDefault `config/dev/consul/snapshot/retain` `30` }}
|
|
name = "{{ keyOrDefault `config/dev/consul/snapshot/name` `consul-snapshot-{{.Timestamp}}` }}"
|
|
}
|
|
|
|
# 备份配置
|
|
backup {
|
|
enabled = {{ keyOrDefault `config/dev/consul/backup/enabled` `true` }}
|
|
interval = "{{ keyOrDefault `config/dev/consul/backup/interval` `6h` }}"
|
|
retain = {{ keyOrDefault `config/dev/consul/backup/retain` `7` }}
|
|
name = "{{ keyOrDefault `config/dev/consul/backup/name` `consul-backup-{{.Timestamp}}` }}"
|
|
}
|
|
EOF
|
|
destination = "local/consul.hcl"
|
|
}
|
|
|
|
config {
|
|
command = "consul"
|
|
args = [
|
|
"agent",
|
|
"-config-dir=local"
|
|
]
|
|
}
|
|
|
|
resources {
|
|
cpu = 300
|
|
memory = 512
|
|
}
|
|
}
|
|
}
|
|
|
|
group "consul-ash3c" {
|
|
count = 1
|
|
|
|
constraint {
|
|
attribute = "${node.unique.name}"
|
|
value = "us-ash3c"
|
|
}
|
|
|
|
network {
|
|
port "http" {
|
|
static = 8500
|
|
}
|
|
port "rpc" {
|
|
static = 8300
|
|
}
|
|
port "serf_lan" {
|
|
static = 8301
|
|
}
|
|
port "serf_wan" {
|
|
static = 8302
|
|
}
|
|
}
|
|
|
|
task "consul" {
|
|
driver = "exec"
|
|
|
|
# 使用模板从Consul KV获取配置
|
|
template {
|
|
data = <<EOF
|
|
# Consul配置文件 - 从KV存储动态获取
|
|
# 遵循 config/{environment}/{provider}/{region_or_service}/{key} 格式
|
|
|
|
# 基础配置
|
|
data_dir = "{{ keyOrDefault `config/dev/consul/cluster/data_dir` `/opt/consul/data` }}"
|
|
raft_dir = "{{ keyOrDefault `config/dev/consul/cluster/raft_dir` `/opt/consul/raft` }}"
|
|
|
|
# 启用UI
|
|
ui_config {
|
|
enabled = {{ keyOrDefault `config/dev/consul/ui/enabled` `true` }}
|
|
}
|
|
|
|
# 数据中心配置
|
|
datacenter = "{{ keyOrDefault `config/dev/consul/cluster/datacenter` `dc1` }}"
|
|
|
|
# 服务器配置
|
|
server = true
|
|
bootstrap_expect = {{ keyOrDefault `config/dev/consul/cluster/bootstrap_expect` `3` }}
|
|
|
|
# 网络配置
|
|
client_addr = "{{ keyOrDefault `config/dev/consul/nodes/ash3c/hostname` `ash3c` }}"
|
|
bind_addr = "{{ keyOrDefault `config/dev/consul/nodes/ash3c/hostname` `ash3c` }}"
|
|
advertise_addr = "{{ keyOrDefault `config/dev/consul/nodes/ash3c/hostname` `ash3c` }}"
|
|
|
|
# 端口配置
|
|
ports {
|
|
dns = {{ keyOrDefault `config/dev/consul/ports/dns` `8600` }}
|
|
http = {{ keyOrDefault `config/dev/consul/ports/http` `8500` }}
|
|
https = {{ keyOrDefault `config/dev/consul/ports/https` `-1` }}
|
|
grpc = {{ keyOrDefault `config/dev/consul/ports/grpc` `8502` }}
|
|
grpc_tls = {{ keyOrDefault `config/dev/consul/ports/grpc_tls` `8503` }}
|
|
serf_lan = {{ keyOrDefault `config/dev/consul/ports/serf_lan` `8301` }}
|
|
serf_wan = {{ keyOrDefault `config/dev/consul/ports/serf_wan` `8302` }}
|
|
server = {{ keyOrDefault `config/dev/consul/ports/server` `8300` }}
|
|
}
|
|
|
|
# 集群连接 - 从KV获取其他节点IP
|
|
retry_join = [
|
|
"{{ keyOrDefault `config/dev/consul/nodes/master/hostname` `master` }}",
|
|
"{{ keyOrDefault `config/dev/consul/nodes/warden/hostname` `warden` }}"
|
|
]
|
|
|
|
# 服务发现
|
|
enable_service_script = {{ keyOrDefault `config/dev/consul/service/enable_service_script` `true` }}
|
|
enable_script_checks = {{ keyOrDefault `config/dev/consul/service/enable_script_checks` `true` }}
|
|
enable_local_script_checks = {{ keyOrDefault `config/dev/consul/service/enable_local_script_checks` `true` }}
|
|
|
|
# 性能调优
|
|
performance {
|
|
raft_multiplier = {{ keyOrDefault `config/dev/consul/performance/raft_multiplier` `1` }}
|
|
}
|
|
|
|
# 日志配置
|
|
log_level = "{{ keyOrDefault `config/dev/consul/cluster/log_level` `INFO` }}"
|
|
enable_syslog = {{ keyOrDefault `config/dev/consul/log/enable_syslog` `false` }}
|
|
log_file = "{{ keyOrDefault `config/dev/consul/log/log_file` `/var/log/consul/consul.log` }}"
|
|
|
|
# 安全配置
|
|
encrypt = "{{ keyOrDefault `config/dev/consul/cluster/encrypt_key` `YourEncryptionKeyHere` }}"
|
|
|
|
# 连接配置
|
|
reconnect_timeout = "{{ keyOrDefault `config/dev/consul/connection/reconnect_timeout` `30s` }}"
|
|
reconnect_timeout_wan = "{{ keyOrDefault `config/dev/consul/connection/reconnect_timeout_wan` `30s` }}"
|
|
session_ttl_min = "{{ keyOrDefault `config/dev/consul/connection/session_ttl_min` `10s` }}"
|
|
|
|
# Autopilot配置
|
|
autopilot {
|
|
cleanup_dead_servers = {{ keyOrDefault `config/dev/consul/autopilot/cleanup_dead_servers` `true` }}
|
|
last_contact_threshold = "{{ keyOrDefault `config/dev/consul/autopilot/last_contact_threshold` `200ms` }}"
|
|
max_trailing_logs = {{ keyOrDefault `config/dev/consul/autopilot/max_trailing_logs` `250` }}
|
|
server_stabilization_time = "{{ keyOrDefault `config/dev/consul/autopilot/server_stabilization_time` `10s` }}"
|
|
redundancy_zone_tag = ""
|
|
disable_upgrade_migration = {{ keyOrDefault `config/dev/consul/autopilot/disable_upgrade_migration` `false` }}
|
|
upgrade_version_tag = ""
|
|
}
|
|
|
|
# 快照配置
|
|
snapshot {
|
|
enabled = {{ keyOrDefault `config/dev/consul/snapshot/enabled` `true` }}
|
|
interval = "{{ keyOrDefault `config/dev/consul/snapshot/interval` `24h` }}"
|
|
retain = {{ keyOrDefault `config/dev/consul/snapshot/retain` `30` }}
|
|
name = "{{ keyOrDefault `config/dev/consul/snapshot/name` `consul-snapshot-{{.Timestamp}}` }}"
|
|
}
|
|
|
|
# 备份配置
|
|
backup {
|
|
enabled = {{ keyOrDefault `config/dev/consul/backup/enabled` `true` }}
|
|
interval = "{{ keyOrDefault `config/dev/consul/backup/interval` `6h` }}"
|
|
retain = {{ keyOrDefault `config/dev/consul/backup/retain` `7` }}
|
|
name = "{{ keyOrDefault `config/dev/consul/backup/name` `consul-backup-{{.Timestamp}}` }}"
|
|
}
|
|
EOF
|
|
destination = "local/consul.hcl"
|
|
}
|
|
|
|
config {
|
|
command = "consul"
|
|
args = [
|
|
"agent",
|
|
"-config-dir=local"
|
|
]
|
|
}
|
|
|
|
resources {
|
|
cpu = 300
|
|
memory = 512
|
|
}
|
|
}
|
|
}
|
|
|
|
group "consul-warden" {
|
|
count = 1
|
|
|
|
constraint {
|
|
attribute = "${node.unique.name}"
|
|
value = "bj-warden"
|
|
}
|
|
|
|
network {
|
|
port "http" {
|
|
static = 8500
|
|
}
|
|
port "rpc" {
|
|
static = 8300
|
|
}
|
|
port "serf_lan" {
|
|
static = 8301
|
|
}
|
|
port "serf_wan" {
|
|
static = 8302
|
|
}
|
|
}
|
|
|
|
task "consul" {
|
|
driver = "exec"
|
|
|
|
# 使用模板从Consul KV获取配置
|
|
template {
|
|
data = <<EOF
|
|
# Consul配置文件 - 从KV存储动态获取
|
|
# 遵循 config/{environment}/{provider}/{region_or_service}/{key} 格式
|
|
|
|
# 基础配置
|
|
data_dir = "{{ keyOrDefault `config/dev/consul/cluster/data_dir` `/opt/consul/data` }}"
|
|
raft_dir = "{{ keyOrDefault `config/dev/consul/cluster/raft_dir` `/opt/consul/raft` }}"
|
|
|
|
# 启用UI
|
|
ui_config {
|
|
enabled = {{ keyOrDefault `config/dev/consul/ui/enabled` `true` }}
|
|
}
|
|
|
|
# 数据中心配置
|
|
datacenter = "{{ keyOrDefault `config/dev/consul/cluster/datacenter` `dc1` }}"
|
|
|
|
# 服务器配置
|
|
server = true
|
|
bootstrap_expect = {{ keyOrDefault `config/dev/consul/cluster/bootstrap_expect` `3` }}
|
|
|
|
# 网络配置
|
|
client_addr = "{{ keyOrDefault `config/dev/consul/nodes/warden/hostname` `warden` }}"
|
|
bind_addr = "{{ keyOrDefault `config/dev/consul/nodes/warden/hostname` `warden` }}"
|
|
advertise_addr = "{{ keyOrDefault `config/dev/consul/nodes/warden/hostname` `warden` }}"
|
|
|
|
# 端口配置
|
|
ports {
|
|
dns = {{ keyOrDefault `config/dev/consul/ports/dns` `8600` }}
|
|
http = {{ keyOrDefault `config/dev/consul/ports/http` `8500` }}
|
|
https = {{ keyOrDefault `config/dev/consul/ports/https` `-1` }}
|
|
grpc = {{ keyOrDefault `config/dev/consul/ports/grpc` `8502` }}
|
|
grpc_tls = {{ keyOrDefault `config/dev/consul/ports/grpc_tls` `8503` }}
|
|
serf_lan = {{ keyOrDefault `config/dev/consul/ports/serf_lan` `8301` }}
|
|
serf_wan = {{ keyOrDefault `config/dev/consul/ports/serf_wan` `8302` }}
|
|
server = {{ keyOrDefault `config/dev/consul/ports/server` `8300` }}
|
|
}
|
|
|
|
# 集群连接 - 从KV获取其他节点IP
|
|
retry_join = [
|
|
"{{ keyOrDefault `config/dev/consul/nodes/master/hostname` `master` }}",
|
|
"{{ keyOrDefault `config/dev/consul/nodes/ash3c/hostname` `ash3c` }}"
|
|
]
|
|
|
|
# 服务发现
|
|
enable_service_script = {{ keyOrDefault `config/dev/consul/service/enable_service_script` `true` }}
|
|
enable_script_checks = {{ keyOrDefault `config/dev/consul/service/enable_script_checks` `true` }}
|
|
enable_local_script_checks = {{ keyOrDefault `config/dev/consul/service/enable_local_script_checks` `true` }}
|
|
|
|
# 性能调优
|
|
performance {
|
|
raft_multiplier = {{ keyOrDefault `config/dev/consul/performance/raft_multiplier` `1` }}
|
|
}
|
|
|
|
# 日志配置
|
|
log_level = "{{ keyOrDefault `config/dev/consul/cluster/log_level` `INFO` }}"
|
|
enable_syslog = {{ keyOrDefault `config/dev/consul/log/enable_syslog` `false` }}
|
|
log_file = "{{ keyOrDefault `config/dev/consul/log/log_file` `/var/log/consul/consul.log` }}"
|
|
|
|
# 安全配置
|
|
encrypt = "{{ keyOrDefault `config/dev/consul/cluster/encrypt_key` `YourEncryptionKeyHere` }}"
|
|
|
|
# 连接配置
|
|
reconnect_timeout = "{{ keyOrDefault `config/dev/consul/connection/reconnect_timeout` `30s` }}"
|
|
reconnect_timeout_wan = "{{ keyOrDefault `config/dev/consul/connection/reconnect_timeout_wan` `30s` }}"
|
|
session_ttl_min = "{{ keyOrDefault `config/dev/consul/connection/session_ttl_min` `10s` }}"
|
|
|
|
# Autopilot配置
|
|
autopilot {
|
|
cleanup_dead_servers = {{ keyOrDefault `config/dev/consul/autopilot/cleanup_dead_servers` `true` }}
|
|
last_contact_threshold = "{{ keyOrDefault `config/dev/consul/autopilot/last_contact_threshold` `200ms` }}"
|
|
max_trailing_logs = {{ keyOrDefault `config/dev/consul/autopilot/max_trailing_logs` `250` }}
|
|
server_stabilization_time = "{{ keyOrDefault `config/dev/consul/autopilot/server_stabilization_time` `10s` }}
|
|
redundancy_zone_tag = ""
|
|
disable_upgrade_migration = {{ keyOrDefault `config/dev/consul/autopilot/disable_upgrade_migration` `false` }}
|
|
upgrade_version_tag = ""
|
|
}
|
|
|
|
# 快照配置
|
|
snapshot {
|
|
enabled = {{ keyOrDefault `config/dev/consul/snapshot/enabled` `true` }}
|
|
interval = "{{ keyOrDefault `config/dev/consul/snapshot/interval` `24h` }}"
|
|
retain = {{ keyOrDefault `config/dev/consul/snapshot/retain` `30` }}
|
|
name = "{{ keyOrDefault `config/dev/consul/snapshot/name` `consul-snapshot-{{.Timestamp}}` }}"
|
|
}
|
|
|
|
# 备份配置
|
|
backup {
|
|
enabled = {{ keyOrDefault `config/dev/consul/backup/enabled` `true` }}
|
|
interval = "{{ keyOrDefault `config/dev/consul/backup/interval` `6h` }}"
|
|
retain = {{ keyOrDefault `config/dev/consul/backup/retain` `7` }}
|
|
name = "{{ keyOrDefault `config/dev/consul/backup/name` `consul-backup-{{.Timestamp}}` }}"
|
|
}
|
|
EOF
|
|
destination = "local/consul.hcl"
|
|
}
|
|
|
|
config {
|
|
command = "consul"
|
|
args = [
|
|
"agent",
|
|
"-config-dir=local"
|
|
]
|
|
}
|
|
|
|
resources {
|
|
cpu = 300
|
|
memory = 512
|
|
}
|
|
}
|
|
}
|
|
} |