【原創】運維基礎之Docker(2)經過docker部署zookeeper nginx tomcat java redis kibana/elasticsearch/logstash mysql ka

經過docker能夠從頭開始構建集羣,也能夠將現有集羣(配置以及數據)平滑的遷移到docker部署;html

1 docker部署zookeeper

# usermod -G docker zookeeper
# mkdir /data
# chown zookeeper.zookeeper /data
# echo 1 > /data/myid
# su - zookeeper
$ docker run --name zookeeper --restart always -p 2181:2181 -p 2888:2888 -p 3888:3888 -e ZOO_LOG4J_PROP="INFO,ROLLINGFILE" -v /var/log/zookeeper:/logs -v /conf/zoo.cfg:/conf/zoo.cfg -v /data:/data -v /etc/hosts:/etc/hosts:ro -d zookeeperjava

其中zoo.cfg使用正常的集羣配置便可,須要掛載配置文件、日誌目錄、數據目錄、host文件等,node

注意:mysql

1)zoo.cfg中的server.*配置能夠經過 -e ZOO_SERVERS=server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 代替,其中本機的ip要配置爲0.0.0.0,不然啓動的時候會綁定端口失敗nginx

2)/data/myid文件也能夠經過 -e ZOO_MY_ID=1 代替git

 

參考:https://docs.docker.com/samples/library/zookeeper/web

 

2 docker部署nginx

# docker run --name nginx --restart always -p 80:80 -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro -v /etc/nginx/passwd:/etc/nginx/passwd:ro -v /var/log/nginx:/var/log/nginx -d nginxredis

其中nginx.conf使用正常的配置便可,須要掛載配置文件、日誌目錄、密碼文件等,有須要還能夠掛載html目錄 -v /some/content:/usr/share/nginx/html:ro;sql

 

參考:https://docs.docker.com/samples/library/nginx/docker

 

3 docker部署tomcat

$ docker run -d --name tomcat -p 8080:8080 -v /dir/webapps:/usr/local/tomcat/webapps -v /dir/logs:/usr/local/tomcat/logs tomcat:8.0

 

參考:https://docs.docker.com/samples/library/tomcat/

 

4 docker部署redis

$ docker run -d --name redis -p 6379:6379 -v /redis/data/dir:/data redis redis-server --appendonly yes

 

參考:https://docs.docker.com/samples/library/redis/

 

5 docker部署java應用

$ docker run -d --name java_app -v /dir/app:/app openjdk java -cp /app/app.jar app.AppClass

參考: https://hub.docker.com/_/openjdk

 

6 docker部署elk

因爲kibana、elasticsearch、logstash3個image內部分別使用各自的用戶啓動,而且uid和gid均爲1000,爲了不衝突,使用一個新的elk組,gid爲1000,將3個用戶都添加到組中,保證對目錄的寫權限

# groupadd -g 1000 elk
# usermod -G elk elasticsearch
# usermod -G elk logstash
# usermod -G elk kibana
# chgrp elk $dir

kibana

# usermod -G docker kibana
# su - kibana
$ docker run --name kibana -p 5601:5601 -v /var/log/kibana:/usr/share/kibana/log -v /etc/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml -d kibana:6.6.0

其中kibana.yml使用正常配置便可,須要掛載配置文件等;

若是分配的內存太少,kibana可能進程直接消失,並且查不到任何logs,至少512m以上;

 

參考:

https://docs.docker.com/samples/library/kibana/

https://www.elastic.co/guide/en/kibana/current/docker.html 

elasticsearch

# usermod -G docker elasticsearch
# chgrp -R elk /opt/lmm/es_data/
# su - elasticsearch
$ docker run -d --name logstash -p 9600:9600 -v /var/log/nginx:/var/log/nginx:ro -v /var/log/logstash:/usr/share/logstash/logs -v /etc/logstash/GeoLite2-City.mmdb:/usr/share/logstash/config/GeoLite2-City.mmdb -v /etc/logstash/nginx_access.conf:/usr/share/logstash/pipeline/logstash.conf docker.elastic.co/logstash/logstash:6.6.0

其中elasticsearch.yml使用正常配置便可,須要設置宿主機ip,掛載配置文件、數據目錄、日誌目錄等;

注意:
1)必定要保證索引目錄的owner或者group的id爲1000(此處設置group爲1000),不然會報failed to obtain node locks或者AccessDeniedException
2)必定要設置network.publish_host爲宿主機ip

The container runs Elasticsearch as user elasticsearch using uid:gid 1000:1000. Bind mounted host directories and files, such as custom_elasticsearch.yml above, need to be accessible by this user. For the data and log dirs, such as /usr/share/elasticsearch/data, write access is required as well.

 

參考:

https://docs.docker.com/samples/library/elasticsearch/

https://www.elastic.co/guide/en/elasticsearch/reference/6.6/docker.html

logstash

# usermod -G docker logstash
# chgrp -R elk /var/log/logstash
# su - logstash
$ docker run -d --name logstash -p 9600:9600 -v /var/log/nginx:/var/log/nginx:ro -v /var/log/logstash:/usr/share/logstash/logs -v /etc/logstash/GeoLite2-City.mmdb:/usr/share/logstash/config/GeoLite2-City.mmdb -v /etc/logstash/nginx_access.conf:/usr/share/logstash/pipeline/logstash.conf docker.elastic.co/logstash/logstash:6.6.0

其中logstash.conf使用正常的配置便可;要保證對日誌目錄可寫;

Bind-mounted configuration files will retain the same permissions and ownership within the container that they have on the host system. Be sure to set permissions such that the files will be readable and, ideally, not writeable by the container’s logstash user (UID 1000). 

 

參考:

https://docs.docker.com/samples/library/logstash/

https://www.elastic.co/guide/en/logstash/current/docker-config.html

 

7 docker部署mysql

$ docker run -d --name mysql -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql -v /etc/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.7.25

其中my.cnf使用正常配置便可,須要掛載數據目錄;

 

參考:https://docs.docker.com/samples/library/mysql/

 

8 docker部署kafka

$ docker run -d --name kafka -p 9092:9092 -e KAFKA_BROKER_ID=1 -e KAFKA_LOG_DIRS=/kafka/kafka-logs -e KAFKA_ZOOKEEPER_CONNECT=$zk_server:2181 -e KAFKA_ADVERTISED_HOST_NAME=$host_ip -e KAFKA_AUTO_CREATE_TOPICS_ENABLE=true -v /data/kafka-logs:/kafka/kafka-logs wurstmeister/kafka

不使用配置文件,配置經過參數傳遞,須要掛載數據目錄;

 

參考:https://hub.docker.com/r/wurstmeister/kafka

 

9 docker部署mesos

mesos-master

$ docker run -d --name mesos-master1 --net=host --restart=always -p 5050:5050 -e MESOS_HOSTNAME=192.168.0.1 -e MESOS_IP=192.168.0.1 -e MESOS_ZK=zk://192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181/mesos -e MESOS_PORT=5050 -e MESOS_LOG_DIR=/var/log/mesos -e MESOS_QUORUM=1 -e MESOS_REGISTRY=in_memory -e MESOS_WORK_DIR=/var/lib/mesos mesoscloud/mesos-master

逐臺修改MESOS_HOSTNAME、MESOS_IP

 

參考:https://hub.docker.com/r/mesosphere/mesos-master

mesos-slave

$ docker run -d --name=mesos-slave1 --net=host --restart=always --pid=host --privileged=true -e MESOS_HOSTNAME=192.168.0.1 -e MESOS_IP=192.168.0.1 -e MESOS_MASTER=zk://192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181/mesos -e MESOS_CONTAINERIZERS=docker,mesos -v /usr/bin/docker:/usr/bin/docker -v /dev:/dev -v /var/run/docker.sock:/var/run/docker.sock -v /var/log/mesos:/var/log/mesos -v /tmp/mesos:/tmp/mesos mesoscloud/mesos-slave

逐臺修改MESOS_HOSTNAME、MESOS_IP

 

參考:https://hub.docker.com/r/mesosphere/mesos-slave

marathon

$ docker run -d --name marathon --net host --restart=always -e MARATHON_HOSTNAME=192.168.0.1 -e MARATHON_HTTPS_ADDRESS=192.168.0.1 -e MARATHON_HTTP_ADDRESS=192.168.0.1 -e MARATHON_MASTER=zk://192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181/mesos -e MARATHON_ZK=zk://192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181/marathon mesoscloud/marathon

逐臺修改MARATHON_HOSTNAME、MARATHON_HTTPS_ADDRESS、MARATHON_HTTP_ADDRESS

 

參考:https://hub.docker.com/r/mesosphere/marathon

 

10 docker部署ftp

$ docker run -d --name ftp --restart always -v $ftp_dir:/home/vsftpd -p 20:20 -p 21:21 -p 47400-47470:47400-47470 -e FTP_USER=user -e FTP_PASS=pass -e PASV_ADDRESS=$ip bogem/ftp

 

參考:https://hub.docker.com/r/bogem/ftp

 

11 docker部署git

docker pull store/gitlab/gitlab-ce:11.10.4-ce.0

參考:

https://hub.docker.com/_/gitlab-community-edition?tab=description

 

12 其餘

https://docs.docker.com/samples/library/cassandra/

https://docs.docker.com/samples/library/flink/

https://docs.docker.com/samples/library/influxdb/

https://docs.docker.com/samples/library/alpine/

相關文章
相關標籤/搜索