zookeeper-ha
Host name | IP address |
---|---|
spark01 | 192.168.171.101 |
spark02 | 192.168.171.102 |
spark03 | 192.168.171.103 |
1. Upgrade kernel and software
yum -y update
2. Install commonly used software
yum -y install gcc gcc-c + + autoconf automake cmake make \ zlib zlib-devel openssl openssl-devel pcre-devel \ rsync openssh-server vim man zip unzip net-tools tcpdump lrzsz tar wget
3. Turn off the firewall
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 systemctl stop firewalld systemctl disable firewalld
4. Modify host name
hostnamectl set-hostname spark01
hostnamectl set-hostname spark02
hostnamectl set-hostname spark03
5. Modify IP address
vim /etc/sysconfig/network-scripts/ifcfg-ens32
Reference is as follows:
TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="none" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens32" DEVICE="ens32" ONBOOT="yes" IPADDR="192.168.171.101" PREFIX="24" GATEWAY="192.168.171.2" DNS1="192.168.171.2" IPV6_PRIVACY="no"
6. Modify hosts configuration file
vim /etc/hosts
The modifications are as follows:
192.168.171.101 spark01 192.168.171.102 spark02 192.168.171.103 spark03
7. Restart the system
reboot
8. Download and install JDK and Zookeeper and configure environment variables
Create software directories on all host nodes
mkdir -p /opt/soft
The following operations are completed on the spark01 host
Enter the software directory
cd /opt/soft
Download JDK
wget https://download.oracle.com/otn/java/jdk/8u391-b13/b291ca3e0c8548b5a51d5a5f50063037/jdk-8u391-linux-x64.tar.gz?AuthParam=1698206552_11c0bb831efdf87adfd187b 0e4ccf970
Download ZooKeeper
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.8.3/apache-zookeeper-3.8.3-bin.tar.gz
Unzip JDK and change the name
Unzip zookeeper and change the name
tar -zxvf jdk-8u391-linux-x64.tar.gz mv jdk1.8.0_391 jdk-8 tar -zxvf apache-zookeeper-3.8.3-bin.tar.gz mv apache-zookeeper-3.8.3-bin zookeeper-3
Configure environment variables
vim /etc/profile.d/my_env.sh
Write the following:
export JAVA_HOME=/opt/soft/jdk-8 export set JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED" export ZOOKEEPER_HOME=/opt/soft/zookeeper-3 export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
Make environment variables effective on each server
source /etc/profile
10. Edit configuration file
cd $ZOOKEEPER_HOME/conf
vim zoo.cfg
# Heartbeat unit, 2s tickTime=2000 # Zookeeper-3 initialization synchronization timeout, 10 heartbeat units, that is, 20s initLimit=10 # Ordinary synchronization: timeout for sending a request and getting a response, 5 heartbeat units, which is 10s syncLimit=5 # Storage location of memory snapshot data dataDir=/home/zookeeper-3/data #Transaction log storage location dataLogDir=/home/zookeeper-3/datalog # Port of the current zookeeper-3 node clientPort=2181 # The number of concurrent connections from a single client to a single node in the cluster. Determine whether it is the same client through IP. The default is 60 maxClientCnxns=1000 # Keep 7 memory snapshot files in dataDir, 3 by default autopurge.snapRetainCount=7 # Clear the scheduled task of the snapshot, the default is 1 hour, if set to 0, it indicates that the clearing task is closed autopurge.purgeInterval=1 #The minimum timeout allowed for client connection settings, the default is 2 heartbeat units minSessionTimeout=4000 #The maximum timeout time allowed for client connection settings. The default is 20 heartbeat units, which is 40s. maxSessionTimeout=300000 #zookeeper-3 3.5.5 will start the AdminService service by default. This service defaults to port 8080. admin.serverPort=9001 #Cluster address configuration server.1=spark01:2888:3888 server.2=spark02:2888:3888 server.3=spark03:2888:3888
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/home/zookeeper-3/data dataLogDir=/home/zookeeper-3/datalog clientPort=2181 maxClientCnxns=1000 autopurge.snapRetainCount=7 autopurge.purgeInterval=1 minSessionTimeout=4000 maxSessionTimeout=300000 admin.serverPort=9001 server.1=spark01:2888:3888 server.2=spark02:2888:3888 server.3=spark03:2888:3888
11. Create a directory based on the configuration file after saving
Execute on each server
mkdir -p /home/zookeeper-3/data mkdir -p /home/zookeeper-3/datalog
12. Write zookeeper-3 startup script
Create a startup script zookeeper-3.service in the /etc/systemd/system/ folder
NOTE: Write on each server
cd /etc/systemd/system vim zookeeper.service
The content is as follows:
[Unit] Description=zookeeper After=syslog.target network.target [Service] Type=forking # Specify the zookeeper-3 log file path, which can also be defined in zkServer.sh Environment=ZOO_LOG_DIR=/home/zookeeper-3/datalog # Specify the JDK path, which can also be defined in zkServer.sh Environment=JAVA_HOME=/opt/soft/jdk-8 ExecStart=/opt/soft/zookeeper-3/bin/zkServer.sh start ExecStop=/opt/soft/zookeeper-3/bin/zkServer.sh stop Restart=always User=root Group=root [Install] WantedBy=multi-user.target
[Unit] Description=zookeeper After=syslog.target network.target [Service] Type=forking Environment=ZOO_LOG_DIR=/home/zookeeper-3/datalog Environment=JAVA_HOME=/opt/soft/jdk-8 ExecStart=/opt/soft/zookeeper-3/bin/zkServer.sh start ExecStop=/opt/soft/zookeeper-3/bin/zkServer.sh stop Restart=always User=root Group=root [Install] WantedBy=multi-user.target
systemctl daemon-reload # Wait until all hosts are configured before executing the following command systemctl start zookeeper systemctl enable zookeeper systemctl status zookeeper
13. Configure ssh key-free login
Create a local key and write the public key to the authentication file
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
ssh-copy-id root@spark01
ssh-copy-id root@spark02
ssh-copy-id root@spark03
ssh root@spark01 exit
ssh root@spark02 exit
ssh root@spark03 exit
14. Distributing software and configuration files
Distribute ssh keyless
scp -r ~/.ssh root@spark02:~/ scp -r ~/.ssh root@spark03:~/
Distribute hosts file
scp -r /etc/hosts root@spark02:/etc/ scp -r /etc/hosts root@spark03:/etc/
Distribute software
scp -r /opt/soft/jdk-8 root@spark02:/opt/soft scp -r /opt/soft/zookeeper-3 root@spark02:/opt/soft scp -r /opt/soft/jdk-8 root@spark03:/opt/soft scp -r /opt/soft/zookeeper-3 root@spark03:/opt/soft
Distribute environment variables
scp /etc/profile.d/my_env.sh root@spark02:/etc/profile.d/ scp /etc/profile.d/my_env.sh root@spark03:/etc/profile.d/
Make the new environment variables take effect on all host nodes
source /etc/profile
15.myid
spark01
echo 1 >/home/zookeeper-3/data/myid more /home/zookeeper-3/data/myid
spark02
echo 2 > /home/zookeeper-3/data/myid more /home/zookeeper-3/data/myid
spark03
echo 3 > /home/zookeeper-3/data/myid more /home/zookeeper-3/data/myid
16. Start service
Execute the following commands on each node
systemctl daemon-reload systemctl start zookeeper systemctl enable zookeeper systemctl status zookeeper
17. Verification
jps
zkServer.sh status