DBILITY

zookeeper replicated mode 설치 본문

bigdata/zookeeper

zookeeper replicated mode 설치

DBILITY 2018. 4. 17. 22:34
반응형

따라해보자. 대충 읽어 보니 

"in production, you should run ZooKeeper in replicated mode, all servers in the quorum have copies of the same configuration file" 이라는데.

dataDir에 myid파일은 서버번호별로~

https://zookeeper.apache.org/doc/r3.4.11/zookeeperStarted.html#sc_RunningReplicatedZooKeeper

https://zookeeper.apache.org/doc/r3.4.11/zookeeperAdmin.html#sc_advancedConfiguration

 

먼저 java설치가 되어 있어야 한다.

#zookeeper가 설치될 3대(5대추천이라는) 모두에 사용자 추가 및 datagroup에 추가
[root@big-master src]# useradd zookeeper ; echo 'zookeeper' | passwd --stdin zookeeper ; usermod -G datagroup zookeeper
Changing password for user zookeeper.
passwd: all authentication tokens updated successfully.

[root@big-master src]# ssh big-slave1 "useradd zookeeper ; echo 'zookeeper' | passwd --stdin zookeeper ; usermod -G datagroup zookeeper"
Changing password for user zookeeper.
passwd: all authentication tokens updated successfully.
[root@big-master src]# ssh big-slave2 "useradd zookeeper ; echo 'zookeeper' | passwd --stdin zookeeper ; usermod -G datagroup zookeeper"
Changing password for user zookeeper.
passwd: all authentication tokens updated successfully.

[root@big-master src]# su - zookeeper

[zookeeper@big-master ~]$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zookeeper/.ssh/id_rsa):
Created directory '/home/zookeeper/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zookeeper/.ssh/id_rsa.
Your public key has been saved in /home/zookeeper/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:cRMNmJCHkT1x+GXuu3Rn7eRvVfsFiPMEJbJTDhdq0p8 zookeeper@big-master
The key's randomart image is:
+---[RSA 4096]----+
|      oB+=O=.    |
|      +.BX.o+    |
|      ..Bo+* .   |
|       o =+o+ . .|
|        S E=   .o|
|            o  .+|
|            ... O|
|           ... *o|
|            .. .=|
+----[SHA256]-----+

[zookeeper@big-master ~]$ cd .ssh/
[zookeeper@big-master .ssh]$ ls
id_rsa  id_rsa.pub
[zookeeper@big-master .ssh]$ cp id_rsa.pub ./authorized_keys
#대상서버에 .ssh 디렉토리가 존재해야함
[zookeeper@big-master .ssh]$ scp id_rsa.pub zookeeper@big-slave1:/home/zookeeper/.ssh/authorized_keys
[zookeeper@big-master .ssh]$ scp id_rsa.pub zookeeper@big-slave2:/home/zookeeper/.ssh/authorized_keys
또는 
#[zookeeper@big-master .ssh]$ ssh-copy-id zookeeper@big-master
#[zookeeper@big-master .ssh]$ ssh-copy-id zookeeper@big-slave1
#[zookeeper@big-master .ssh]$ ssh-copy-id zookeeper@big-slave2

[root@big-master src]# wget http://mirror.apache-kr.org/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
--2018-04-18 10:47:22--  http://mirror.apache-kr.org/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
Resolving mirror.apache-kr.org (mirror.apache-kr.org)... 1.201.139.179
Connecting to mirror.apache-kr.org (mirror.apache-kr.org)|1.201.139.179|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 36668066 (35M) [application/x-gzip]
Saving to: ‘zookeeper-3.4.11.tar.gz’

100%[==========================================================>] 36,668,066  11.3MB/s   in 3.2s

2018-04-18 10:47:25 (11.0 MB/s) - ‘zookeeper-3.4.11.tar.gz’ saved [36668066/36668066]

[root@big-master src]#
[root@big-master src]# tar -zxpf zookeeper-3.4.11.tar.gz

[root@big-master src]# cp -rf zookeeper-3.4.11 /bigdata

[root@big-master src]# chown -R zookeeper.zookeeper /bigdata/zookeeper-3.4.11/

[root@big-master src]# ln -s /bigdata/zookeeper-3.4.11/ /zookeeper

[root@big-master src]# vi /etc/profile
export ZOOKEEPER_HOME=/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin

[root@big-master src]# source /etc/profile

[root@big-master src]# rsync -az /etc/profile root@big-slave1:/etc/profile
[root@big-master src]# rsync -az /etc/profile root@big-slave2:/etc/profile

[root@big-master src]# su - zookeeper

[zookeeper@big-master ~]$ cd /bigdata/zookeeper-3.4.11/

[zookeeper@big-master zookeeper-3.4.11]$ mkdir data

[zookeeper@big-master zookeeper-3.4.11]$ cp conf/zoo_sample.cfg conf/zoo.cfg

[zookeeper@big-master zookeeper-3.4.11]$ vi conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/zookeeper/data
dataLogDir=/zookeeper/logs
clientPort=2181
server.1=big-master:2888:3888
server.2=big-slave1:2888:3888
server.3=big-slave2:2888:3888
:wq!

[zookeeper@big-master zookeeper-3.4.11]$ vi conf/log4j.properties
zookeeper.root.logger=INFO, CONSOLE
zookeeper.console.threshold=INFO
zookeeper.log.dir=/zookeeper/logs
zookeeper.log.file=zookeeper.log
zookeeper.log.threshold=DEBUG
zookeeper.tracelog.dir=/zookeeper/logs
zookeeper.tracelog.file=zookeeper_trace.log
:wq!

[zookeeper@big-master zookeeper-3.4.11]$ vi bin/zkEnv.sh
ZOO_LOG_DIR="${ZOOKEEPER_HOME}/logs"
:wq!

#The entries of the form server.X list the servers that make up the ZooKeeper service. When the server starts up,
#it knows which server it is by looking for the file myid in the data directory. That file has the contains the server number, in ASCII.
[zookeeper@big-master zookeeper-3.4.11]$ echo 1 > /zookeeper/data/myid

[zookeeper@big-master ~]$ rsync -az /bigdata/zookeeper-3.4.11 zookeeper@big-slave1:/bigdata/
[zookeeper@big-master ~]$ rsync -az /bigdata/zookeeper-3.4.11 zookeeper@big-slave2:/bigdata/

[zookeeper@big-master ~]$ ssh big-slave1 "echo 2 > /bigdata/zookeeper-3.4.11/data/myid"
[zookeeper@big-master ~]$ ssh big-slave2 "echo 3 > /bigdata/zookeeper-3.4.11/data/myid"

[root@big-master ~]# ssh big-slave1 "ln -s /bigdata/zookeeper-3.4.11 /zookeeper"
[root@big-master ~]# ssh big-slave2 "ln -s /bigdata/zookeeper-3.4.11 /zookeeper"

[zookeeper@big-master ~]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[zookeeper@big-master ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /zookeeper/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

[zookeeper@big-slave1 ~]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[zookeeper@big-slave1 ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /zookeeper/bin/../conf/zoo.cfg
Mode: leader

[zookeeper@big-slave2 ~]$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[zookeeper@big-slave2 ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /zookeeper/bin/../conf/zoo.cfg
Mode: follower

[zookeeper@big-master ~]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /zookeeper/bin/../conf/zoo.cfg
Mode: follower

[zookeeper@big-master ~]$ jps
3968 Jps
3652 QuorumPeerMain

[zookeeper@big-slave1 ~]$ jps
3364 QuorumPeerMain
3676 Jps

[zookeeper@big-slave2 ~]$ jps
3110 QuorumPeerMain
3321 Jps

 

서비스등록은 systemd 서비스등록하기를 참고

반응형
Comments