Zookeeper 集群安装

  1. 基本配置(3台)--先安装jdk1.8
#ZKA、ZKB、ZKC 3台 配置同
[root@ZKA local]# hostname
   ZKA.COM
##修改主机名:
[root@ZKA ~]#vim /etc/hostname
   ZKA.COM

[root@ZKA local]#vim /etc/sysconfig/network
-----------------------------------------------------------------------------
NETWORKING=yes
HOSTNAME=ZKA
-----------------------------------------------------------------------------

[root@ZKA local]# # vim /etc/hosts
-----------------------------------------------------------------------------
127.0.0.1 ZKA
192.168.40.151 ZKA
-----------------------------------------------------------------------------

#3台服务器的的 selinux 都要 disable
[root@ZKA local]# vim /etc/selinux/config
-----------------------------------------------------------------------------
SELINUX=disabled
-----------------------------------------------------------------------------

[root@ZKA ~]# yum install -y openssh openssh-clients

检查并卸载OpenJDK & 安裝JDK 1.8

[root@xag200 ~]# rpm -qa|grep -i mysql

[root@xag200 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64

[root@xag200 ~]# yum remove mariadb*
[root@xag200 ~]# rm /etc/my.cnf

[root@xag200 ~]# rpm -qa|grep mariadb

#安装jdk
[root@XAG193 ~]# mkdir /u01/java -p
[root@XAG193 ~]# cd /u01/java/
[root@XAG193 java]# ls
jdk1.8.0_181  jdk-8u181-linux-x64.tar.gz
[root@XAG193 java]# tar -zxvf jdk-8u181-linux-x64.tar.gz
#设置环境变量
[root@XAG193 java]# vim /etc/profile

在profile中添加如下内容:
#set java environment
JAVA_HOME=/u01/java/jdk1.8.0_181
JRE_HOME=/u01/java/jdk1.8.0_181/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

#让修改生效:
[root@XAG193 java]# source /etc/profile
#输入java -version查看一下jdk版本信息:
[root@xag182 java]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
  1. 设置环境变量(3台)
[root@ZKA ~]# vim /etc/profile
在profile中添加如下内容:
### Zookeeper ###
ZK_HOME=/usr/local/zookeeper
PATH=$ZK_HOME/bin:$PATH
export ZK_HOME
export PATH

#让修改生效:
[root@ZKA ~]# source /etc/profile
  1. 安装(3台)
wget http://archive.apache.org/dist/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz

[root@ZKA ~]# tar -xvf zookeeper-3.4.12.tar.gz

安装Zookeeper
[root@ZKA ~]# mv zookeeper-3.4.12 /usr/local/zookeeper

[root@ZKA ~]# cd /usr/local

#规划文件及日志的存储位置
[root@ZKA ~]#mkdir -p /usr/local/zookeeper/data

[root@ZKA ~]#mkdir -p /usr/local/zookeeper/log
  1. 配置Zookeeper参数文件(3台)
[root@ZKA ]#mv /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg

[root@ZKA ~]#cp /usr/local/zookeeper/conf/zoo.cfg /usr/local/zookeeper/conf/zoo.cfg_bak

[root@ZKA ~]# vim /usr/local/zookeeper/conf/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.
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections. (set to 0 is unlimit the maximum)
maxClientCnxns=0
server.1=192.168.40.151:2888:3888
server.2=192.168.40.152:2888:3888
server.3=192.168.40.153:2888:3888
----------------------------------------------------------------------------------------
  1. 配置Zookeeper启动时所识别的服务器编号文件
ZKA服务器:
[root@ZKA ~]# echo "1" > /usr/local/zookeeper/data/myid
 
ZKB服务器:
[root@ZKB ~]# echo "2" > /usr/local/zookeeper/data/myid
 
ZKC服务器:
[root@ZKC ~]# echo "3" > /usr/local/zookeeper/data/myid
  1. 编辑防火墙配置文件(3台)
[root@ZKA ~]# vi /etc/sysconfig/iptables
##添加下面三句话到默认的22端口这条规则的下面
-------------------------------------------------------------------------------------------------------------------
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT
-------------------------------------------------------------------------------------------------------------------
##最后重启防火墙使配置生效
[root@elk-node2 ~]#systemctl restart iptables.service

##查看防火墙状态
[root@elk-node2 ~]systemctl status iptables.service
  1. 启动、检测Zookeeper (3台)
##启动Zookeeper
[root@elk-node2 ~]# /usr/local/zookeeper/bin/zkServer.sh start

##启动后检测Zookeeper状态
[root@elk-node2 ~]#/usr/local/zookeeper/bin/zkServer.sh status

检测Zookeeper的端口:
[root@elk-node2 ~]# netstat -an | grep -E "2181|2888|3888"

##测试Zookeeper
[root@elk-node2 ~]#/usr/local/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181

[root@elk-node2 ~]# /usr/local/zookeeper/bin/zkCli.sh -server 192.168.40.151:2181
[root@elk-node2 ~]# /usr/local/zookeeper/bin/zkCli.sh -server 192.168.40.152:2181
[root@elk-node2 ~]# /usr/local/zookeeper/bin/zkCli.sh -server 192.168.40.153:2181

8.1 配置Zookeeper服务开机自动启动(3台) --與8.2 二選一

shell> touch /etc/init.d/zookeeper
shell> chmod +x /etc/init.d/zookeeper
shell> vim /etc/init.d/zookeeper
#!/bin/bash
#chkconfig: 2345 10 90
#description: service zookeeper
export JAVA_HOME=/usr/java/jdk1.8.0_181
export ZOO_LOG_DIR=/usr/local/zookeeper/log
ZOOKEEPER_HOME=/usr/local/zookeeper

case  "$1"   in
    start)
        ${ZOOKEEPER_HOME}/bin/zkServer.sh start
        ;;
    start-foreground)
        ${ZOOKEEPER_HOME}/bin/zkServer.sh start-foreground
        ;;
    stop)
        ${ZOOKEEPER_HOME}/bin/zkServer.sh stop
        ;;
    status)
        ${ZOOKEEPER_HOME}/bin/zkServer.sh status
        ;;
    restart)
        ${ZOOKEEPER_HOME}/bin/zkServer.sh restart
        ;;
    upgrade)
        ${ZOOKEEPER_HOME}/bin/zkServer.sh upgrade
        ;;
    print-cmd)
        ${ZOOKEEPER_HOME}/bin/zkServer.sh print-cmd
        ;;
    *)
        echo "requirestart|start-foreground|stop|status|restart|print-cmd"
    ;;
esac
shell> chkconfig --del zookeeper
shell> chkconfig --add zookeeper

8.2 systemctl开机启动zookeeper (推建)--與8.1 二選一

1. 创建zookeeper.service  在/usr/lib/systemd/system目录下创建文件
vim /usr/lib/systemd/system/zookeeper.service
--------------------------------------------------------
[Unit]
Description=zookeeper
After=syslog.target network.target

[Service]
Type=forking
Environment="JAVA_HOME=/u01/java/jdk1.8.0_181"
Environment="ZOO_LOG_DIR=/usr/local/zookeeper/log"
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart
LimitNOFILE=65536
LimitNPROC=16384
LimitCORE=infinity
LimitMEMLOCK=infinity

[Install]
WantedBy=multi-user.target
--------------------------------------------------------
设置开机启动
systemctl enable zookeeper.service

你可能感兴趣的:(Zookeeper 集群安装)