加载中...

第十五章 部署zookeeper集群

1、集群规划

主机名				角色				IP
hdss7-11.host.com		k8s代理节点1、zk1			10.4.7.11
hdss7-12.host.com		k8s代理节点2、zk2			10.4.7.12
hdss7-21.host.com		k8s运算节点1、zk3			10.4.7.21
hdss7-22.host.com		k8s运算节点2、jenkins             10.4.7.22
hdss7-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
#jdk8
export JAVA_HOME=/usr/local/jdk/
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
[root@hdss7-11 src]# source /etc/profile
[root@hdss7-11 src]# java -version
java 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 minute
dns                A    10.4.7.11
harbor             A    10.4.7.200
k8s-yaml           A    10.4.7.200
traefik            A    10.4.7.10
dashboard          A    10.4.7.10
zk1                A    10.4.7.11
zk2                A    10.4.7.12
zk3                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 +short
10.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.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/data
clientPort=2181
server.1=zk1.od.com:2888:3888
server.2=zk2.od.com:2888:3888
server.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 start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

4.5 查看集群状态

当至启东一个节点时,因为无法满足集群,所以会有以下报错,忽略

[root@hdss7-11 src]# /opt/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

当启动第二个节点后满足集群要求,集群状态就正常了(而且第二个启动的一定是master),接着启动第三个节点就行

[root@hdss7-12 src]# /opt/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@hdss7-11 src]# /opt/zookeeper/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Mode: follower

4.6 设置zk开机自启

[root@hdss7-11 src]# vim /etc/rc.d/rc.local
export JAVA_HOME=/usr/local/jdk/
/opt/zookeeper/bin/zkServer.sh start
posted @ 2021-08-10 22:08  沾沾自喜的混子  阅读(100)  评论(0编辑  收藏  举报