etcd集群部署

ansible自动部署:

相关安装包下载链接:

链接:https://pan.baidu.com/s/1DYU-JBod0HAAX5foyFs48w 
提取码:7571
## etcd-v3.4.13-linux-amd64.tar.gz

目录结构:

[root@localhost ansible]# tree etcd_install/
etcd_install/
├── conf
│   └── run.sh
├── etcd.yml
├── id_rsa
├── inv
├── README.TXT
└── run.sh

etcd.yml配置文件
- name: etcd集群安装
  hosts: all
  gather_facts: no
  remote_user: sa
  become_user: root
  serial: 3
  vars:
  tasks:
    - name: 下载安装包
      get_url:
        url: http://192.168.1.230/packages/etcd-v3.4.13-linux-amd64.tar.gz
        dest: /tmp/
        mode: 0644
        force: no
        checksum: md5:b4a093f33fb75e49f2b53f8062ead621
      become: yes
    - name: 解压安装包到
      unarchive:
        src: /tmp/etcd-v3.4.13-linux-amd64.tar.gz
        dest: /data/op/
        remote_src: yes
      args:
        creates: /data/op/etcd-v3.4.13-linux-amd64/etcdctl
      become: yes
    - name: 传输文件到 {{ addr_1 }}
      template:
        src: ./conf/run.sh
        dest: /data/op/etcd-v3.4.13-linux-amd64/
      vars:
        THIS_NAME: '${NAME_1}'
        THIS_IP: '${HOST_1}'
      when: inventory_hostname == (addr_1)
      become: yes
    - name: 传输文件到 {{ addr_2 }}
      template:
        src: ./conf/run.sh
        dest: /data/op/etcd-v3.4.13-linux-amd64/
      vars:
        THIS_NAME: '${NAME_2}'
        THIS_IP: '${HOST_2}'
      when: inventory_hostname == (addr_2) 
      become: yes
    - name: 传输文件到 {{ addr_3 }}
      template:
        src: ./conf/run.sh
        dest: /data/op/etcd-v3.4.13-linux-amd64/
      vars:
        THIS_NAME: '${NAME_3}'
        THIS_IP: '${HOST_3}'
      when: inventory_hostname == (addr_3)
      become: yes
    - name: 启动服务etcd
      shell: nohup sh ./run.sh > /dev/null 2>&1 &
      args:
        chdir: /data/op/etcd-v3.4.13-linux-amd64/
      become: yes

run.sh配置文件
cd `dirname $0`

IP=`awk 'BEGIN{ ORS="" }{a[NR]=$1}END{for(i=1;i<=NR;i++){print i%5?a[i]",":a[i]"\n"}}' inv`
addr_1=`awk 'NR == 1' inv | awk {'print $1'}`
addr_2=`awk 'NR == 2' inv | awk {'print $1'}`
addr_3=`awk 'NR == 3' inv | awk {'print $1'}`
HOSTNAME_1=`awk 'NR == 1' inv | awk {'print $2'}`
HOSTNAME_2=`awk 'NR == 2' inv | awk {'print $2'}`
HOSTNAME_3=`awk 'NR == 3' inv | awk {'print $2'}`

ansible_options="
    -e addr_1=$addr_1
    -e addr_2=$addr_2
    -e addr_3=$addr_3
    -e HOSTNAME_1=$HOSTNAME_1
    -e HOSTNAME_2=$HOSTNAME_2
    -e HOSTNAME_3=$HOSTNAME_3"
 
ansible-playbook -i ${IP} \
    $ansible_options \
    --key-file "./id_rsa"\
    etcd.yml $*


inv配置文件
10.10.80.176 k8s-slave2
10.10.80.177 k8s-slave1
10.10.80.178 k8s-master

id_rsa配置文件
三台服务器公用的私钥

conf目录:

run.sh配置文件
TOKEN=etcd_test
CLUSTER_STATE=new
DATA_DIR=/data/appdata/etcd/data.etcd
NAME_1={{ HOSTNAME_1 }}
NAME_2={{ HOSTNAME_2 }}
NAME_3={{ HOSTNAME_3 }}
HOST_1={{ addr_1 }}
HOST_2={{ addr_2 }}
HOST_3={{ addr_3 }}
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380
THIS_NAME={{ THIS_NAME }}
THIS_IP={{ THIS_IP }}
./etcd --data-dir=${DATA_DIR} --name ${THIS_NAME} \
        --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
        --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
        --initial-cluster ${CLUSTER} \
        --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
上一篇:U-Boot 常用命令介绍


下一篇:uboot模式下操作spi flash