Linux系统Zookeeper集群配置

Zookeeper版本:zookeeper-3.4.8.tar.gz

用户:root

  • 解压
  • [root@localhost zookeeper]# tar -xvf zookeeper-3.4.8.tar.gz 
    

     

  • 配置集群单个节点
  • [root@localhost zookeeper]# mv zookeeper-3.4.8 zookeeper-2181
    [root@localhost zookeeper]# cd zookeeper-2181
    [root@localhost zookeeper-2181]# ll
    total 1572
    drwxr-xr-x.  2 listen listen    4096 Feb  5 19:49 bin
    -rw-rw-r--.  1 listen listen   83235 Feb  5 19:46 build.xml
    -rw-rw-r--.  1 listen listen   88625 Feb  5 19:46 CHANGES.txt
    drwxr-xr-x.  2 listen listen      67 Apr 27 00:21 conf
    drwxr-xr-x. 10 listen listen    4096 Feb  5 19:46 contrib
    drwxr-xr-x.  2 listen listen    4096 Feb  5 19:50 dist-maven
    drwxr-xr-x.  6 listen listen    4096 Feb  5 19:49 docs
    -rw-rw-r--.  1 listen listen    1953 Feb  5 19:46 ivysettings.xml
    -rw-rw-r--.  1 listen listen    3498 Feb  5 19:46 ivy.xml
    drwxr-xr-x.  4 listen listen    4096 Feb  5 19:49 lib
    -rw-rw-r--.  1 listen listen   11938 Feb  5 19:46 LICENSE.txt
    -rw-rw-r--.  1 listen listen     171 Feb  5 19:46 NOTICE.txt
    -rw-rw-r--.  1 listen listen    1770 Feb  5 19:46 README_packaging.txt
    -rw-rw-r--.  1 listen listen    1585 Feb  5 19:46 README.txt
    drwxr-xr-x.  5 listen listen      44 Feb  5 19:46 recipes
    drwxr-xr-x.  8 listen listen    4096 Feb  5 19:49 src
    -rw-rw-r--.  1 listen listen 1360961 Feb  5 19:46 zookeeper-3.4.8.jar
    -rw-rw-r--.  1 listen listen     819 Feb  5 19:50 zookeeper-3.4.8.jar.asc
    -rw-rw-r--.  1 listen listen      33 Feb  5 19:46 zookeeper-3.4.8.jar.md5
    -rw-rw-r--.  1 listen listen      41 Feb  5 19:46 zookeeper-3.4.8.jar.sha1
    [root@localhost conf]# mv zoo_sample.cfg zoo.cfg
    [root@localhost conf]# vi zoo.cfg 
    #在文件末尾追加以下内容
    server.2181=192.168.75.141:2881:3881
    server.2182=192.168.75.141:2882:3882
    server.2183=192.168.75.141:2883:3883
    server.2184=192.168.75.141:2884:3884
    server.2185=192.168.75.141:2885:3885
    

    copy 4份

  • [root@localhost zookeeper]# cp -r zookeeper-2181 zookeeper-2182
    [root@localhost zookeeper]# cp -r zookeeper-2181 zookeeper-2183
    [root@localhost zookeeper]# cp -r zookeeper-2181 zookeeper-2184
    [root@localhost zookeeper]# cp -r zookeeper-2181 zookeeper-2185

    修改其他4份的配置文件{zookeeper_home}/conf/zoo.cfg

  • #zookeeper-2182/conf/zoo.cfg文件修改为以下内容,其他内容不变
    dataDir=/home/listen/zookeeper/data/2182
    clientPort=2182
    
    #zookeeper-2183/conf/zoo.cfg文件修改为以下内容,其他内容不变
    dataDir=/home/listen/zookeeper/data/2183
    clientPort=2183
    
    #zookeeper-2184/conf/zoo.cfg文件修改为以下内容,其他内容不变
    dataDir=/home/listen/zookeeper/data/2184
    clientPort=2184
    
    #zookeeper-2185/conf/zoo.cfg文件修改为以下内容,其他内容不变
    dataDir=/home/listen/zookeeper/data/2185
    clientPort=2185

     

  • 创建数据文件存储目录
  • #创建数据文件存储目录,与{zookeeper_home/conf/zoo.cfg}文件中的dataDir变量对应
    [root@localhost zookeeper]# pwd
    /home/listen/zookeeper
    [root@localhost zookeeper]# mkdir data
    [root@localhost zookeeper]# cd data
    [root@localhost zookeeper]# mkdir 2181
    [root@localhost zookeeper]# mkdir 2182
    [root@localhost zookeeper]# mkdir 2183
    [root@localhost zookeeper]# mkdir 2184
    [root@localhost zookeeper]# mkdir 2185
  • 创建myid文件
  • #myid文件内容为{zookeeper_home}/conf/zoo.cfg文件中server.xxx={ip:port:port}的xxx对应的数字
    [root@localhost data]# pwd
    /home/listen/zookeeper/data
    [root@localhost data]# vi 2181/myid 
    #输入以下内容,保存
    2181
    
    [root@localhost data]# vi 2182/myid 
    #输入以下内容,保存
    2182
    
    [root@localhost data]# vi 2183/myid 
    #输入以下内容,保存
    2183
    
    [root@localhost data]# vi 2184/myid 
    #输入以下内容,保存
    2184
    
    [root@localhost data]# vi 2185/myid 
    #输入以下内容,保存
    2185
    
    
  • 编写统一启停脚本
  • #编写重启脚本
    [root@localhost zookeeper]# vi zookeeper-cluster-restart.sh 
    #输入以下内容
    #停止所有Zookeeper服务
    pgrep zookeeper | xargs kill -s 9
    #启动集群中的Zookeeper服务
    zookeeper-2181/bin/zkServer.sh start
    zookeeper-2182/bin/zkServer.sh start
    zookeeper-2183/bin/zkServer.sh start
    zookeeper-2184/bin/zkServer.sh start
    zookeeper-2185/bin/zkServer.sh start
     
    #编写停止脚本
    [root@localhost zookeeper]# vi zookeeper-cluster-stop.sh 
    #输入以下内容
    #停止所有Zookeeper服务
    pgrep zookeeper | xargs kill -s 9
    #编写启动脚本
    [root@localhost zookeeper]# vi zookeeper-cluster-start.sh 
    #输入以下内容
    #启动集群中的Zookeeper服务
    zookeeper-2181/bin/zkServer.sh start
    zookeeper-2182/bin/zkServer.sh start
    zookeeper-2183/bin/zkServer.sh start
    zookeeper-2184/bin/zkServer.sh start
    zookeeper-2185/bin/zkServer.sh start

     

  • 测试脚本和集群是否成功
  • [root@localhost zookeeper]# ./zookeeper-cluster-restart.sh 
    
    Usage:
     kill [options] <pid|name> [...]
    
    Options:
     -a, --all              do not restrict the name-to-pid conversion to processes
                            with the same uid as the present process
     -s, --signal <sig>     send specified signal
     -q, --queue <sig>      use sigqueue(2) rather than kill(2)
     -p, --pid              print pids without signaling them
     -l, --list [=<signal>] list signal names, or convert one to a name
     -L, --table            list signal names and numbers
    
     -h, --help     display this help and exit
     -V, --version  output version information and exit
    
    For more details see kill(1).
    ZooKeeper JMX enabled by default
    Using config: /home/listen/zookeeper/zookeeper-2181/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    ZooKeeper JMX enabled by default
    Using config: /home/listen/zookeeper/zookeeper-2182/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    ZooKeeper JMX enabled by default
    Using config: /home/listen/zookeeper/zookeeper-2183/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    ZooKeeper JMX enabled by default
    Using config: /home/listen/zookeeper/zookeeper-2184/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    ZooKeeper JMX enabled by default
    Using config: /home/listen/zookeeper/zookeeper-2185/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    [root@localhost zookeeper]# ps aux|grep zookeeper
    root      15449 66.5  1.7 2723468 51360 pts/7   Sl   03:19   0:06 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/listen/zookeeper/zookeeper-2181/bin/../build/classes:/home/listen/zookeeper/zookeeper-2181/bin/../build/lib/*.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/slf4j-api-1.6.1.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/netty-3.7.0.Final.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/log4j-1.2.16.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/jline-0.9.94.jar:/home/listen/zookeeper/zookeeper-2181/bin/../zookeeper-3.4.8.jar:/home/listen/zookeeper/zookeepe-2181/bin/../src/java/lib/*.jar:/home/listen/zookeeper/zookeeper-2181/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/listen/zookeeper/zookeeper-2181/bin/../conf/zoo.cfg
    root      15490 86.0  1.8 2723468 53116 pts/7   Sl   03:19   0:07 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/listen/zookeeper/zookeeper-2182/bin/../build/classes:/home/listen/zookeeper/zookeeper-2182/bin/../build/lib/*.jar:/home/listen/zookeeper/zookeeper-2182/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/listen/zookeeper/zookeeper-2182/bin/../lib/slf4j-api-1.6.1.jar:/home/listen/zookeeper/zookeeper-2182/bin/../lib/netty-3.7.0.Final.jar:/home/listen/zookeeper/zookeeper-2182/bin/../lib/log4j-1.2.16.jar:/home/listen/zookeeper/zookeeper-2182/bin/../lib/jline-0.9.94.jar:/home/listen/zookeeper/zookeeper-2182/bin/../zookeeper-3.4.8.jar:/home/listen/zookeeper/zookeepe-2182/bin/../src/java/lib/*.jar:/home/listen/zookeeper/zookeeper-2182/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/listen/zookeeper/zookeeper-2182/bin/../conf/zoo.cfg
    root      15515 71.2  1.7 2723468 51272 pts/7   Sl   03:19   0:05 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/listen/zookeeper/zookeeper-2183/bin/../build/classes:/home/listen/zookeeper/zookeeper-2183/bin/../build/lib/*.jar:/home/listen/zookeeper/zookeeper-2183/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/listen/zookeeper/zookeeper-2183/bin/../lib/slf4j-api-1.6.1.jar:/home/listen/zookeeper/zookeeper-2183/bin/../lib/netty-3.7.0.Final.jar:/home/listen/zookeeper/zookeeper-2183/bin/../lib/log4j-1.2.16.jar:/home/listen/zookeeper/zookeeper-2183/bin/../lib/jline-0.9.94.jar:/home/listen/zookeeper/zookeeper-2183/bin/../zookeeper-3.4.8.jar:/home/listen/zookeeper/zookeepe-2183/bin/../src/java/lib/*.jar:/home/listen/zookeeper/zookeeper-2183/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/listen/zookeeper/zookeeper-2183/bin/../conf/zoo.cfg
    root      15544 77.3  1.7 3125936 52180 pts/7   Sl   03:19   0:04 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/listen/zookeeper/zookeeper-2184/bin/../build/classes:/home/listen/zookeeper/zookeeper-2184/bin/../build/lib/*.jar:/home/listen/zookeeper/zookeeper-2184/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/listen/zookeeper/zookeeper-2184/bin/../lib/slf4j-api-1.6.1.jar:/home/listen/zookeeper/zookeeper-2184/bin/../lib/netty-3.7.0.Final.jar:/home/listen/zookeeper/zookeeper-2184/bin/../lib/log4j-1.2.16.jar:/home/listen/zookeeper/zookeeper-2184/bin/../lib/jline-0.9.94.jar:/home/listen/zookeeper/zookeeper-2184/bin/../zookeeper-3.4.8.jar:/home/listen/zookeeper/zookeepe-2184/bin/../src/java/lib/*.jar:/home/listen/zookeeper/zookeeper-2184/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/listen/zookeeper/zookeeper-2184/bin/../conf/zoo.cfg
    root      15567 59.2  1.4 1991264 41848 pts/7   Sl   03:19   0:02 java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/listen/zookeeper/zookeeper-2185/bin/../build/classes:/home/listen/zookeeper/zookeeper-2185/bin/../build/lib/*.jar:/home/listen/zookeeper/zookeeper-2185/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/listen/zookeeper/zookeeper-2185/bin/../lib/slf4j-api-1.6.1.jar:/home/listen/zookeeper/zookeeper-2185/bin/../lib/netty-3.7.0.Final.jar:/home/listen/zookeeper/zookeeper-2185/bin/../lib/log4j-1.2.16.jar:/home/listen/zookeeper/zookeeper-2185/bin/../lib/jline-0.9.94.jar:/home/listen/zookeeper/zookeeper-2185/bin/../zookeeper-3.4.8.jar:/home/listen/zookeeper/zookeepe-2185/bin/../src/java/lib/*.jar:/home/listen/zookeeper/zookeeper-2185/bin/../conf: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/listen/zookeeper/zookeeper-2185/bin/../conf/zoo.cfg
    root      15651  0.0  0.0 112640   960 pts/7    R+   03:20   0:00 grep --color=auto zookeeper
  • 客户端连接测试
  • [root@localhost zookeeper]# zookeeper-2181/bin/zkCli.sh -server localhost:2181
    Connecting to localhost:2181
    2016-05-11 03:26:21,295 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT
    2016-05-11 03:26:21,638 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=localhost
    2016-05-11 03:26:21,638 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_67
    2016-05-11 03:26:21,642 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
    2016-05-11 03:26:21,643 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/java/jdk1.7.0_67/jre
    2016-05-11 03:26:21,643 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/listen/zookeeper/zookeeper-2181/bin/../build/classes:/home/listen/zookeeper/zookeeper-2181/bin/../build/lib/*.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/slf4j-api-1.6.1.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/netty-3.7.0.Final.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/log4j-1.2.16.jar:/home/listen/zookeeper/zookeeper-2181/bin/../lib/jline-0.9.94.jar:/home/listen/zookeeper/zookeeper-2181/bin/../zookeeper-3.4.8.jar:/home/listen/zookeeper/zookeeper-2181/bin/../src/java/lib/*.jar:/home/listen/zookeeper/zookeeper-2181/bin/../conf:
    2016-05-11 03:26:21,643 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
    2016-05-11 03:26:21,644 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
    2016-05-11 03:26:21,644 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
    2016-05-11 03:26:21,644 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
    2016-05-11 03:26:21,644 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
    2016-05-11 03:26:21,645 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-229.el7.x86_64
    2016-05-11 03:26:21,645 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
    2016-05-11 03:26:21,645 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
    2016-05-11 03:26:21,645 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/listen/zookeeper
    2016-05-11 03:26:21,649 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@36527386
    Welcome to ZooKeeper!
    2016-05-11 03:26:21,757 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
    2016-05-11 03:26:21,768 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session
    JLine support is enabled
    2016-05-11 03:26:21,858 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x85549f54972b000d, negotiated timeout = 30000
    
    WATCHER::
    
    WatchedEvent state:SyncConnected type:None path:null
    [zk: localhost:2181(CONNECTED) 0] ls /zk
    [codis]
    [zk: localhost:2181(CONNECTED) 1] 

over! 

你可能感兴趣的:(jdk,linux,zookeeper)