部署zookeeper集群
1、集群规划
主机名 角色 IPhdss7-11.host.com k8s代理节点1、zk1 10.4.7.11hdss7-12.host.com k8s代理节点2、zk2 10.4.7.12hdss7-21.host.com k8s运算节点1、zk3 10.4.7.21hdss7-22.host.com k8s运算节点2、jenkins 10.4.7.22hdss7-200.host.com k8s运维节点(docker仓库) 10.4.7.200
2、配置jdk
2.1 下载
下载地址(需要oracle账号)
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
2.2 安装jdk
以10.4.7.11部署为例,10.4.7.12/21类似
[root@hdss7-11 ~]# mkdir /opt/src[root@hdss7-11 ~]# mv jdk-8u301-linux-x64.tar.gz /opt/src/[root@hdss7-11 ~]# cd /opt/src/[root@hdss7-11 src]# tar -zxvf jdk-8u301-linux-x64.tar.gz -C /usr/local/[root@hdss7-11 src]# ln -s /usr/local/jdk1.8.0_301/ /usr/local/jdk
2.3 配置环境变量
[root@hdss7-11 src]# vim /etc/profile#jdk8export JAVA_HOME=/usr/local/jdk/export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport PATH=$JAVA_HOME/bin:$PATH[root@hdss7-11 src]# source /etc/profile[root@hdss7-11 src]# java -versionjava version "1.8.0_301"Java(TM) SE Runtime Environment (build 1.8.0_301-b09)Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)
3、配置域名解析
在域名服务器10.4.7.11上配置域名解析
[root@hdss7-11 src]# vim /var/named/od.com.zone$ORIGIN od.com.$TTL 600 ; 10 minutes@ IN SOA dns.od.com. dnsadmin.od.com. ( 2020010506 ; serial 10800 ; refresh (3 hours) 900 ; retry (15 minutes) 604800 ; expire (1 week) 86400 ; minimum (1 day) ) NS dns.od.com.$TTL 60 ; 1 minutedns A 10.4.7.11harbor A 10.4.7.200k8s-yaml A 10.4.7.200traefik A 10.4.7.10dashboard A 10.4.7.10zk1 A 10.4.7.11zk2 A 10.4.7.12zk3 A 10.4.7.21[root@hdss7-11 src]# systemctl restart named验证[root@hdss7-11 src]# dig -t A zk1.od.com @10.4.7.11 +short10.4.7.11
4、部署zookeeper集群
以10.4.7.11部署为例,10.4.7.12/21类似
4.1 下载解压
二进制下载地址:https://archive.apache.org/dist/zookeeper/
[root@hdss7-11 src]# wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz[root@hdss7-11 src]# tar -zxvf zookeeper-3.4.8.tar.gz -C /opt/[root@hdss7-11 src]# ln -s /opt/zookeeper-3.4.8/ /opt/zookeeper
4.2 创建数据、日志目录
[root@hdss7-11 src]# mkdir -p /data/zookeeper/{data,logs}
4.3 修改配置文件(各节点相同)
[root@hdss7-11 src]# vim /opt/zookeeper/conf/zoo.cfgtickTime=2000initLimit=10syncLimit=5dataDir=/data/zookeeper/dataclientPort=2181server.1=zk1.od.com:2888:3888server.2=zk2.od.com:2888:3888server.3=zk3.od.com:2888:3888
配置myid(各节点不同,分别是1/2/3)
[root@hdss7-11 src]# echo 1 > /data/zookeeper/data/myid
4.4 启动
[root@hdss7-11 src]# /opt/zookeeper/bin/zkServer.sh startZooKeeper JMX enabled by defaultUsing config: /opt/zookeeper/bin/../conf/zoo.cfgStarting zookeeper ... STARTED
4.5 查看集群状态
当至启东一个节点时,因为无法满足集群,所以会有以下报错,忽略
[root@hdss7-11 src]# /opt/zookeeper/bin/zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /opt/zookeeper/bin/../conf/zoo.cfgError contacting service. It is probably not running.
当启动第二个节点后满足集群要求,集群状态就正常了(而且第二个启动的一定是master),接着启动第三个节点就行
[root@hdss7-12 src]# /opt/zookeeper/bin/zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /opt/zookeeper/bin/../conf/zoo.cfgMode: leader[root@hdss7-11 src]# /opt/zookeeper/bin/zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /opt/zookeeper/bin/../conf/zoo.cfgMode: follower
4.6 设置zk开机自启
[root@hdss7-11 src]# vim /etc/rc.d/rc.localexport JAVA_HOME=/usr/local/jdk//opt/zookeeper/bin/zkServer.sh start