博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一键部署ETCD集群脚本
阅读量:5790 次
发布时间:2019-06-18

本文共 3445 字,大约阅读时间需要 11 分钟。

#!/bin/bashset -xset -e #更改这里的IP, 只支持部署3个节点etcd集群declare -A NODE_MAP=(["etcd0"]="192.168.0.153" ["etcd1"]="192.168.0.154" ["etcd2"]="192.168.0.164") etcddownload(){    ETCD_VER=v3.2.9    #指定要安装的版本号    DOWNLOAD_URL=https://github.com/coreos/etcd/releases/download    [ -f ${PWD}/temp-etcd/etcd ]  && return    curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o ${PWD}/etcd-${ETCD_VER}-linux-amd64.tar.gz    mkdir -p ${PWD}/temp-etcd && tar -zxf ${PWD}/etcd-${ETCD_VER}-linux-amd64.tar.gz -C ${PWD}/temp-etcd --strip-components=1} etcdconfig(){    local node_index=$1 cat <
${PWD}/${node_index}.confETCD_NAME=${node_index}ETCD_DATA_DIR="/var/lib/etcd"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://${NODE_MAP[${node_index}]}:2380"ETCD_LISTEN_PEER_URLS="http://${NODE_MAP[${node_index}]}:2380"ETCD_LISTEN_CLIENT_URLS="http://${NODE_MAP[${node_index}]}:2379,http://127.0.0.1:2379"ETCD_ADVERTISE_CLIENT_URLS="http://${NODE_MAP[${node_index}]}:2379"ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-378"ETCD_INITIAL_CLUSTER="etcd0=http://${NODE_MAP['etcd0']}:2380,etcd1=http://${NODE_MAP['etcd1']}:2380,etcd2=http://${NODE_MAP['etcd2']}:2380"ETCD_INITIAL_CLUSTER_STATE="new"# ETCD_DISCOVERY=""# ETCD_DISCOVERY_SRV=""# ETCD_DISCOVERY_FALLBACK="proxy"# ETCD_DISCOVERY_PROXY=""## ETCD_CA_FILE=""# ETCD_CERT_FILE=""# ETCD_KEY_FILE=""# ETCD_PEER_CA_FILE=""# ETCD_PEER_CERT_FILE=""# ETCD_PEER_KEY_FILE=""EOF} etcdgen_unit(){cat <
${PWD}/etcd.service[Unit]Description=Etcd ServerAfter=network.target [Service]Type=notifyWorkingDirectory=/var/lib/etcdEnvironmentFile=-/etc/etcd/10-etcd.confExecStart=/usr/bin/etcdRestart=alwaysRestartSec=8sLimitNOFILE=40000 [Install]WantedBy=multi-user.targetEOF} SSH_OPTS="-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=ERROR -C"etcdscp(){ local host="$1" local src=($2) local dst="$3" scp -r ${SSH_OPTS} ${src[*]} "${host}:${dst}"}etcdssh(){ local host="$1" shift ssh ${SSH_OPTS} -t "${host}" "$@" >/dev/null 2>&1}etcdssh_nowait(){ local host="$1" shift ssh ${SSH_OPTS} -t "${host}" "nohup $@" >/dev/null 2>&1 &} etcddeploy(){ for key in ${!NODE_MAP[@]} do etcdconfig $key etcdssh "root@${NODE_MAP[$key]}" "mkdir -p /var/lib/etcd /etc/etcd" etcdscp "root@${NODE_MAP[$key]}" "${key}.conf" "/etc/etcd/10-etcd.conf" etcdscp "root@${NODE_MAP[$key]}" "etcd.service" "/usr/lib/systemd/system" etcdscp "root@${NODE_MAP[$key]}" "${PWD}/temp-etcd/etcd ${PWD}/temp-etcd/etcd" "/usr/bin" etcdscp "root@${NODE_MAP[$key]}" "${PWD}/temp-etcd/etcd ${PWD}/temp-etcd/etcdctl" "/usr/bin" etcdssh "root@${NODE_MAP[$key]}" "chmod 755 /usr/bin/etcd*" etcdssh_nowait "root@${NODE_MAP[$key]}" "systemctl daemon-reload && systemctl enable etcd && nohup systemctl start etcd" done } etcdclean(){ for key in ${!NODE_MAP[@]} do rm -f ${PWD}/${key}.conf done rm -f ${PWD}/etcd.service} #etcddownloadetcdgen_unitetcddeployetcdclean echo -e "\033[32m 部署完毕! 执行 etcdctl cluster-health,检测是否OK。\033[0m"

 

1、准备三台机器,系统为centos7

yum install -y epel-release vim bash-c* net-tools lrzsz

2、关闭防火墙和selinux

# systemctl stop firewalld && systemctl disable firewalld# vim /etc/selinux/configSELINUX=disabled# setenforce 0

3、校对时间

yum install -y ntp ntpdate && ntpdate pool.ntp.org

4、设置ssh互信

5、执行脚本即可。

# bash deploy-etcd.sh 原地址:http://www.cnblogs.com/keithtt/p/6649951.html

转载于:https://www.cnblogs.com/Tempted/p/7690691.html

你可能感兴趣的文章
VC中实现文字竖排的简单方法
查看>>
会话标识未更新
查看>>
阿里架构师:程序员必须掌握的几项核心技术能力
查看>>
程序员常用的六大技术博客类
查看>>
Iceworks 2.8.0 发布,自定义你的 React 模板
查看>>
胖哥学SpringMVC:请求方式转换过滤器配置
查看>>
Kotlin 更加优雅的 Builder - 理解 with
查看>>
前端日拱一卒D6——字符编码与浏览器解析
查看>>
深入理解浏览器的缓存机制
查看>>
微软向Linux社区开放60000多项专利:对开源微软是认真的
查看>>
Hoshin Kanri在丰田的应用
查看>>
又拍云沈志华:如何打造一款安全的App
查看>>
克服大数据集群的挑战
查看>>
PostgreSQL并发控制(MVCC, 事务,事务隔离级别)
查看>>
DM***的第二阶段OSPF
查看>>
20180702搭建青岛RAC记录
查看>>
Spring Security OAuth 实现OAuth 2.0 授权
查看>>
linux文件及简单命令学习
查看>>
dubbo源码分析-架构
查看>>
新 Terraform 提供商: Oracle OCI, Brightbox, RightScale
查看>>