Centos 7 阿里云服务器搭建 Zookeeper 配置集群
环境:Cenots 7
软件版本:Zookeeper 3.4.14
JDK 软件版本: jdk-8u241-linux-x64 自行下载
软件下载地址:https://www-eu.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
服务器需求:三台
172.31.209.146
172.31.209.149
172.31.209.148
1. 配置防火墙开放通信端口,三台服务器同样的配置:
[root@DataNode-01 tophadoop]# firewall-cmd --zone=public --add-port=2181/tcp --add-port=2888/tcp --add-port=3888/tcp --permanent success [root@DataNode-01 tophadoop]# firewall-cmd --reload
2.下载软件:
[root@tophad-NameNode-01 tophadoop]# wget https://www-eu.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz --2020-02-18 11:34:25-- https://www-eu.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz Resolving www-eu.apache.org (www-eu.apache.org)... 95.216.24.32, 2a01:4f9:2a:185f::2 Connecting to www-eu.apache.org (www-eu.apache.org)|95.216.24.32|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://downloads.apache.org/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz [following] --2020-02-18 11:34:26-- https://downloads.apache.org/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz Resolving downloads.apache.org (downloads.apache.org)... 88.99.95.219, 2a01:4f8:10a:201a::2 Connecting to downloads.apache.org (downloads.apache.org)|88.99.95.219|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 37676320 (36M) [application/x-gzip] Saving to: ‘zookeeper-3.4.14.tar.gz’ 100%[================================================================================================================================>] 37,676,320 6.06MB/s in 7.3s 2020-02-18 11:34:35 (4.92 MB/s) - ‘zookeeper-3.4.14.tar.gz’ saved [37676320/37676320] [root@tophad-NameNode-01 tophadoop]#
3.配置zookeeper 文件
#解压 [root@tophad-NameNode-01 tophadoop]# tar xf zookeeper-3.4.14.tar.gz #复制到/usr/local 目录下面 [root@tophad-NameNode-01 tophadoop]# mv zookeeper /usr/local/
#更改配置文件 [root@tophad-NameNode-01 tophadoop]# vim /usr/local/zookeeper/conf/zoo.cfg # The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. #存储数据目录与日志目录,注意最后一个文件夹不要有"/" dataDir=/Data/zookeeper/data dataLogDir=/Data/zookeeper/logs # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature autopurge.purgeInterval=1 server.1=172.31.209.146:2888:3888 server.2=172.31.209.148:2888:3888 server.3=172.31.209.149:2888:3888
但是如果使用的是公网IP的时候,注意把本机配置为0.0.0.0。假设我们现在在hadoop1节点上,且使用的是公网IP,则应该如下配置
server.1=0.0.0.0:2888:3888
server.2=172.31.209.148:2888:3888
server.3=172.31.209.149:2888:3888
#创建数据与日志目录 [root@tophad-NameNode-01 tophadoop]# mkdir /Data/zookeeper/data -p [root@tophad-NameNode-01 tophadoop]# mkdir /Data/zookeeper/logs
#创建配置服务器与zoo.cfg 配置时所对应的id [root@tophad-NameNode-01 tophadoop]# echo "1" >> /Data/zookeeper/data/myid [root@tophad-NameNode-01 tophadoop]#
4.配置环境变量
[root@tophad-NameNode-01 tophadoop]# echo ' > export ZOOKEEPER_HOME=/usr/local/zookeeper > export PATH=$PATH:$ZOOKEEPER_HOME/bin > > ' >> /etc/profile [root@tophad-NameNode-01 tophadoop]# source /etc/profile
5.配置服务管理
[root@tophad-NameNode-01 tophadoop]# echo ' > [Unit] > Description=zookeeper.service > After=network.target > [Service] > Type=forking > Environment=/usr/local/zookeeper > ExecStart=/usr/local/zookeeper/bin/zkServer.sh start > ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop > ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart > [Install] > WantedBy=multi-user.target > ' > /lib/systemd/system/zookeeper.service [root@tophad-NameNode-01 tophadoop]# systemctl daemon-reload
6.把zookeeper 目录同步到其它两台服务器
#由于我这边配置了端口号,所以scp 上传时需要用到-P [root@tophad-NameNode-01 tophadoop]# scp -P 55550 -r /usr/local/zookeeper/ tophadoop@172.31.209.148:/home/tophadoop/ [root@tophad-NameNode-01 tophadoop]# scp -P 55550 -r /usr/local/zookeeper/ tophadoop@172.31.209.149:/home/tophadoop/
7.分别在148 149 服务器上面配置
[root@Manager-01 tophadoop]# mv zookeeper/ /usr/local/ [root@Manager-01 tophadoop]# echo ' > export ZOOKEEPER_HOME=/usr/local/zookeeper > export PATH=$PATH:$ZOOKEEPER_HOME/bin > > ' >> /etc/profile [root@Manager-01 tophadoop]# source /etc/profile [root@Manager-01 tophadoop]# mkdir /Data/zookeeper/data -p [root@Manager-01 tophadoop]# mkdir /Data/zookeeper/logs [root@Manager-01 tophadoop]#
#148 配置id 2 [root@Manager-01 tophadoop]# echo "2" >> /Data/zookeeper/data/myid #149 配置id 3 [root@DataNode-01 tophadoop]# echo "3" >> /Data/zookeeper/data/myid
8.配置Jdk,三台服务器同样的配置,zookeeper 使用是Jar包
[root@tophad-NameNode-01 tophadoop]# tar xf jdk-8u241-linux-x64.tar.gz [root@tophad-NameNode-01 tophadoop]# mv jdk1.8.0_241/ /usr/java [root@tophad-NameNode-01 tophadoop]# echo ' > export JAVA_HOME=/usr/java > export JRE_HOME=/usr/java/jre > export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin > export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib > export JAVA_HOME JRE_HOME PATH CLASSPATH' >> /etc/profile [root@tophad-NameNode-01 tophadoop]# source /etc/profile
9.启动服务
[root@tophad-NameNode-01 tophadoop]# zkServer.sh start ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@tophad-NameNode-01 tophadoop]# zkServer.sh status ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg Mode: follower