initial upload
This commit is contained in:
7
files/consul/configs/consul.hcl
Normal file
7
files/consul/configs/consul.hcl
Normal file
@@ -0,0 +1,7 @@
|
||||
datacenter = "MSI-DC"
|
||||
data_dir = "/opt/consul"
|
||||
encrypt = "eRhnp22+c0bkV0wPolk6Mw=="
|
||||
retry_join = ["consul-admin"]
|
||||
performance {
|
||||
raft_multiplier = 1
|
||||
}
|
||||
23
files/consul/configs/consul.service
Normal file
23
files/consul/configs/consul.service
Normal file
@@ -0,0 +1,23 @@
|
||||
[Unit]
|
||||
Description=Consul Service Discovery Agent
|
||||
Documentation=https://www.consul.io/
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=consul
|
||||
Group=consul
|
||||
ExecStart=/usr/local/bin/consul agent -server -ui \
|
||||
-data-dir=/opt/consul \
|
||||
-node=consul-%H \
|
||||
-config-dir=/etc/consul.d
|
||||
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillSignal=SIGINT
|
||||
TimeoutStopSec=5
|
||||
Restart=on-failure
|
||||
SyslogIdentifier=consul
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
4
files/consul/configs/server.hcl
Normal file
4
files/consul/configs/server.hcl
Normal file
@@ -0,0 +1,4 @@
|
||||
server = true
|
||||
bootstrap_expect = 2
|
||||
bind_addr = "10.11.10.101"
|
||||
ui = true
|
||||
10
files/consul/configs/service-apache.hcl
Normal file
10
files/consul/configs/service-apache.hcl
Normal file
@@ -0,0 +1,10 @@
|
||||
service {
|
||||
name = "apache"
|
||||
port = 443
|
||||
tags = [ "srv1", "pedimedic", "webmail", "git" ]
|
||||
check {
|
||||
http = "https://srv1.maruntiel.com"
|
||||
interval = "5s"
|
||||
tlsSkipVerify = true
|
||||
}
|
||||
}
|
||||
9
files/consul/configs/service-mysql.hcl
Normal file
9
files/consul/configs/service-mysql.hcl
Normal file
@@ -0,0 +1,9 @@
|
||||
service {
|
||||
name = "mariadb"
|
||||
port = 3306
|
||||
tags = [ "db" ]
|
||||
check {
|
||||
tcp = "localhost:3306"
|
||||
interval = "5s"
|
||||
}
|
||||
}
|
||||
8
files/consul/configs/service-ssh.hcl
Normal file
8
files/consul/configs/service-ssh.hcl
Normal file
@@ -0,0 +1,8 @@
|
||||
service {
|
||||
name = "SSHD"
|
||||
port = 22
|
||||
check {
|
||||
tcp = "localhost:22"
|
||||
interval = "5s"
|
||||
}
|
||||
}
|
||||
70
files/consul/consul-tag
Normal file
70
files/consul/consul-tag
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import requests
|
||||
|
||||
CONSUL_API = 'http://localhost:8500'
|
||||
|
||||
|
||||
def get_service(sess, service_id):
|
||||
r = sess.get(CONSUL_API + '/v1/agent/services', timeout=2)
|
||||
r.raise_for_status()
|
||||
services = r.json()
|
||||
|
||||
for svc in services.values():
|
||||
if svc['ID'] == service_id:
|
||||
return svc
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def change_service_tags(service, tags_to_add, tags_to_remove):
|
||||
with requests.Session() as sess:
|
||||
sess.headers = {'X-Consul-Token': os.getenv('CONSUL_HTTP_TOKEN')}
|
||||
|
||||
svc = get_service(sess, service)
|
||||
if svc:
|
||||
new_tags = (set(svc.get('Tags', [])) | tags_to_add) - tags_to_remove
|
||||
new_svc = {
|
||||
'ID': svc['ID'],
|
||||
'Name': svc['Service'],
|
||||
'Address': svc.get('Address', ''),
|
||||
'Port': svc.get('Port', 0),
|
||||
'Meta': svc.get('Meta', {}),
|
||||
'Tags': sorted(list(new_tags)),
|
||||
'EnableTagOverride': svc.get('EnableTagOverride', False),
|
||||
}
|
||||
for k, v in new_svc.items():
|
||||
print('{} = {}'.format(k, v))
|
||||
r = sess.put(CONSUL_API + '/v1/agent/service/register', json=new_svc, timeout=2)
|
||||
r.raise_for_status()
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) < 3:
|
||||
print("Usage: consul-tag service +tag -tag...")
|
||||
return 1
|
||||
|
||||
service = argv[1]
|
||||
tags_to_add = set()
|
||||
tags_to_remove = set()
|
||||
for tag in argv[2:]:
|
||||
if tag.startswith('-'):
|
||||
tags_to_remove.add(tag[1:])
|
||||
elif tag.startswith('+'):
|
||||
tags_to_add.add(tag[1:])
|
||||
else:
|
||||
tags_to_add.add(tag)
|
||||
|
||||
try:
|
||||
change_service_tags(service, tags_to_add, tags_to_remove)
|
||||
except Exception as exc:
|
||||
print("Error: {}".format(exc))
|
||||
return 2
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
BIN
files/consul/consul.1.7.4
Normal file
BIN
files/consul/consul.1.7.4
Normal file
Binary file not shown.
Reference in New Issue
Block a user