卸载命令
yum remove nomad consul -y
systemctl stop consul
rm -rf /etc/rsyslog.d/consul.conf
rm -rf /etc/logrotate.d/consul
rm -rf /var/log/consul.log
rm -rf /etc/consul.d
rm -rf /opt/consul
rm -rf /usr/bin/consul
systemctl daemon-reload
ps -ef |grep consul
userdel consul
consul members
systemctl stop nomad
rm -rf /etc/rsyslog.d/nomad.conf
rm -rf /etc/logrotate.d/nomad
rm -rf /var/log/nomad.log
rm -rf /etc/nomad.d
rm -rf /opt/nomad
rm -rf /usr/bin/nomad
systemctl daemon-reload
ps -ef |grep nomad |awk '{print $2}' |xargs kill
ps -ef |grep nomad
userdel nomad
部署
# 1.准备二进制
# mkdir /tmp/consul/ -p && cd /tmp/consul/
export CONSUL_VERSION="1.11.2"
export CONSUL_URL="https://releases.hashicorp.com/consul"
curl --remote-name \
${CONSUL_URL}/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip
unzip -d /usr/bin/ consul_${CONSUL_VERSION}_linux_amd64.zip
chown root:root /usr/bin/consul
# consul --version
# consul -autocomplete-install
# complete -C /usr/bin/consul consul
# 2.创建用户
useradd -r -d /etc/consul.d -s /bin/false consul
mkdir -p /opt/consul
chown -r consul:consul /opt/consul
mkdir /etc/consul.d/ -p
- name: 创建目录
file:
dest: /opt/consul
state=directory
recurse: yes # chown -r consul:consul /opt/consul
owner: "consul" # chown root:root consul
group: "consul"
# 3.准备配置文件
cat <<EOF > /etc/consul.d/consul.hcl
datacenter = "dc1" #运行代理的数据中心。
data_dir = "/opt/consul" #代理用于存储状态的数据目录
bind_addr = "10.102.193.227" #应绑定到的内部群集通信的地址。默认情况下,这是"0.0.0.0",这意味着 Consul 将绑定到本地计算机上的所有地址,可不指定,当服务器有多个网卡可能会报错
retry_join = ["10.102.193.227"] #启动时要加入的另一个代理的地址,可不指定 会自动发现
client_addr = "0.0.0.0" #Consul 将客户端接口绑定到的地址,包括 HTTP 和 DNS 服务器。默认情况下。默认情况下,它是"127.0.0.1",仅允许环回连接
server = true #此标志用于控制代理是否处于服务器或客户端模式
bootstrap_expect = 3 #此标志提供数据中心中预期服务器的数量。不应提供此值,或者该值应在数据中心的所有服务器上保持一致
ui_config { # 启动ui 默认情况下,UI 绑定到 client_addr ,不建议都启用ui
enabled = true
}
EOF
#
sudo chown --recursive consul:consul /etc/consul.d
sudo chmod 640 /etc/consul.d/consul.hcl
# 4.准备启动文件
cat <<EOF > /etc/systemd/system/consul.service
[Unit]
Description="HashiCorp Consul - A service mesh solution"
Documentation=https://www.consul.io/
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/consul.d/consul.hcl
[Service]
EnvironmentFile=-/etc/consul.d/consul.env
User=consul
Group=consul
ExecStart=/usr/bin/consul agent -config-dir=/etc/consul.d/
ExecReload=/bin/kill --signal HUP \$MAINPID
KillMode=process
KillSignal=SIGTERM
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
#检查您的配置文件是否有效 并启动
sudo consul validate /etc/consul.d/
sudo systemctl enable consul
sudo systemctl restart consul
sudo systemctl status consul
# 查看集群状态
consul members
nomad
# 1.准备二进制
# mkdir /tmp/nomad/ -p && cd /tmp/nomad/
export NOMAD_VERSION="1.2.6"
curl --remote-name https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip
# 安装 Nomad
unzip nomad_${NOMAD_VERSION}_linux_amd64.zip
sudo chown root:root nomad
sudo mv nomad /usr/bin/
nomad version
# nomad -autocomplete-install
# complete -C /usr/bin/nomad nomad
# 2.创建用户
useradd --system --home /etc/nomad.d --shell /bin/false nomad
# 3.创建目录
mkdir -p /etc/nomad.d /opt/nomad
chmod 700 /etc/nomad.d
cat <<EOF > /etc/nomad.d/nomad.hcl
datacenter = "dc1"
data_dir = "/opt/nomad"
bind_addr = "0.0.0.0"
EOF
sudo cat <<EOF > /etc/nomad.d/server.hcl
server {
enabled = true #指定此代理是否应在服务器模式下运行
bootstrap_expect = 3 #群集中预期的服务器数。
}
EOF
sudo cat <<EOF > /etc/nomad.d/client.hcl
client {
enabled = true # 指定此代理是否应在客户端模式下运行 主节点不指定 将没有工作节点功能
}
plugin "docker" {
config {
allow_privileged = true
}
}
EOF
sudo cat <<EOF > /etc/systemd/system/nomad.service
[Unit]
Description=Nomad
Documentation=https://www.nomadproject.io/docs/
Wants=network-online.target
After=network-online.target
[Service]
# nomad server 应以nomad用户身份运行。Nomad 客户端应以 root 用户身份运行。
User=root
Group=root
ExecReload=/bin/kill -HUP \$MAINPID
ExecStart=/usr/bin/nomad agent -config /etc/nomad.d
KillMode=process
KillSignal=SIGINT
LimitNOFILE=65536
LimitNPROC=infinity
Restart=on-failure
RestartSec=2
TasksMax=infinity
OOMScoreAdjust=-1000
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable nomad
sudo systemctl restart nomad
sudo systemctl status nomad
# 查看 server 和 node 节点
nomad server members
nomad node status