安装zookeeper
1.在宿主机上创建目录:
mkdir -p /data1/zookeeper/2181/data;
mkdir -p /data1/zookeeper/2181/logs;
mkdir -p /data1/zookeeper/2182/data;
mkdir -p /data1/zookeeper/2182/logs;
mkdir -p /data1/zookeeper/2183/data;
mkdir -p /data1/zookeeper/2183/logs;
#加权限
chmod 777 -R /data1/zookeeper;
2.启动容器命名为zookeeper_container
docker run -it --name=zookeeper_container --net=host -v /data1:/data1 centos /bin/bash
3.安装
基础工具:
yum -y install java && yum -y install wget;
下载
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz
解压
tar -zxvf zookeeper-3.3.6.tar.gz
复制到/usr/local/zookeeper目录:
mv zookeeper-3.3.6 /usr/local/zookeeper
在宿主机的2181,2182,2183目录下新增配置文件zoo.cfg
2183/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=/data1/zookeeper/2183/data
dataLogDir=/data1/zookeeper/2183/logs
# the port at which the clients will connect
clientPort=2183
server.1= 10.210.234.203:2881:3881
server.2= 10.210.234.203:2882:3882
server.3= 10.210.234.203:2883:3883
2182/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=/data1/zookeeper/2182/data
dataLogDir=/data1/zookeeper/2182/logs
# the port at which the clients will connect
clientPort=2182
server.1= 10.210.234.203:2881:3881
server.2= 10.210.234.203:2882:3882
server.3= 10.210.234.203:2883:3883
2181/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=/data1/zookeeper/2181/data
dataLogDir=/data1/zookeeper/2181/logs
# the port at which the clients will connect
clientPort=2181
server.1= 10.210.234.203:2881:3881
server.2= 10.210.234.203:2882:3882
server.3= 10.210.234.203:2883:3883
指定集群编号:
echo 1 > /data1/zookeeper/2181/data/myid;
echo 2 > /data1/zookeeper/2182/data/myid;
echo 3 > /data1/zookeeper/2183/data/myid;
启动服务:
2183
export ZOOCFGDIR=/data1/zookeeper/2183;
export ZOO_LOG_DIR=/data1/zookeeper/2183;
/usr/local/zookeeper/bin/zkServer.sh start;
2182:
export ZOOCFGDIR=/data1/zookeeper/2182;
export ZOO_LOG_DIR=/data1/zookeeper/2182;
/usr/local/zookeeper/bin/zkServer.sh start;
2181:
export ZOOCFGDIR=/data1/zookeeper/2181;
export ZOO_LOG_DIR=/data1/zookeeper/2181;
/usr/local/zookeeper/bin/zkServer.sh start;
在宿主机上判断命令是否启动成功:
netstat -apn | grep 2181;
netstat -apn | grep 2182;
netstat -apn | grep 2183;
如果都能看到相应的进程则启动成功,安装完毕
2.安装zkdash(zookeeper管理工具)
1.准备工作:
在宿主机上创建目录:
mkdir -p /data1/zkdash;
chmod 777 /data1;
2.启动容器:
docker run -itd --net=host --name=zkdash -v /data1:/data1 -v /data1/zkdash:/usr/local/zkdash/conf centos /bin/bash
3.安装基础工具:
yum -y install wget && yum -y install git;
yum -y install epel-release;
yum -y install python-pip;
pip install --upgrade pip;
4.python安装(如果没有则安装,版本是2.7.5):
yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expat-devel
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
./configure --prefix=/usr/local/python27
make && make install
4.克隆zkdash
git clone https://github.com/ireaderlab/zkdash.git /usr/local;
cd /usr/local/zkdash;
pip install -r requirements.txt
5.在宿主机下新增配置文件:conf.yml
内容如下:
# database
DATABASE:
db: 'zkdash'
host: '10.210.234.203'
port: 3306
user: 'root'
passwd: 'root'
# 是否通过QConf获取zookeeper数据(使用该项需要在本地先运行QConf客户端agent)
USE_QCONF: False
# log conf
LOG_ITEMS:
- file: /data1/zkdash/zkdash.log
log_levels:
- DEBUG
- INFO
- WARNING
- ERROR
- CRITICAL
format: '[%(levelname)s %(asctime)s %(filename)s %(lineno)d] %(message)s'
when: 'midnight'
interval: 1
backup_count: 10
backup_suffix: '%Y%m%d'
level: 'DEBUG'
- file: /data1/zkdash/zkdash.error.log
log_levels:
- WARNING
- ERROR
- CRITICAL
format: '[%(levelname)s %(asctime)s %(filename)s %(lineno)d] %(message)s'
when: 'midnight'
interval: 1
backup_count: 30
backup_suffix: '%Y%m%d'
level: 'DEBUG'
5.启动:
python /usr/local/zkdash/bin/syncdb.py >/dev/null 2>/dev/null &
python /usr/local/zkdash/init.py -port=8888 >/dev/null 2>/dev/null &
6.最终效果