实时搭建
一、虚拟机的前期准备
1. 准备三台虚拟机
- 克隆三台虚拟机(linux101、linux101、linux101),配置好对应主机的网络IP、主机名称、关闭防火墙。
- 设置linux101、linux101、linux101的主机对应内存分别是:4G、4G、4G
2. 配置免密登录
- 修改linux101 hosts文件并添加主机节点 ip
vim /etc/hosts
192.168.191.101 linux101
192.168.191.102 linux102
192.168.191.103 linux103
- 配置免密登录命令(rsa算法)
ssh-keygen -t rsa
ssh-copy-id linux101
ssh-copy-id linux102
ssh-copy-id linux103
- linux102、linux103重复以上过程
3. 安装jdk
3.1 卸载Linux自带的 jdk
-
查询jdk
## 方法一 [longlong@linux101 ~]$ rpm -qa | grep jdk java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64 copy-jdk-configs-3.3-2.el7.noarch java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64 ## 方法二 [longlong@linux101 ~]$ rpm -qa | grep -i java | xargs -n1 rpm -e --nodeps
-
卸载 jdk
[longlong@linux101 ~]$ rpm -e --nodeps java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64 [longlong@linux101 ~]$ rpm -e --nodeps copy-jdk-configs-3.3-2.el7.noarch [longlong@linux101 ~]$ rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
3.2 解压并配置jdk环境变量
-
解压
tar -zxvf jdk-8u211-linux-x64.tar.gz -C /opt/module/jdk1.8.0_211
-
配置环境变量
[longlong@linux101 ~]$ sudo vim /etc/profile.d/my-env.sh #JAVA_HOME export JAVA_HOME=/opt/module/jdk1.8.0_211 export PATH=$PATH:$JAVA_HOME/bin [longlong@linux101 ~]$ source /etc/profile
-
测试
[longlong@linux101 ~]$ java -version java version "1.8.0_212" Java(TM) SE Runtime Environment (build 1.8.0_212-b10) Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)
4. 关闭防火墙
# 关闭防火墙
[root@hadoop101 ~]# systemctl stop firewalld.service
# 禁用防火墙
[root@hadoop101 ~]# systemctl disable firewalld.service
二、Zookeeper集群的安装与配置
-
上传并解压至linux101机器
-
进入到Zookeeper目录创建zkData文件夹
[longlong@linux101 ~]$ cd /opt/module/zookeeper-3.5.7/ [longlong@linux101 zookeeper-3.5.7]$ mkdir zkData
-
在zkData中创建myid文件
[longlong@linux101 zookeeper-3.5.7]$ cd zkData/ [longlong@linux101 zkData]$ vim myid 1
-
修改Zookeeper的数据存储目录
[longlong@linux101 zkData]$ cd ../conf/ [longlong@linux101 conf]$ mv zoo_sample.cfg zoo.cfg [longlong@linux101 conf]$vim zoo.cfg ## 数据存储目录 dataDir=/opt/module/zookeeper-3.5.7/zkData ## 节点内部通信端口以及级别配置 server.1=linux101:2888:3888 server.2=linux102:2888:3888 server.3=linux103:2888:3888
-
分发至其他机器
[longlong@linux101 ~]$ scp -r zookeeper-3.5.7/ linux102:/opt/module/ [longlong@linux101 ~]$ scp -r zookeeper-3.5.7/ linux103:/opt/module/
-
修改节点级别
[longlong@linux102 ~]$ vim /opt/module/zookeeper-3.5.7/zkData/myid 2 [longlong@linux103 ~]$ vim /opt/module/zookeeper-3.5.7/zkData/myid 3
-
启动测试
[longlong@linux101 ~]$ cd /opt/module/zookeeper-3.5.7/ [longlong@linux101 zookeeper-3.5.7]$ bin/zkServer.sh start