安装源选择:
qiuxiafei/zk-web:git上使用人群较多的仓库,可以通过直接运行源码和通过docker编译安装包来安装后运行的两种方式开启服务。
tobilg/zookeeper-webui:启动运行docker容器便可提供服务,web界面效果与上面的一致。
我们选择通过第一种安装源安装,并开启服务。
源码直接运行
leiningen安装
下载 lein 并执行如下操作:
$ sudo mv my_path/lein /usr/bin/
$ chmod +x /usr/bin
$ lein
本地运行zk-web
运行如下命令:
$ lein deps # run this if you're using lein 1.x
$ lein run
克隆zk-web仓库
$ git clone git://github.com/qiuxiafei/zk-web.git
修改配置文件
配置 conf/zk-web-conf.clj 文件如下所示
{
:server-port 8989 ;; optional, 8080 by default
:users {
"admin" "hello"
;; map of user -> password
;; you can add more
}
:default-node "0.0.0.0:2181" ;; optional
}
启动zk-web
$ lein deps # run this if you're using lein 1.x
$ lein run
在执行lein run命令后出现如下异常:
log4j:WARN No appenders could be found for logger (org.mortbay.log).
log4j:WARN Please initialize the log4j system properly.
该异常显示log4j没有初始化,解决方法如下:
在../zk-web/target/classes目录下新建log4j.properties文件,并写入如下内容,再次运行后问题解决。(参阅:resolve1,resolve2)
log4j.rootLogger=ERROR, stdout, runwayAppender
# SqlMap logging configuration...
log4j.logger.com.ibatis=DEBUG
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
通过docker构建安装
打包UberJar
运行如下命令:
$ cd zk-web
$ lein uberjar
结果如下:
➜ zk-web git:(master) ✗ lein uberjar
Warning: specified :main without including it in :aot.
Implicit AOT of :main will be removed in Leiningen 3.0.0.
If you only need AOT for your uberjar, consider adding :aot :all into your
:uberjar profile instead.
Compiling zk-web.server
Created /home/topiot/zk-web/target/zk-web-0.2.0.jar
Created /home/topiot/zk-web/target/zk-web-0.2.0-standalone.jar
通过docker构建Debian安装包
运行如下命令:
docker build -t zk-web .
docker run -it --rm -v $(pwd):/usr/src/app zk-web /bin/bash /usr/src/app/build-pkg-with-fpm.sh
运行结果:
➜ zk-web git:(master) ✗ docker build -t zk-web .
Sending build context to Docker daemon 18.65MB
Step 1/6 : FROM debian:wheezy
---> 2d79c539d0db
Step 2/6 : ENV LANG C.UTF-8
---> Running in 000b9d65613e
Removing intermediate container 000b9d65613e
---> 9b3329da7508
Step 3/6 : RUN apt-get update && apt-get install -y wget ca-certificates make ruby-dev gcc && rm -rf /var/lib/apt/lists/*
---> Running in 40f6ae4db0ee
Get:1 http://security.debian.org wheezy/updates Release.gpg [1601 B]
Get:2 http://security.debian.org wheezy/updates Release [52.3 kB]
…………………………
Updating certificates in /etc/ssl/certs... 155 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.
Removing intermediate container 40f6ae4db0ee
---> 8d7c13175636
Step 4/6 : RUN gem install fpm
---> Running in f0507c6732ed
Building native extensions. This could take a while...
Building native extensions. This could take a while...
Successfully installed json-1.8.6
Successfully installed cabin-0.9.0
Successfully installed backports-3.11.4
Successfully installed arr-pm-0.0.10
Successfully installed clamp-1.0.1
Successfully installed ffi-1.9.25
Successfully installed childprocess-0.9.0
Successfully installed io-like-0.3.0
Successfully installed ruby-xz-0.2.3
Successfully installed stud-0.0.23
Successfully installed mustache-0.99.8
Successfully installed insist-1.0.0
Successfully installed dotenv-2.5.0
Successfully installed pleaserun-0.0.30
Successfully installed fpm-1.10.2
15 gems installed
Installing ri documentation for json-1.8.6...
…………………………
Installing RDoc documentation for mustache-0.99.8...
Installing RDoc documentation for insist-1.0.0...
Installing RDoc documentation for dotenv-2.5.0...
Installing RDoc documentation for pleaserun-0.0.30...
Installing RDoc documentation for fpm-1.10.2...
Removing intermediate container f0507c6732ed
---> 42f051484de6
Step 5/6 : RUN mkdir -p /usr/src/app
---> Running in b3dd17d08028
Removing intermediate container b3dd17d08028
---> e5c0f508c60b
Step 6/6 : WORKDIR /usr/src/app
---> Running in 79639e3566df
Removing intermediate container 79639e3566df
---> a50d59315eb2
Successfully built a50d59315eb2
Successfully tagged zk-web:latest
➜ zk-web git:(master) ✗ docker run -it --rm -v $(pwd):/usr/src/app zk-web /bin/bash /usr/src/app/build-pkg-with-fpm.sh
+ name=zk-web
+ version=0.2.0
+ packaging_version=
+ maintainer=@localhost
+ description='zk-web is a web ui for zookeeper'
+ url=https://github.com/qiuxiafei/zk-web
+ arch=all
+ section=mics
+ prefix=/usr/lib
++ pwd
+ origdir=/usr/src/app
+ rm -rf 'zk-web*.deb'
+ '[' -d tmp ']'
+ rm -rf tmp
+ mkdir -p tmp
+ pushd tmp
/usr/src/app/tmp /usr/src/app
+ mkdir -p zk-web
+ cd zk-web
+ mkdir -p build/usr/lib/zk-web
+ mkdir -p build/etc/systemd/system
+ cp /usr/src/app/debian/zk-web.service build/etc/systemd/system
+ cp /usr/src/app/target/zk-web-0.2.0-standalone.jar build/usr/lib/zk-web
+ ln -s zk-web-0.2.0-standalone.jar build/usr/lib/zk-web/zk-web-standalone.jar
+ cd build
+ fpm -t deb -n zk-web -v 0.2.0 --description 'zk-web is a web ui for zookeeper' --category mics '--url={https://github.com/qiuxiafei/zk-web}' -a all --vendor '' --deb-user root --deb-group root -m @localhost --before-install /usr/src/app/debian/zk-web.preinst --after-install /usr/src/app/debian/zk-web.postinst --after-remove /usr/src/app/debian/zk-web.postrm --prefix=/ -s dir -d default-jre-headless -- .
Debian packaging tools generally labels all files in /etc as config files, as mandated by policy, so fpm defaults to this behavior for deb packages. You can disable this default behavior with --deb-no-default-config-files flag {:level=>:warn}
Created package {:path=>"zk-web_0.2.0_all.deb"}
+ mv zk-web_0.2.0_all.deb /usr/src/app
+ popd
/usr/src/app
+ dpkg -c zk-web_0.2.0_all.deb
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./etc/
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./etc/systemd/
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./etc/systemd/system/
-rw-r--r-- 0/0 253 2018-08-31 13:30 ./etc/systemd/system/zk-web.service
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./usr/
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./usr/lib/
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./usr/lib/zk-web/
lrwxrwxrwx 0/0 0 2018-08-31 13:30 ./usr/lib/zk-web/zk-web-standalone.jar -> zk-web-0.2.0-standalone.jar
-rw-r--r-- 0/0 13088347 2018-08-31 13:30 ./usr/lib/zk-web/zk-web-0.2.0-standalone.jar
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./usr/share/
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./usr/share/doc/
drwxr-xr-x 0/0 0 2018-08-31 13:30 ./usr/share/doc/zk-web/
-rw-r--r-- 0/0 131 2018-08-31 13:30 ./usr/share/doc/zk-web/changelog.gz
➜ zk-web git:(master) ✗ docker ps
通过.deb包安装zk-web:
运行如下命令
$ sudo dpkg -i zk-web_0.1.0-SNAPSHOT_all.deb
$ sudo systemctl start zk-web
运行结果:
➜ zk-web git:(master) ✗ sudo dpkg -i zk-web_0.2.0_all.deb
[sudo] password for topiot:
Selecting previously unselected package zk-web.
(Reading database ... 70256 files and directories currently installed.)
Preparing to unpack zk-web_0.2.0_all.deb ...
Creating zk-web user account and group
Making sure zk-web user is unlocked
Unpacking zk-web (0.2.0) ...
Setting up zk-web (0.2.0) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
➜ zk-web git:(master) ✗ sudo systemctl start zk-web
➜ zk-web git:(master) ✗ sudo systemctl enable zk-web
Created symlink from /etc/systemd/system/multi-user.target.wants/zk-web.service to /etc/systemd/system/zk-web.service.
➜ zk-web git:(master) ✗
使能zk-web服务自动重启功能:
命令如下:
sudo systemctl enable zk-web
运行结果:
➜ zk-web git:(master) ✗ sudo systemctl enable zk-web
Created symlink from /etc/systemd/system/multi-user.target.wants/zk-web.service to /etc/systemd/system/zk-web.service.
➜ zk-web git:(master) ✗
通过 http://[ip]:[port] 打开管理页面如下所示: