1. 程式人生 > 其它 >關於精準測試左移設計方案的思考

關於精準測試左移設計方案的思考

1 指令碼啟動方式
建立/data目錄,關閉防火牆,selinux;上傳etcd軟體包​​etcd-v3.2.12-linux-amd64.tar.gz​​
解壓軟體包
# tar xf etcd-v3.2.12-linux-amd64.tar.gz -C /data/
# mv /data/etcd-v3.2.12-linux-amd64 /data/etcd-v3.2.12

配置​​etcd.sh​​啟動檔案
1)node1節點
[root@192-168-2-29 etcd-v3.2.12]# cat etcd.sh
# For each machine
TOKEN=my-etcd-token-1
CLUSTER_STATE=new
NAME_1=etcd_1
NAME_2=etcd_2
NAME_3=etcd_3
HOST_1=192.168.2.29
HOST_2=192.168.2.56
HOST_3=192.168.2.71
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

# For node 1
THIS_NAME=${NAME_1}
THIS_IP=${HOST_1}
/data/etcd-v3.2.12/etcd --data-dir=/data/etcd-v3.2.12/data.etcd --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,http://127.0.0.1:2379 \
--listen-client-urls http://${THIS_IP}:2379,http://127.0.0.1:2379 \
--initial-cluster ${CLUSTER} \
--initial-cluster-state ${CLUSTER_STATE} \
--initial-cluster-token ${TOKEN} > /data/etcd-v3.2.12/etcd.out 2>&1 &

2)node2節點

[root@192-168-2-56 etcd-v3.2.12]# cat etcd.sh
# For each machine
TOKEN=my-etcd-token-1
CLUSTER_STATE=new
NAME_1=etcd_1
NAME_2=etcd_2
NAME_3=etcd_3
HOST_1=192.168.2.29
HOST_2=192.168.2.56
HOST_3=192.168.2.71
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

# For node 2
THIS_NAME=${NAME_2}
THIS_IP=${HOST_2}
/data/etcd-v3.2.12/etcd --data-dir=/data/etcd-v3.2.12/data.etcd --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,http://127.0.0.1:2379 \
--listen-client-urls http://${THIS_IP}:2379,http://127.0.0.1:2379 \
--initial-cluster ${CLUSTER} \
--initial-cluster-state ${CLUSTER_STATE} \
--initial-cluster-token ${TOKEN} > /data/etcd-v3.2.12/etcd.out 2>&1 &

3)node3節點

[root@192-168-2-71 etcd-v3.2.12]# cat etcd.sh
# For each machine
TOKEN=my-etcd-token-1
CLUSTER_STATE=new
NAME_1=etcd_1
NAME_2=etcd_2
NAME_3=etcd_3
HOST_1=192.168.2.29
HOST_2=192.168.2.56
HOST_3=192.168.2.71
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

# For node 3
THIS_NAME=${NAME_3}
THIS_IP=${HOST_3}
/data/etcd-v3.2.12/etcd --data-dir=/data/etcd-v3.2.12/data.etcd --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,http://127.0.0.1:2379 \
--listen-client-urls http://${THIS_IP}:2379,http://127.0.0.1:2379 \
--initial-cluster ${CLUSTER} \
--initial-cluster-state ${CLUSTER_STATE} \
--initial-cluster-token ${TOKEN} > /data/etcd-v3.2.12/etcd.out 2>&1 &

給etcd.sh賦予執行許可權並啟動
# chmod +x /data/etcd-v3.2.12/etcd.sh
# /data/etcd-v3.2.12/etcd.sh

檢視cluster成員
[root@192-168-2-29 etcd-v3.2.12]# /data/etcd-v3.2.12/etcdctl member list
30c42f05af63bfb4: name=etcd_2 peerURLs=http://192.168.2.56:2380 clientURLs=http://127.0.0.1:2379,http://192.168.2.56:2379 isLeader=false
85c8cfeb60178e73: name=etcd_3 peerURLs=http://192.168.2.71:2380 clientURLs=http://127.0.0.1:2379,http://192.168.2.71:2379 isLeader=false
c497a3d3216ce778: name=etcd_1 peerURLs=http://192.168.2.29:2380 clientURLs=http://127.0.0.1:2379,http://192.168.2.29:2379 isLeader=true

檢視cluster健康狀態
方法①
[root@192-168-2-29 etcd-v3.2.12]# /data/etcd-v3.2.12/etcdctl cluster-health
member 30c42f05af63bfb4 is healthy: got healthy result from http://127.0.0.1:2379
member 85c8cfeb60178e73 is healthy: got healthy result from http://127.0.0.1:2379
member c497a3d3216ce778 is healthy: got healthy result from http://127.0.0.1:2379
cluster is healthy

方法②
[root@192-168-2-29 etcd-v3.2.12]# curl http://192.168.2.29:2379/health
{"health": "true"}[root@192-168-2-29 etcd-v3.2.12]# curl http://192.168.2.56:2379/health
{"health": "true"}[root@192-168-2-29 etcd-v3.2.12]# curl http://192.168.2.71:2379/health
{"health": "true"}[root@192-168-2-29 etcd-v3.2.12]#

2 systemd啟動方式
建立/data目錄,關閉防火牆,selinux;上傳etcd軟體包​​etcd-v3.2.12-linux-amd64.tar.gz​​
解壓軟體包
# tar xf etcd-v3.2.12-linux-amd64.tar.gz -C /data/
# mv /data/etcd-v3.2.12-linux-amd64 /data/etcd-v3.2.12

準備配置檔案存放目錄
# mkdir /etc/etcd

編寫配置檔案etcd.conf
1)node1節點
[root@192-168-2-29 ~]# cat /etc/etcd/etcd.conf
#[Member]
ETCD_NAME="etcd_1"
ETCD_DATA_DIR="/data/etcd-v3.2.12/data.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.2.29:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.2.29:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.2.29:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.2.29:2379"
ETCD_INITIAL_CLUSTER="etcd_1=http://192.168.2.29:2380,etcd_2=http://192.168.2.56:2380,etcd_3=http://192.168.2.71:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

2)node2節點

[root@192-168-2-56 ~]# cat /etc/etcd/etcd.conf
#[Member]
ETCD_NAME="etcd_2"
ETCD_DATA_DIR="/data/etcd-v3.2.12/data.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.2.56:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.2.56:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.2.56:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.2.56:2379"
ETCD_INITIAL_CLUSTER="etcd_1=http://192.168.2.29:2380,etcd_2=http://192.168.2.56:2380,etcd_3=http://192.168.2.71:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

3)node3節點

[root@192-168-2-71 ~]# cat /etc/etcd/etcd.conf
#[Member]
ETCD_NAME="etcd_3"
ETCD_DATA_DIR="/data/etcd-v3.2.12/data.etcd"
ETCD_LISTEN_PEER_URLS="http://192.168.2.71:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.2.71:2379"

#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.2.71:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.2.71:2379"
ETCD_INITIAL_CLUSTER="etcd_1=http://192.168.2.29:2380,etcd_2=http://192.168.2.56:2380,etcd_3=http://192.168.2.71:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

編寫systemd啟動檔案
# cat /usr/lib/systemd/system/etcd.service
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/data/etcd-v3.2.12/etcd \
--name=${ETCD_NAME} \
--data-dir=${ETCD_DATA_DIR} \
--listen-peer-urls=${ETCD_LISTEN_PEER_URLS} \
--listen-client-urls=${ETCD_LISTEN_CLIENT_URLS},http://127.0.0.1:2379 \
--advertise-client-urls=${ETCD_ADVERTISE_CLIENT_URLS},http://127.0.0.1:2379 \
--initial-advertise-peer-urls=${ETCD_INITIAL_ADVERTISE_PEER_URLS} \
--initial-cluster=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-token=${ETCD_INITIAL_CLUSTER} \
--initial-cluster-state=${ETCD_INITIAL_CLUSTER_STATE}

Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

過載服務配置檔案
# systemctl daemon-reload
1.
啟動服務etcd注意:這裡啟動需要三臺一起啟動,不然先啟動的會一直卡在那裡
[root@192-168-2-29 ~]# systemctl start etcd
[root@192-168-2-56 ~]# systemctl start etcd
[root@192-168-2-71 ~]# systemctl start etcd

檢視cluster成員
複製
[root@192-168-2-29 ~]# /data/etcd-v3.2.12/etcdctl member list
829071e6c4e48ea: name=etcd_2 peerURLs=http://192.168.2.56:2380 clientURLs=http://127.0.0.1:2379,http://192.168.2.56:2379 isLeader=false
79d3438e3a7d6f7e: name=etcd_3 peerURLs=http://192.168.2.71:2380 clientURLs=http://127.0.0.1:2379,http://192.168.2.71:2379 isLeader=false
fe64de8659b559f1: name=etcd_1 peerURLs=http://192.168.2.29:2380 clientURLs=http://127.0.0.1:2379,http://192.168.2.29:2379 isLeader=true

檢視cluster叢集狀態
[root@192-168-2-29 ~]# /data/etcd-v3.2.12/etcdctl cluster-health
member 829071e6c4e48ea is healthy: got healthy result from http://127.0.0.1:2379
member 79d3438e3a7d6f7e is healthy: got healthy result from http://127.0.0.1:2379
member fe64de8659b559f1 is healthy: got healthy result from http://127.0.0.1:2379
cluster is healthy
-----------------------------------