一、准备虚拟机
准备三台虚拟机,对应ip地址和主机名如下:
ip地址 | Hostname |
192.168.153.150 | ant163 |
192.168.153.151 | ant164 |
192.168.153.152 | ant165 |
修改hostname,并使之生效
[root@localhost /]# hostnamectl set-hostname zookeeper1 //修改hostname
[root@localhost /]# hostname //查看hostname
[root@localhost /]# bash //刷新
进入/etc/sysconfig/network-scripts/ifcfg-ens33目录下修改网络信息
重启网络服务
systemlctl restart network.service
service network restart
测试ping
成功连接XShell
【注】这里可能由于内存不够导致无法创建新虚拟机。关闭虚拟机需要使用shutdown命令,不能直接使用可视化关闭。
二、安装配置zookeeper
添加压缩包,压缩包我放在/opt/install下面。
链接: https://pan.baidu.com/s/1FWn0t095KxoSz3PaKteHZw 提取码: 4ew2 复制这段内容后打开百度网盘手机App,操作更方便哦
添加主机hosts
# 添加hosts
[root@hadoop02 ~]# vim /etc/hosts
# 添加IP地址和主机名
192.168.153.150 ant163
192.168.153.151 ant164
192.168.153.152 ant165
尝试连接,可以ping通
将hosts文件拷贝到其他两台主机上
[root@hadoop02 ~]# scp /etc/hosts root@ant164:/etc/
[root@hadoop02 ~]# scp /etc/hosts root@ant165:/etc/
打开另一台机器,成功拷贝
设置免密登录
进入家目录,进入.ssh目录下
# 设置免密登录
[root@hadoop02 .ssh]# ssh-keygen -t rsa -P ''
# 将公钥追加到authorized_keys文件中
[root@hadoop02 .ssh]# cat /root/.ssh/id_rsa.pub >> ./authorized_keys
# 将当前公钥拷贝到ant164公钥中
[root@hadoop02 .ssh]# ssh-copy-id -i ./id_rsa.pub -p22 root@ant164
[root@hadoop02 .ssh]# ssh-copy-id -i ./id_rsa.pub -p22 root@ant165
查看id_rsa.pub公钥
查看备付公钥:
# 测试免密登录是否成功
[root@hadoop02 .ssh]# ssh -p22 root@ant163
[root@hadoop02 .ssh]# ssh -p22 root@ant164
[root@hadoop02 .ssh]# ssh -p22 root@ant165
将zookeeper压缩包分配到其他两台主机上
[root@ant163 .ssh]# scp /opt/install/zookeeper-3.4.5-cdh5.14.2.tar.gz root@ant164:/opt/install/
[root@ant163 .ssh]# scp /opt/install/zookeeper-3.4.5-cdh5.14.2.tar.gz root@ant165:/opt/install/
在ant163上安装脚本文件
#! /bin/bash
echo 'auto install begining....'
#global var
hostname=`hostname`
jdk=false
hadoop=false
zk=true
# JAVA_HOME
if [ "$jdk" = true ];then
echo 'jdk install set true'
echo 'setup jdk-8u321-linux-x64.tar.gz'
tar -zxf /opt/install/jdk-8u321-linux-x64.tar.gz -C /opt/soft/
mv /opt/soft/jdk1.8.0_321 /opt/soft/jdk180
sed -i '73a\export PATH=$PATH:$JAVA_HOME/bin' /etc/profile
sed -i '73a\export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' /etc/profile
sed -i '73a\export JAVA_HOME=/opt/soft/jdk180' /etc/profile
sed -i '73a\#jdk' /etc/profile
echo 'setup jdk 8 success!!!'
fi
#ZK_HOME
if [ "$zk" = true ];then
echo 'zookeeper install set true'
echo 'setup zookeeper-3.4.5-cdh5.14.2.tar.gz'
tar -zxf /opt/install/zookeeper-3.4.5-cdh5.14.2.tar.gz -C /opt/soft/
mv /opt/soft/zookeeper-3.4.5-cdh5.14.2 /opt/soft/zk345
cp /opt/soft/zk345/conf/zoo_sample.cfg /opt/soft/zk345/conf/zoo.cfg
mkdir -p /opt/soft/zk345/datas
sed -i '12c dataDir=/opt/soft/zk345/datas' /opt/soft/zk345/conf/zoo.cfg
echo "server.0=$hostname:2287:3387" >> /opt/soft/zk345/conf/zoo.cfg
echo "0" > /opt/soft/zk345/datas/myid
sed -i '73a\export PATH=$PATH:$ZOOKEEPER_HOME/bin' /etc/profile
sed -i '73a\export ZOOKEEPER_HOME=/opt/soft/zk345' /etc/profile
sed -i '73a\#ZK' /etc/profile
# 刷新系统配置文件
source /etc/profile
echo 'setup zookeeper success!!!'
fi
开启进程
# 进入到zookeeper/bin目录下
[root@ant163 bin]# ./zkServer.sh start
显示上面进程,表示zookeeper运行。
三台主机分别start,查看status
启动/关闭所有zookeeper/查看所有zookeeper状态
[root@ant151 shell]# ./zkop.sh start
#! /bin/bash
case $1 in
"start"){
for i in ant151 ant152 ant153
do
ssh $i "/opt/soft/zk345/bin/zkServer.sh start "
done
};;
"stop"){
for i in ant151 ant152 ant153
do
ssh $i "/opt/soft/zk345/bin/zkServer.sh stop "
done
};;
"status"){
for i in ant151 ant152 ant153
do
ssh $i "/opt/soft/zk345/bin/zkServer.sh status "
done
};;
esac
查看所有zookeeper服务启动情况
[root@ant163 .ssh]# ./showalljps.sh
# showalljps.sh
#! /bin/bash
for i in ant151 ant152 ant153 ant154
do
echo ---------- $i 服务启动状态 -------------
ssh $i "$* "
done