一、安装
查看linux 32/64
uname -a
//输出
Linux izuf6dvndr65ahvkhs6davz 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
java环境:http://www.cnblogs.com/tq03/p/4980110.html
//从yum 安装
yum list | grep jdk
yum install java-1.8.0-openjdk.x86_64
rpm -qa | grep jdk
//输出yum安装的jdk
java-1.8.0-openjdk-headless-1.8.0.141-1.b16.el7_3.x86_64
copy-jdk-configs-1.2-1.el7.noarch
java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64
rpm -ql java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64
//查看安装后的路径
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/
//设置环境变量
export JAVA_HOME="/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64"
export PATH=$JAVA_HOME/bin:$PATH
java -version
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)
下载安装zookeeper
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
tar -zxvf /opt/download/zookeeper-3.4.9.tar.gz
//zookeeper-3.4.9.tar.gz/conf
cp zoo_sample.cfg zoo.cfg
export ZOOKEEPER_INSTALL=/opt/work/zookeeper-3.4.9
export PATH=$PATH:$ZOOKEEPER_INSTALL/bin
[root@izuf6dvndr65ahvkhs6davz bin]# ./zkServer.sh start
[root@izuf6dvndr65ahvkhs6davz bin]# ./zkCli.sh -server 127.0.0.1:2181
//输出
Connecting to 127.0.0.1:2181
2017-09-03 16:41:47,244 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
2017-09-03 16:41:47,247 [myid:] - INFO [main:Environment@100] - Client environment:host.name=izuf6dvndr65ahvkhs6davz
2017-09-03 16:41:47,247 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_141
2017-09-03 16:41:47,249 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2017-09-03 16:41:47,249 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/jre
2017-09-03 16:41:47,249 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/work/zookeeper-3.4.9/bin/../build/classes:/opt/work/zookeeper-3.4.9/bin/../build/lib/*.jar:/opt/work/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/work/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/opt/work/zookeeper-3.4.9/bin/../lib/netty-3.10.5.Final.jar:/opt/work/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.jar:/opt/work/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/opt/work/zookeeper-3.4.9/bin/../zookeeper-3.4.9.jar:/opt/work/zookeeper-3.4.9/bin/../src/java/lib/*.jar:/opt/work/zookeeper-3.4.9/bin/../conf:
2017-09-03 16:41:47,249 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017-09-03 16:41:47,249 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2017-09-03 16:41:47,249 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=
2017-09-03 16:41:47,249 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2017-09-03 16:41:47,249 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2017-09-03 16:41:47,250 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-514.26.2.el7.x86_64
2017-09-03 16:41:47,250 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2017-09-03 16:41:47,250 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2017-09-03 16:41:47,250 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/work/zookeeper-3.4.9/bin
2017-09-03 16:41:47,251 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@3eb07fd3
2017-09-03 16:41:47,276 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
JLine support is enabled
2017-09-03 16:41:47,364 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@876] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
2017-09-03 16:41:47,426 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x15e46e710900000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0]
zoo.cfg
vi 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.
dataDir=/usr/zookeeper
dataLogDir=/usr/zookeeper/log
# the port at which the clients will connect
clientPort=2181
#server.1=192.168.32.129:2888:3888
tickTime:心跳时间,为了确保连接存在的,以毫秒为单位,最小超时时间为两个心跳时间
initLimit:多少个心跳时间内,允许其他server连接并初始化数据,如果ZooKeeper管理的数据较大,则应相应增大这个值
clientPort:服务的监听端口
dataDir:用于存放内存数据库快照的文件夹,同时用于集群的myid文件也存在这个文件夹里(注意:一个配置文件只能包含一个dataDir字样,即使它被注释掉了。)
dataLogDir:用于单独设置transaction log的目录,transaction log分离可以避免和普通log还有快照的竞争
syncLimit:多少个tickTime内,允许follower同步,如果follower落后太多,则会被丢弃。
server.id=host:port1:port2
host是一个数字,表示这个是第几号服务器,host是这个服务器的ip地址
port1第一个端口用来集群成员的信息交换,表示的是这个服务器与集群中的Leader服务器交换信息的端口
port2是在leader挂掉时专门用来进行选举leader所用
集群部署:
需要在zoo.cfg 添加集群的节点配置,如
server.1=192.168.32.131:2888:3888
server.2=192.168.32.132:2888:3888
server.3=192.168.32.133:2888:3888
在dataDir所指定的目录下创建一个文件名为zookeeper_server.pid的文件,文件中的内容只有一行,为本主机对应的id值,如192.168.32.131机器里配置1。
refer:http://blog.csdn.net/shirdrn/article/details/7183503