OS:CentOS 7.2.1511 (Core)
JDK:1.8
zookeeper:3.4.9
服务器列表:
172.31.23.121
172.31.49.27
172.31.17.19
一,安装java JDK
检查系统是否已安装jdk:
rpm -qa | grep java
如已安装先卸载:
rpm -qa | grep java | xargs rpm -e --nodeps
建立JAVA_HOME目录
mkdir /usr/local/java/
将二进制包放入JAVA_HOME目录并解压:
cd /usr/local/java/ scp 52.79.97.181:/home/emma/jdk-8u144-linux-x64.tar.gz ./ tar -xvf jdk-8u144-linux-x64.tar.gz
配置全局java环境变量:
vim /etc/profile export JAVA_HOME=/usr/local/java/jdk1.8.0_144 export JRE_HOME=$JAVA_HOME/jre export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=./:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
使环境变更生效:
source /etc/profile
检测是否安装成功:
java -version java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
二,zookeeper集群的安装
1,下载zookeeper二进制安装文件
cd /usr/local/ wget http://apache.website-solution.net/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
2,解压
tar -zxvf zookeeper-3.4.9.tar.gz
3,准备配置文件:
cd zookeeper-3.4.9/conf vim zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/usr/local/zookeeper-3.4.9/data clientPort=2181 server.1=172.31.23.121:2888:3888 server.2=172.31.49.27:2888:3888 server.3=172.31.17.19:2888:3888
4,创建数据目录:
cd /usr/local/zookeeper-3.4.9/ mkdir data
5,在数据目录中创建myid文件:
vim myid 1
(myid文件的内容为zoo.cfg对应server的id号,172.31.23.121为1,172.31.49.27为2,172.31.17.19为3)
6,在另外两台服务器上按上面的步骤进行相应的部署
三,启动集群
1,三个服务器都部署完后,现在可以启动集群了
cd /usr/local/zookeeper-3.4.9/bin sh zkServer.sh start ZooKeeper JMX enabled by default Using config: /usr/local/zookeeper-3.4.9/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
2,验证服务器是否正常:
telnet 127.0.0.1 2181 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is ‘^]‘. stat Zookeeper version: 3.4.9-1757313, built on 08/23/2016 06:50 GMT Clients: /127.0.0.1:51174[0](queued=0,recved=1,sent=0) Latency min/avg/max: 0/0/0 Received: 1 Sent: 0 Connections: 1 Outstanding: 0 Zxid: 0x0 Mode: follower Node count: 4 Connection closed by foreign host.
stat命令输出以上信息就说明服务已正常启动。
时间: 2024-10-12 15:29:46