contos7 安裝zookeeper集群
1.軟件版本:
zookeeper-3.4.6.tar.gz
2.下載地址:
https://mirrors.cnnic.cn/apache/zookeeper/
3.上傳到機器目錄:/usr/local
4.進入上傳的目錄后解壓zookeeper:
tar -zxvf zookeeper-3.4.6.tar.gz zookeeper
# 進入zookeeper目錄
cd zoookeeper/
# 創(chuàng)建data 和 logs目錄
mkdir data logs
5.在 data 目錄下創(chuàng)建 myid 文件,并寫入編號
cd ../data touch myid echo "1">>myid
每臺機器的myid里面的值對應server.后面的數字x。
6.需要開放3個端口(可選做)
[root@redhat66 data]# sudo /sbin/iptables -I INPUT -p tcp --dport 2181 -j ACCEPT [root@redhat66 data]# sudo /sbin/iptables -I INPUT -p tcp --dport 2888 -j ACCEPT [root@redhat66 data]# sudo /sbin/iptables -I INPUT -p tcp --dport 3888 -j ACCEPT
7.配置zookeeper環(huán)境變量
# 編輯 /etc/profile [root@192 ~]# vi /etc/profile # 在文件尾部新增如下內容: #zookeeper export ZOOKEEPER_HOME=/usr/local/zookeeper export PATH=$ZOOKEEPER_HOME/bin/:$PATH # 使文件生效 source /etc/profile
8.配置zookeeper啟動文件
# 進入conf cd conf/ # 拷貝文件 cp zoo_sample.cfg zoo.cfg # 編輯 vim 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=/usr/local/zookeeper/data dataLogDir=/usr/local/zookeeper/logs/ server.1=192.168.0.165:2888:3888 server.2=192.168.0.166:2888:3888 server.3=192.168.0.167:2888:3888 # 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.x x與myid文件中的內容保持一致
9.其他的機器重復步驟3-8步驟
10.分別啟動三臺機器上的zookeeper服務
zkServer.sh start
11.查看服務狀態(tài)
zkServer.sh status
[root@192 bin]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@redhat66 bin]# zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@192 bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower
12.或者使用jps,有(4895 QuorumPeerMain)則啟動成功
[root@192 bin]# jps 4922 Jps 4895 QuorumPeerMain
13.客戶端連接
./zkCli.sh -server 192.168.0.166:2181
go big or go home -- facebook

浙公網安備 33010602011771號