Zookeeper cluster construction
- 1. Centos virtual machine configuration
-
- 1. Create a new virtual machine and select [Typical]
- 2. Next step, [Install the operating system later]
- 3. Next, select [Linux] [Centos7 64-bit]
- 4. Next, set the virtual machine name and installation directory
- 5. Next step, default
- 6. In the next step, [Custom Hardware Configuration] select the downloaded image
- 7. Complete, start the virtual machine
- 8. Log in and bind the network card to set the address
- 2. Zookeeper configuration
1. Centos virtual machine configuration
Install Centos 7 on VmWare
1. Create a new virtual machine and select [Typical]
2. Next step, [Install the operating system later]
3. Next, select [Linux] [Centos7 64-bit]
4. Next, set the virtual machine name and installation directory
5. Next step, default
6. In the next step, [Custom Hardware Configuration] select the downloaded image
7. Complete, start the virtual machine
automatic partition
start installation
Set username and password
restart the system
8. Log in and bind the network card to set the address
## 修改网卡配置
vi /etc/sysconfig/network-scripts/ifcfg-ens33
## 增加以下配置
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT=yes
## 删除 dhcp : BOOTPROTO=dhcp 并重启系统
2. Zookeeper configuration
1. Download Zookeeper
2. Stand-alone configuration
## 1.解压缩 zookeeper
tar zxvf apache-zookeeper-3.8.2-bin.tar.gz
## 2.移动位置
mv apache-zookeeper-3.8.2-bin /usr/local/zookeeper
## 3.解压缩 jdk
tar zxvf jdk-11.0.19_linux-x64_bin.tar.gz
## 4.移动位置
mv jdk-11.0.19 /usr/local/java
## 5.配置环境变量
echo 'export JAVA_HOME=/usr/local/java' >> /etc/profile
echo 'export ZOOKEEPER_HOME=/usr/local/zookeeper' >> /etc/profile
echo 'export PATH=${JAVA_HOME}/bin:${ZOOKEEPER_HOME}/bin:${PATH}' >> /etc/profile
## 6.刷新环境变量
source /etc/profile
## 7.复制配置
cp $ZOOKEEPER_HOME/conf/zoo_sample.cfg $ZOOKEEPER_HOME/conf/zoo.cfg
## 8.单机启动
zkServer.sh start
## 1.停止服务
zkServer.sh stop
3. Cluster configuration
The address assignment is as follows:
node | address | Host |
---|---|---|
host | 192.168.1.100 | zk1 |
from | 192.168.1.101 | zk2 |
from | 192.168.1.102 | zk3 |
zoo.cfg configuration instructions
configuration item | Defaults | meaning |
---|---|---|
tickTime | 2000 | communication heartbeat |
initLimit | 10 | Leader and Follower initialize to tolerate the most heartbeat book |
syncLimit | 5 | Leader and Follower synchronization timeout, if the heartbeat exceeds this number, Follower will be removed |
dataDir | /tmp/zookeeper | data directory |
clientPort | 2181 | client port |
server.A=B:C:D | A Server serial number B Local machine address C Leader and Follower communication port D Election communication port |
## 分别设置集群内虚拟机域名(查看域名:hostname)
hostnamectl set-hostname zk1
hostnamectl set-hostname zk2
hostnamectl set-hostname zk3
## 分别设置集群内虚拟机域名解析
echo '192.168.1.100 zk1' >> /etc/hosts
echo '192.168.1.101 zk2' >> /etc/hosts
echo '192.168.1.102 zk3' >> /etc/hosts
## 创建数据目录并修改 zoo.cfe 配置的 dataDir 为新创建目录
mkdir -p $ZOOKEEPER_HOME/data
## 创建文件 myid 用于标识服务器序号
touch $ZOOKEEPER_HOME/data/myid
## 修改 zoo.cfg 配置,增加集群配置
echo 'server.1=zk1:3188:3288' >> $ZOOKEEPER_HOME/conf/zoo.cfg
echo 'server.2=zk2:3188:3288' >> $ZOOKEEPER_HOME/conf/zoo.cfg
echo 'server.3=zk3:3188:3288' >> $ZOOKEEPER_HOME/conf/zoo.cfg
## 分发当前配置和文件到 zk2 zk3
scp -r /usr/local/zookeeper root@zk2:/usr/local/
scp -r /usr/local/zookeeper root@zk3:/usr/local/
scp -r /usr/local/java root@zk2:/usr/local/
scp -r /usr/local/java root@zk3:/usr/local/
scp /etc/profile root@zk2:/etc/profile
scp /etc/profile root@zk3:/etc/profile
## 刷新 zk2 zk3 环境变量并分别设置服务 ID
source /etc/profile
echo 1 >> $ZOOKEEPER_HOME/data/myid
echo 2 >> $ZOOKEEPER_HOME/data/myid
echo 3 >> $ZOOKEEPER_HOME/data/myid
Configure password-free login
## 修改 192.168.1.100 服务器
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
ssh-copy-id -i ~/.ssh/id_rsa root@zk2
ssh-copy-id -i ~/.ssh/id_rsa root@zk3
## 修改 192.168.1.101 服务器
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
ssh-copy-id -i ~/.ssh/id_rsa root@zk1
ssh-copy-id -i ~/.ssh/id_rsa root@zk3
## 修改 192.168.1.102 服务器
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
ssh-copy-id -i ~/.ssh/id_rsa root@zk1
ssh-copy-id -i ~/.ssh/id_rsa root@zk2
## 分别配置本地登录
ssh-copy-id -i ~/.ssh/id_rsa root@localhost
## 1.关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
## 2.分别启动集群内 zookeeper 服务
zkServer.sh start && ssh root@zk2 "source /etc/profile && zkServer.sh start && exit" && ssh root@zk3 "source /etc/profile && zkServer.sh start && exit"
## 3.查看状态
zkServer.sh status
## 4.关闭
zkServer.sh stop && ssh root@zk2 "source /etc/profile && zkServer.sh stop && exit" && ssh root@zk3 "source /etc/profile && zkServer.sh stop && exit"
ZK1
ZK2
ZK3
stop