安装zookeeper
- 在/usr/local目录中新建一个zookeeper目录
mkdir zookeeper
- 将zookeeper-3.4.11.tar.gz移动到zookeeper,解压
tar -zxvf zookeeper-3.4.11.tar.gz
- *在/usr/local/zookeeper/zookeeper-3.4.11中新建一下目录
mkdir data
mkdir logs
- 把zookeeper-3.4.11/conf目录中zoo_sample.cfg拷贝为zoo.cfg
cp zoo_sample.cfg zoo.cfg
- 修改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/zookeeper/zookeeper-3.4.11/data
dataLogDir=/usr/local/zookeeper/zookeeper-3.4.11/logs
# the port at which the clients will connect
clientPort=2181
#ip填写注册中心服务器
server.1=ip:2888:3888
# 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
- 在/usr/local/zookeeper/zookeeper-3.4.11/data创建myid文件
vim myid
内容填写:1
- 配置环境变量
# 打开环境配置
vim /etc/profile
# zookeeper
export ZOOKEEPER_HOME=/usr/local/zookeeper/zookeeper-3.4.11
export PATH=$ZOOKEEPER_HOME/bin:$PATH
# 生效配置
source /etc/profile
- 配置防火墙
centos7没有iptables防火墙文件
1、首先要停止 firewalld 服务,输入下面的命令:
systemctl stop firewalld.service
然后要禁止 firewalld 服务在系统启动的时候自动启动, 输入下面的命令:
2、systemctl disable firewalld.server
如果卸载:
yum remove firewalld -y
3、CentOS 7 安装 iptables 防火墙
安装iptables 包
yum install iptables-services
4、设置iptables 防火墙服务开机自动启动
systemctl enable iptables
5、开启服务
systemctl start iptables.service
6、重启防火墙使配置生效
systemctl restart iptables.service
7、检查是否安装了iptables
service iptables status
8、编辑iptables
vim /etc/sysconfig/iptables
然后增加:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2181 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2888 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3888 -j ACCEPT
- 启用并测试zookeeper
在/usr/local/zookeeper/zookeeper-3.4.11/bin中
启动
zkServer.sh start
重启
zkServer.sh restart
停止
zkServer.sh start
查看状态
zkServer.sh status
·输入命令查看进程
jps
·可以看到
15097 QuorumPeerMain
26383 Jps
·QuorumPeerMain是zookeeper进程,启动正常
查看zookeeper服务输入的日志:
cd /usr/local/zookeeper/zookeeper-3.4.11/bin
tail -f zookeeper.out
- 服务配置
cd /etc/init.d/目录下,创建zookeeper文件
#!/bin/bash
export JAVA_HOME=/usr/local/java/jdk1.8.0_162
export PATH=$JAVA_HOME/bin:$PATH
#chkconfig:2345 20 90
#description:zookeeper
#processname:zookeeper
case $1 in
start) su root /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh start;;
stop) su root /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh stop;;
status) su root /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh status;;
restart) su root /usr/local/zookeeper/zookeeper-3.4.11/bin/zkServer.sh restart;;
*) echo "require start|stop|status|restart" ;;
esac
添加权限
chmod +x zookeeper
配置成服务
chkconfig --add zookeeper
开机启动
chkconfig zookeeper on
启动
service zookeeper start
停止
service zookeeper stop
重启
service zookeeper restart
状态
service zookeeper status