Induction of consul knowledge points
Consul_template: https://www.hi-linux.com/posts/36431.html
1. Download the installation package and extract the consul to get the consul binary file
Https://releases.hashicorp.com/consul/1.3.1/consul_1.3.1_linux_amd64.zip
Mkdir / application & & mv consul / application
2. Start consul_server with startup script
#! / bin/bashbin_path=/application/data_path= "$bin_path" / datanodename= `hostname`idc = dc1bindip= `/ sbin/ifconfig eth0 | grep'\ binet\ b' | sed-nr's # [^ 0-9] * ([0-9.] *). * #\ 1roomgp`bootstrap_expect=1 $bin_path/consul agent-server\-bind=$bindip\-ui\-client=0.0.0.0\ -bootstrap-expect=$bootstrap_expect\-data-dir $data_path\-node $nodename\-datacenter=$idc\-log-level=warn\-pid-file=$bin_path/consul.pid
3. Consul cooperates with consul_template to automatically modify prometheus configuration
Reference blog: https://www.hi-linux.com/posts/36431.html
1. Consul specifies to add a single key
. / consul kv put prometheus/kubernetes-apiserver/address 10.0.0.31
2. Consul specifies to get a single key
. / consul kv get prometheus/kubernetes-apiserver/address
3. Consul specifies to delete a single key
. / consul kv delete prometheus/kubernetes-apiserver/address
4. Consul_template installation
$wget https://releases.hashicorp.com/consul-template/0.18.3/consul-template_0.18.3_linux_amd64.zip$ unzip consul-template_0.18.3_linux_amd64.zip$ mv consul-template / usr/local/bin/
5. Prometheus configuration file to set the tcp port detection mechanism:
-job_name: "tcp_port_discorvery" scrape_interval: 5s metrics_path: / probe params: module: [tcp_connect] file_sd_configs:-files:-/ home/work/software/prometheus/tcp_port.json relabel_configs:-source_labels: [_ address__] target_label: _ param_target- source_labels: [_ param_target] target_label: instance- target_label : _ _ address__ replacement: xxx.xx.xx.xx:31659
Configure the consul_template template for configuration rendering
Vim / prometheus/template.json [{{range tree "prometheus/linux"}} {"targets": [{{.Value} "]," labels ": {" process_name ":" {{.key} "}}, {{end}} {" targets ": [" xxx.xx.xx.xx:80 "]," labels ": {" process_name ":" tengine "}}]
Vim / application/prometheus.opsconsul {address = "xxx.xx.xx.xx:8500"} template {source = "/ prometheus/template.json" destination = "/ home/work/software/prometheus/tcp_port.json" command = "curl-X POST http://127.0.0.1:9090/-/reload"}
The test template generation file saw that the content of the file was empty
Consul-template-consul-addr xxx.xxx.xx.xx:8500-template= "complate.json:result"-once-dry
Push the key to be obtained to register in consul
. / consul kv put prometheus/tcp_port/k8smaster-apiserver 1xx.xx.xx.xx:6443
Start consul-template after the test is correct
Consul-template-config "/ application/prometheus.ops" &
It can also be added to the systemctl service manager to set boot self-startup