Original: https://blog.csdn.net/wuyongzhou/article/details/80908428
One,
CentOS7 need to have installed JDK
Please refer to: https: //blog.csdn.net/wuyongzhou/article/details/80906975
two,
Download good zookeeper
I chose this version. Download this should not be difficult, not specifically say.
three,
The downloaded zookeeper use WinSCP uploaded to the specified directory.
I was put on / under the / usr / local directory
four,
Use tar xvzf zookeeper-3.4.12.tar.gz give
Fives,
Use mv zookeeper-3.4.12 zookeeper rename folders
six,
Zookeeper folder into the folder conf
The copy zoo_sample.cfg out cp zoo_sample.cfg zoo.cfg effect as FIG.
Seven,
Modify zoo.cfg file vi zoo.cfg
Will open the default parameters. Which should be noted is dataDir this parameter represents the log file output location
clientPort the port external service provider
Here I modify the path
In the final insertion
server.1=192.168.174.130:2888:3888
server.2=192.168.174.131:2888:3888
server.3=192.168.174.132:2888:3888
Such a format is server.id = host: port: port
id: custom integer representing the server
host: ip address of the server
A communication port between the follower and leader: a first port
The second port: Voting communication port on the leader
Please be configured according to the IP address of your own server. Finally, save and exit.
Eight,
这时候需要到 var 目录下面创建文件夹 zookeeper ,并在zookeeper文件夹里面创建myid文件
在myid文件中写入对应的id
假设当前服务器ip为 192.168.174.130 那么myid文件中写入1,请根据自己在zoo.cfg文件的内容来编写,保存后退出。
九、
由于我们是三台服务器,我们上面才大致将其中一台配置好,需要是对其余两台进行同样的操作,同样的先是解压zookeeper并且重命名(解压的路径三台服务器最好相同),然后回到一开始操作的服务器中,
使用 scp zoo.cfg 用户名@服务器ip:/usr/local/zookeeper/conf
例子:scp zoo.cfg [email protected]:/usr/local/zookeeper/conf(请根据实际调整)
接着输入服务器的密码,就可以把zoo.cfg文件传输到指定的服务器中,接着对最好一台服务器也是这样操作,只是改变服务器ip
接着,到第二台服务器中,重复第八步,第三台服务器也是这样。
按照我的配置 192.168.174.130 在myid文件中是 1,192.168.174.131在myid文件中是 2,192.168.174.132在myid文件中是 3
各位请分清。
十、
这时候,我们的三台服务器都已经做好了基本的配置,接着在第一台服务器中,cd /usr/local/zookeeper/bin 移动到bin目录下,执行zkServer.sh start 启动zookeeper
若提示这样的信息代表成功启动。
这时候我们可以使用telnet 进行访问
如果之前没有安装过telnet的话,肯定会提示没有这个命令。
这时候我们需要先安装telnet。
yum list |grep telnet 获取可以安装的源数据
再执行 yum install telnet-server.x86_64 如果安装过程中提示
那么恭喜你,和我一样。需要配置dns网关
执行 vi /etc/resolv.conf 打开文件,加上一句 nameserver 114.114.114.114 后保存退出。
然后,再次执行yum install telnet-server.x86_64 过程会提示缺少什么的,无视就好。
接着再执行 yum install telnet.x86_64
这时候就可以使用telnet 连接zookeeper服务器了。
十一、
执行 telnet 192.168.174.130 2181 (服务器ip以及端口号请根据实际调整)
接着输入 stat 可以如上图那样,能看到指定服务器的zookeeper信息。
需要注意的是,我们的服务器防火墙需要对zookeeper的相关端口进行开放,否则,会提示这样的错误。
这是因为我其中两台服务器都开放了相对应的端口号,而最后这台132服务器没有开放。
防火墙相关命令:
添加开放端口
样例: firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
根据上面设置的端口,最少需要开放三个
firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --zone=public --add-port=2888/tcp --permanent
firewall-cmd --zone=public --add-port=3888/tcp --permanent
添加后需要执行 firewall-cmd --reload
执行 firewall-cmd --zone=public --list-ports 查看所有打开的端口
这时候,在132服务器再次执行 telnet 192.168.174.132 2181
成功了。
以上的就是最基本的zookeeper集群部署的相关内容,包含了很多方面(也是我一边尝试一边发现的坑),如果有不对的地方,请提出来,谢谢