Docker setup the development environment Collection

Since contact with Docker, it had a keen interest in it, usually require development environment also try to build Docker, compared to the virtual machine does a lot of convenience, this is mainly the record about Docker usually use to build a nice development environment in development. Where all applications are created using a docker placed under dockerapps directory.

Version: 3.5

1.1 Single node deployment

Create a zookeeper directory under dockerapps. This directory contains a directory for data zookeeper persistent application data, comprising a configuration file to configure zoo.cfg zookeeper application, comprising a promoter for zk start.sh single node. The directory structure is shown below:

1
2
3
4
zookeeper/
├── data
├── start.sh
└── zoo.cfg

1.1.1 Creating persistent data directory data

Zk zookeeper created in the directory data persistence directory

1
mkdir data

1.1.2 Creating zoo.cfg profile

Zk created in the directory configuration file zookeeper zoo.cfg, reads as follows:

1
2
3
clientPort=2181
dataDir=/data
dataLogDir=/data/log

1.1.3 create a startup script start.sh

In the first zookeeper directory created zk startup script start.sh, reads as follows:

1
2
3
docker stop zookeeper
docker rm zookeeper
docker run -itd -p 2181:2181 -v `pwd`/data:/data --name zookeeper -v `pwd`/zoo.cfg:/conf/zoo.cfg zookeeper:3.5

1.1.4 Start Service

After completion of the above steps can be started in a single node zk. Execution start.sh

1
sh start.sh

View docker process

1
docker ps
1
2
3

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
39a6cf356e1a zookeeper:3.5 "/docker-entrypoint.…" 11 seconds ago Up 10 seconds 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp zookeeper

Zk into the client zkCli

1
docker exec -it 39a6cf356e1a bin/zkCli.sh

1.2 cluster deployment

For zk cluster deployment, we can use the docker-compose orchestrate. Zk-cluster to create a directory used to store documents related to cluster in the zookeeper directory. Here, for example with three nodes.

1
mkdir zk-cluster

1.2.1 Creating persistent data folder

Here are created data1, data2, data3 to persist data three nodes.

1
mkdir data1 data2 data3

Myid and create files in each directory data, content, respectively, 2, 3

1.2.2 Creating zk profile zoo.cfg

This configuration file can use the same file can also be similar to the data, were created here for simplicity, use the same configuration file, as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 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< 大专栏  Docker搭建开发环境合集/span>
# example sakes.
dataDir=/data
dataLogDir=/data/log
# the port at which the clients will connect
clientPort=2181
# 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
#
# 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
server.1=localhost:2881:3881
server.1=zookeeper1:2888:3888
server.2=zookeeper2:2888:3888
server.3=zookeeper3:2888:3888
4lw.commands.whitelist=*

1.2.3 Creating layout files docker-compose.yml

In zk-cluster directory from creating layout files, as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
version: '2'
services:
zoo1:
image: zookeeper:3.5
restart: always
container_name: zookeeper1
volumes:
- ./data1:/data
- ./zoo.cfg:/conf/zoo.cfg
ports:
- "2181:2181"

zoo2:
image: zookeeper:3.5
restart: always
container_name: zookeeper2
volumes:
- ./data2:/data
- ./zoo.cfg:/conf/zoo.cfg
ports:
- "2182:2181"

zoo3:
image: zookeeper:3.5
restart: always
container_name: zookeeper3
volumes:
- ./data3:/data
- ./zoo.cfg:/conf/zoo.cfg
ports:
- "2183:2181"

1.2.4 创建集群启动文件start.sh

内容如下:

1
2
docker-compose stop
docker-compose -p zk-cluster up -d

1.2.5 启动集群

1
sh start.sh
1
2
3
Starting zookeeper1 ... done
Starting zookeeper3 ... done
Starting zookeeper2 ... done

使用四字命令查看集群状态

1
echo stat |nc localhost 2181
1
2
3
4
5
6
7
8
9
10
11
12
Zookeeper version: 3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT
Clients:
/172.18.0.1:41462[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/0/0
Received: 1
Sent: 0
Connections: 1
Outstanding: 0
Zxid: 0x0
Mode: standalone
Node count: 5

Guess you like

Origin www.cnblogs.com/dajunjun/p/11694017.html