开整!!
第一步,准备3台虚拟机,系统为CentOS 7,如下
IP | 角色 |
---|---|
172.16.31.191 | zookeeper-1 |
172.16.31.192 | zookeeper-2 |
172.16.31.193 | zookeeper-3 |
第二步,在虚拟机上装好docker并启动(不会使用 docker 的话请先百度了解一下),3台虚拟机都要
第三步,创建存储目录 /usr/local/docker/zookeeper,3台虚拟机都要,如下
mkdir /usr/local/docker/zookeeper
并创建相关挂载目录,3台虚拟机都要,如下
mkdir /usr/local/docker/zookeeper/config
mkdir /usr/local/docker/zookeeper/data
第四步,在 /usr/local/docker/zookeeper/config 目录下新建 zoo.cfg 配置文件,3台虚拟机都要,内容一样,如下
vim /usr/local/docker/zookeeper/config/zoo.cfg
zoo.cfg
clientPort=2181
dataDir=/data
dataLogDir=/data/log
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
4lw.commands.whitelist=*
server.1=172.16.31.191:2888:3888
server.2=172.16.31.192:2888:3888
server.3=172.16.31.193:2888:3888
另外,还要在 /usr/local/docker/zookeeper/data 目录下新建 myid 配置文件,里面的内容编号不能重复,3台虚拟机都要,如下
172.16.31.191
# 创建 myid 配置文件
touch /usr/local/docker/zookeeper/data/myid
# 添加配置 1 ,此编号代表选举的时候的编号
echo 1 > /usr/local/docker/zookeeper/data/myid
172.16.31.192
# 创建 myid 配置文件
touch /usr/local/docker/zookeeper/data/myid
# 添加配置 2 ,此编号代表选举的时候的编号
echo 2 > /usr/local/docker/zookeeper/data/myid
172.16.31.193
# 创建 myid 配置文件
touch /usr/local/docker/zookeeper/data/myid
# 添加配置 3 ,此编号代表选举的时候的编号
echo 3 > /usr/local/docker/zookeeper/data/myid
第五步,docker方式启动 Zookeeper 3.6.1,3台虚拟机都要,如下
172.16.31.191
docker run --network host -v /usr/local/docker/zookeeper/data:/data -v /usr/local/docker/zookeeper/conf/zoo.cfg:/conf/zoo.cfg --name zookeeper-1 -d zookeeper:3.6.1
172.16.31.192
docker run --network host -v /usr/local/docker/zookeeper/data:/data -v /usr/local/docker/zookeeper/conf/zoo.cfg:/conf/zoo.cfg --name zookeeper-2 -d zookeeper:3.6.1
172.16.31.193
docker run --network host -v /usr/local/docker/zookeeper/data:/data -v /usr/local/docker/zookeeper/conf/zoo.cfg:/conf/zoo.cfg --name zookeeper-3 -d zookeeper:3.6.1
第五步,任选一台虚拟机配置 zookeeper-ui 可视化管理界面,我选的是 172.16.31.191,虚拟机需要配置好 jdk 环境!如下
1、上 GitHub 拉取最新代码: https://github.com/DeemOpen/zkui
git clone https://github.com/DeemOpen/zkui.git
2、打开项目,进入根目录进行编译打包
mvn clean install
3、打包完后将 target 目录下的 zkui-2.0-SNAPSHOT-jar-with-dependencies.jar 包上传到 /usr/local/docker/zookeeper/zookeeper-ui 目录下
4、进入 /usr/local/docker/zookeeper/zookeeper-ui 目录,创建 config.cfg 配置文件,如下
cd /usr/local/docker/zookeeper/zookeeper-ui
vim config.cfg
config.cfg
#Server Port
serverPort=9090
#Comma seperated list of all the zookeeper servers
zkServer=172.16.31.191:2181,172.16.31.192:2181,172.16.31.193:2181
#Http path of the repository. Ignore if you dont intent to upload files from repository.
scmRepo=http://myserver.com/@rev1=
#Path appended to the repo url. Ignore if you dont intent to upload files from repository.
scmRepoPath=//appconfig.txt
#if set to true then userSet is used for authentication, else ldap authentication is used.
ldapAuth=false
ldapDomain=mycompany,mydomain
#ldap authentication url. Ignore if using file based authentication.
ldapUrl=ldap://:/dc=mycom,dc=com
#Specific roles for ldap authenticated users. Ignore if using file based authentication.
ldapRoleSet={"users": [{ "username":"domain\\user1" , "role": "ADMIN" }]}
userSet = {"users": [{ "username":"admin" , "password":"admin","role": "ADMIN" },{ "username":"appconfig" , "password":"appconfig","role": "USER" }]}
#Set to prod in production and dev in local. Setting to dev will clear history each time.
env=prod
jdbcClass=org.h2.Driver
jdbcUrl=jdbc:h2:zkui
jdbcUser=root
jdbcPwd=manager
#If you want to use mysql db to store history then comment the h2 db section.
#jdbcClass=com.mysql.jdbc.Driver
#jdbcUrl=jdbc:mysql://localhost:3306/zkui
#jdbcUser=root
#jdbcPwd=manager
loginMessage=Please login using admin/manager or appconfig/appconfig.
#session timeout 5 mins/300 secs.
sessionTimeout=300
#Default 5 seconds to keep short lived zk sessions. If you have large data then the read will take more than 30 seconds so increase this accordingly.
#A bigger zkSessionTimeout means the connection will be held longer and resource consumption will be high.
zkSessionTimeout=5
#Block PWD exposure over rest call.
blockPwdOverRest=false
#ignore rest of the props below if https=false.
https=false
keystoreFile=/home/user/keystore.jks
keystorePwd=password
keystoreManagerPwd=password
# The default ACL to use for all creation of nodes. If left blank, then all nodes will be universally accessible
# Permissions are based on single character flags: c (Create), r (read), w (write), d (delete), a (admin), * (all)
# For example defaultAcl={"acls": [{"scheme":"ip", "id":"192.168.1.192", "perms":"*"}, {"scheme":"ip", id":"192.168.1.0/24", "perms":"r"}]
defaultAcl=
# Set X-Forwarded-For to true if zkui is behind a proxy
X-Forwarded-For=false
5、保存后启动项目,如下
nohup java -jar zkui-2.0-SNAPSHOT-jar-with-dependencies.jar &
第六步,访问 172.16.31.191:9090 查看集群状态,如下
注意,账号密码在 config.cfg 里面的 userSet 配置选项,我配置为 admin/admin,如下能查到各个节点的信息,则表示集群部署成功