Chinaunix首页 | 论坛 | 博客
  • 博客访问: 43204
  • 博文数量: 18
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 165
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-19 15:23
个人简介

转身撞上猪

文章分类

全部博文(18)

文章存档

2017年(18)

我的朋友

分类: LINUX

2017-10-19 17:29:45

一、实验主机:3台阿里云主机centos6.9
node1
node2
node3
在/etc/hosts文件中设置如上三个主机名解析
三台主机之间相互设置免密登录(这里直接使用root用户,生产环境应该使用其它应用用户),使用命令 ssh-keygen -t rsa 生成密钥对
把三台主机公钥文件~/.ssh/id_rsa.pub文件内容追加写入到文件~/.ssh/authorized_keys中
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyDjuH7Hai32Bek5Y/UBoP0tZyEYY+2ziIC2B5nhZF805psiL4lz0j6dB9MdgDOkR1XSO7wKkJs2JOlcu98xH7Xn2mIiGmgh+5l0eudKq3MtprtggkjmE/QuS/vgOqK6B7KgPVKbxDbsfl4ZzUe2ww2JGRwfpH22a+cBVxf8YiJVKCuAIyKy8uDHfL7uurZqW7WJ6TI2ViRlc85uzp1xL5Duhg1T2oJHmaO2aqGvicuBxtG/Uowlk76pchO32me7K8BQkn5ABHFSISrJH8i8sctHkKkqkBveYrtuLwkDaOz9inQeQAZtiFUTpKsEEn2eCVbn1rChVO9qKOrtuoPoMfQ== root@node1
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmS7039h+9HoeiCx1EwBQ/VrRoSUyUy9cPTYXLr7cd0rp58IcKqV0WsJZ4pEVYQxPkxoTEgMLJSqJ8PyK45LmEItkOikl3GSWJT97ox3GxGOlS7gxcbT4B4BOXqnrBYujyV07Lv2FApwqNbPUkZ5wGCMVphTp3HGZpQaNu0NX0Z6mhaDu10tlqIShKxGKpzxYOSHCpy1nRhVj/J0w/BK//xFfdSHpD/EFk1uGVHgxVB7lIvZNAWl0hxFvqELNC59w6ElcyLJ6ziUvb2jiXolNayUYH5qVJcGrXtGj/7ekM45HaWq5CGCYU3pVIEhyDQgWPKT1BgH+SJHgEZoGXW29yw== root@node2
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAriWHYbOa3wjD4+UXf0/Fwhl6aVBVFFze6F5h7oD/am1R8HxHKKLKndQg59E2aQMxRjinrYMh52iKDIZmGUWMacld8FNFcL5CN4QHKG2DNveIyU/C4cXFCpWfW96qB87K9iKZIWtnZbgQ8zpJ+FXfiBg9eoyZCSHPuAR3zVZ2W2n9EVqDAqOL52Mvah1MMJrrRkJPm5ZTFWwAZFnYn/h/DSJ8+3PXyJA35acqnYJRrcoTTObYBs0YJJk8Q6gqODLHi9qvYHTnLMxVeeCiPaFJRHkICyBGAVTBzLqBS8ngE3o73XQqSMdxGavDFj4Nzfi3ugOWmaLNmPnZOtZtMBk2gQ== root@node3


二、下载安装介质
zookeeper-3.4.10:   
jdk-7u80-linux-x64.tar.gz:    oracle官网下载
[root@node1 tools]# ls /root/tools
jdk-7u80-linux-x64.tar.gz  zookeeper-3.4.10.tar.gz
[root@node1 tools]#

解压到/usr/local/目录下
 tar -zxf jdk-7u80-linux-x64.tar.gz  -C /usr/local/
 tar -zxf zookeeper-3.4.10.tar.gz -C /usr/local/

三、设置环境变量
echo "export JAVA_HOME=/usr/local/jdk1.7.0_80"  >>/etc/profile
echo "export PATH=$PATH:$JAVA_HOME/bin/" >>/etc/profile
source /etc/profile
java -version查看环境变量是否生效
 [root@node1 tools]# java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
[root@node1 tools]#


四、配置zookeeper
cd /usr/local/zookeeper-3.4.10/conf/
cp zoo_sample.cfg zoo.cfg
编辑zoo.cfg,编辑结果如下,修改了dataDir=/var/lib/zookeeper,并新增了最后三行,其它配置保持默认
[root@node1 conf]# cat 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=/var/lib/zookeeper
# 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=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
[root@node1 conf]#

创建/var/lib/zookeeper目录,并在该目录下创建文件myid,文件内容分别为1、2、3,即zoo.cfg中最后三行配置的数字。
[root@node1 conf]# cd /var/lib/zookeeper/
[root@node1 zookeeper]# cat myid
1
[root@node1 zookeeper]#

[root@node2 conf]# cd /var/lib/zookeeper/
[root@node2 zookeeper]# cat myid
2
[root@node2 zookeeper]#

[root@node3 conf]# cd /var/lib/zookeeper/
[root@node3 zookeeper]# cat myid
3
[root@node3 zookeeper]#

五、启动zookeeper
观察启动日志zookeeper.out是否有报错
[root@node1 zookeeper]# cd /usr/local/zookeeper-3.4.10/bin/
[root@node1 bin]# ./zkServer.sh start
启动后使用命令jps查看QuorumPeerMain进程是否启动
[root@node1 bin]# jps
8211 Jps
8104 QuorumPeerMain
[root@node1 bin]#
使用zkServer.sh status命令查看zookeeper状态,如下可以看到现在是一台leader,两台follower
[root@node1 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
[root@node1 bin]#
[root@node2 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
[root@node2 bin]#
[root@node3 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
[root@node3 bin]#


六、使用zookeeper客户端命令操作zookeeper



[root@node1 bin]# ./zkCli.sh  -server node1:2181


[zk: node1:2181(CONNECTED) 12] ls /
[zookeeper]
[zk: node1:2181(CONNECTED) 13] help
ZooKeeper -server host:port cmd args
connect host:port
get path [watch]
ls path [watch]
set path data [version]
rmr path
delquota [-n|-b] path
quit
printwatches on|off
create [-s] [-e] path data acl
stat path [watch]
close
ls2 path [watch]
history
listquota path
setAcl path acl
getAcl path
sync path
redo cmdno
addauth scheme auth
delete path [version]
setquota -n|-b val path
[zk: node1:2181(CONNECTED) 14]


七、登录zookeeper WEB控制台查看zookeeper运行状态
使
node-zk-browser开源项目











阅读(1684) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~