docker-compose部署consul
at 2年前 ca 注册发现 pv 442 by touch
安装前的准备
如果本机是首次使用docker-compose环境部署,需要在在/deploy/sorts创建以下脚本
vim pre_install.sh #!/bin/bash ###关闭selinux sed -i 's/SELINUXTYPE=targeted/SELINUXTYPE=disabled/g' /etc/selinux/config setenforce 0 ###卸载旧版本docker,安装docker-ce #yum remove docker \ # docker-client \ # docker-client-latest \ # docker-common \ # docker-latest \ # docker-latest-logrotate \ # docker-logrotate \ # docker-engine yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum makecache fast yum -y install docker-ce ###配置拉取国内镜像仓库 tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": [ "https://5sr5uink.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn", "https://hub-mirror.c.163.com", "https://mirror.baidubce.com" ], "insecure-registries": ["harbor.xxx.com"] } EOF ###启动docker systemctl start docker systemctl enable docker ###配置阿里云epel 源 cd /etc/yum.repo.d mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo ###安装docker-compose yum -y install epel-release yum install -y docker-compose docker-compose -version
创建目录
mkdir -p /deploy/sorts/consul
创建子目录
cd /deploy/sorts/consul mkdir conf data log
编辑docker-compose.yml文件
version: '3.1' services: consul: image: consul volumes: - ./data:/consul/data ##保存数据目录 - ./conf:/consul/config ##保存配置目录 - ./log:/var/log/consul ##保存日志目录 ports: - 8300:8300 - 8301:8301 - 8301:8301/udp - 8302:8302 - 8302:8302/udp - 8400:8400 - 8500:8500 - 53:53/udp network_mode: "host" command: agent -server -bind=10.10.10.203 -client=0.0.0.0 -node=consul -bootstrap-expect=1 -ui -log-file=/var/log/consul ##绑定地址需要改成安装主机的IP
配置文件
{ "node_name": "consul-server1", "server": true, "ui_config": { "enabled": true }, "data_dir": "/consul/data", "addresses": { "http": "0.0.0.0" }, "retry_join": ["consul-server2", "consul-server3"], "encrypt": "aPuGh+5UDskRAbkLaXRzFoSOcSM+5vAK+NEYOWHJH7w=", "verify_incoming": true, "verify_outgoing": true, "verify_server_hostname": true, "ca_file": "/consul/config/certs/consul-agent-ca.pem", "cert_file": "/consul/config/certs/dc1-server-consul-0.pem", "key_file": "/consul/config/certs/dc1-server-consul-0-key.pem" }
编辑启动和停止脚本
启动脚本
vim up.sh #!/bin/bash set -e tm=`date +%Y%m%d-%H%M%S` echo "=====================================================" echo "Starting consul." echo "Starting <${tm}>." echo "=====================================================" echo "Please ensure the config files right." echo "=====================================================" docker-compose -p consul up -d
停止脚本
vim down.sh #!/bin/bash set -e tm=`date +%Y%m%d-%H%M%S` echo "=====================================================" echo "Starting consul." echo "Starting <${tm}>." echo "=====================================================" echo "Please ensure the config files right." echo "=====================================================" docker-compose -p consul down
启动和查看状态
up表示已经启动
sh up.sh [root@test_docker_compose_10 consul]# docker-compose ps Name Command State Ports ---------------------------------------------------------------- consul_consul_1 docker-entrypoint.sh agent ... Up
查看日志
docker-compose logs consul
访问:192.168.238.100:8500
版权声明
本文仅代表作者观点,不代表码农殇立场。
本文系作者授权码农殇发表,未经许可,不得转载。
已有0条评论