注:本次安装包存放目录为h3cu,解压目录为/usr/local/src/(因为是集群所以需要准备三台虚拟机,分别为master,slave1,slave2)
一.免密
以下操作三台虚拟机各执行一遍
[root@master src]# ssh-keygen -t rsa
[root@master src]# ssh-copy-id master
[root@master src]# ssh-copy-id slave1
[root@master src]# ssh-copy-id slave2
二.JDK的安装
1.解压jdk安装包
[root@master /]# tar -zxvf /h3cu/jdk-8u161-linux-x64.tar.gz -C /usr/local/src/
2.进入到安装目录下
[root@master src]# cd /usr/local/src/ #进入到安装目录下
[root@master src]# ls #查看解压完成的jdk
jdk1.8.0_161
[root@master src]# mv jdk1.8.0_161/ jdk #改名为jdk
[root@master src]# ls #再次查看
jdk
3.增加jdk环境变量
[root@master src]# vi /etc/profile
#在文件末尾添加
export JAVA_HOME=/usr/local/src/jdk
export PATH=$PATH:$JAVA_HOME/bin
[root@master src]# source /etc/profile #使化境变量生效
4.检查jdk是否安装完成
[root@master src]# java -version #检查jdk版本号
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
5.分发环境变量配置及jdk到另外两台虚拟机
[root@master src]# scp /etc/profile slave1:/etc/profile
profile 100% 1889 1.4MB/s 00:00
[root@master src]# scp /etc/profile slave2:/etc/profile
profile 100% 1889 1.2MB/s 00:00
[root@master src]# scp -r /usr/local/src/jdk/ slave1:/usr/local/src/
[root@master src]# scp -r /usr/local/src/jdk/ slave2:/usr/local/src/
6.在另外两台虚拟机上执行一下命令使环境变量生效
[root@slave1 /]# source /etc/profile
[root@slave2 /]# source /etc/profile
三.zookeeper的安装
1.解压zookeeper安装包
[root@master src]# tar -zxvf /h3cu/apache-zookeeper-3.5.7-bin.tar.gz -C /usr/local/src/
2.进入到安装目录下
[root@master src]# cd /usr/local/src/
[root@master src]# ls
apache-zookeeper-3.5.7-bin jdk
[root@master src]# mv apache-zookeeper-3.5.7-bin/ zk
[root@master src]# ls
jdk zk
3.增加zookeeper的环境变量
[root@master src]# vi /etc/profile
#在文件末尾追加
export ZK_HOME=/usr/local/src/zk
export PATH=$PATH:$ZK_HOME/bin
[root@master src]# source /etc/profile #使环境变量生效
4.进入zookeeper下
[root@master src]# cd zk/
[root@master zk]# mkdir tmp
[root@master zk]# vi tmp/myid
#在myid文件里写入数字1,另外两个分别更改为2,3(切记不可有空格)
5.进入zookeeper的conf目录下
[root@master zk]# cd conf/
[root@master conf]# ls
configuration.xsl log4j.properties zoo_sample.cfg
[root@master conf]# mv zoo_sample.cfg zoo.cfg
6.编辑配置文件zoo.cfg
[root@master conf]# 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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/src/zk/tmp #数据存放目录
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=master:2888:3888 #####
server.2=slave1:2888:3888
server.3=slave2:2888:3888
7.分发环境变量及zookeeper到另外两台虚拟机
[root@master conf]# scp /etc/profile slave1:/etc/
profile 100% 1954 1.1MB/s 00:00
[root@master conf]# scp /etc/profile slave2:/etc/
profile 100% 1954 1.4MB/s 00:00
[root@master conf]# scp -r /usr/local/src/zk/ slave1:/usr/local/src/
[root@master conf]# scp -r /usr/local/src/zk/ slave2:/usr/local/src/
source /etc/profile #在另外两台虚拟机上执行
8.分别更改另外两台虚拟机的myid为2,3
9.启动zookeeper
[root@master conf]# zkServer.sh start #三台虚拟机都执行此命令(启动zookeeper)
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zk/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@master conf]# zkServer.sh status #查看状态(其中有一台为leader)
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zk/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower