Docker安装及应用(mysql,redis,elk,zookeeper,kafka …)部署

Docker安装及应用(mysql,redis,elk,zookeeper,kafka …)部署

1.1 安装Docker

注意:这里安装在CentOS7.x以上的版本,在CentOS6.x的版本中,安装前需要安装其他很多的环境而且Docker很多补丁不支持更新。

(1)yum 包更新到最新

sudo yum update

(2)安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

(3)设置yum源为阿里云

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

(4)安装docker

sudo yum install docker-ce

(5)安装后查看docker版本

docker -v

1.2 配置阿里云加速器

https://cr.console.aliyun.com/cn-shenzhen/mirrors

编辑该文件:

vi /etc/docker/daemon.json  

在该文件中输入如下内容:

{
  "registry-mirrors": ["加速器地址"]
}

1.3 Docker的启动与停止

systemctl命令是系统服务管理器指令

启动docker:

systemctl start docker

停止docker:

systemctl stop docker

重启docker:

systemctl restart docker

查看docker状态:

systemctl status docker

开机启动:

systemctl enable docker

查看docker概要信息

docker info

查看docker帮助文档

docker --help

1.4 应用部署

1.4.1 MySQL部署

下载镜像

docker pull mysql:5.7

运行

 docker run -p 3306:3306 --name mysql \
             -v  $PWD/mydata/mysql/log:/var/log/mysql \
             -v $PWD/mydata/mysql/data:/var/lib/mysql \
             -v $PWD/mydata/mysql/conf:/etc/mysql \
             -e MYSQL_ROOT_PASSWORD=root \
             -d mysql:5.7

修改配置

cat my.cnf

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

进入容器查看配置

docker exec -it mysql /bin/bash
whereis mysql
cat /etc/mysql/my.cnf 

设置启动docker时,即运行mysql

 docker update mysql --restart=always

1.4.2Redis部署

下载镜像

 docker pull redis

运行

mkdir -p /opt/mydata/redis/conf
touch  /opt/mydata/redis/conf/redis.conf
echo "appendonly yes"  >> /mydata/redis/conf/redis.conf
docker run -p 6379:6379 --name redis -v /opt/mydata/redis/data:/data \
           -v /opt/mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
           -d redis redis-server /etc/redis/redis.conf

进入容器查看配置

docker exec -it redis redis-cli

设置启动docker时,即运行redis

 docker update redis --restart=always

1.4.3ELK部署

修改mmap计数大于等于262144的限制,在/etc/sysctl.conf文件最后一行添加

vm.max_map_count=655360
#执行
sysctl -p 

下载并运行镜像

docker run -p 5601:5601 -p 9200:9200 -p 9300:9300 -p 5044:5044 --name elk -d sebp/elk:740

elasticsearch的配置文件

mkdir /opt/elk/elasticsearch/conf
#复制elasticsearch的配置出来
docker cp elk:/etc/elasticsearch/elasticsearch.yml /opt/elk/elasticsearch/conf

修改elasticsearch.yml配置

cluster.name: my-es
thread_pool.bulk.queue_size: 1000
http.cors.enabled: true
http.cors.allow-origin: "*"

logstash的配置文件

mkdir /opt/elk/logstash/conf
#复制logstash的配置出来
docker cp elk:/etc/logstash/conf.d/. /opt/elk/logstash/conf/

创建运行脚本

docker stop elk
docker rm elk

docker run -p 5601:5601 -p 9200:9200 -p 9300:9300 -p 5044:5044 \
    -e LS_HEAP_SIZE="1g" -e ES_JAVA_OPTS="-Xms2g -Xmx2g" \
    -v $PWD/elasticsearch/data:/var/lib/elasticsearch \
    -v $PWD/elasticsearch/plugins:/opt/elasticsearch/plugins \
    -v $PWD/logstash/conf:/etc/logstash/conf.d \
    -v $PWD/logstash/patterns:/opt/logstash/patterns \
    -v $PWD/elasticsearch/conf/elasticsearch.yml:/etc/elasticsearch/elasticsearch.yml \
    -v $PWD/elasticsearch/log:/var/log/elasticsearch \
    -v $PWD/logstash/log:/var/log/logstash \
    --name elk \
    -d sebp/elk:740

Zookeeper部署

下载镜像

docker pull wurstmeister/zookeeper

启动镜像

docker stop zookeeper
docker rm zookeeper
docker run -d \
           -v /home/ict/zookeeper/data:/data \
          -v /home/ict/zookeeper/log:/datalog \
          -e ZOO_MY_ID=1 \
          -p 2181:2181 \
         --name=zookeeper \
         wurstmeister/zookeeper

Kafka部署

下载镜像

docker pull wurstmeister/kafka

启动镜像

docker stop kafka
docker rm kafka
docker run -d --name kafka \
	      -p 9092:9092 \
          --env KAFKA_ADVERTISED_HOST_NAME=localhost \
          --env KAFKA_ZOOKEEPER_CONNECT=172.17.0.1:2181 \
          --env KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
          --env KAFKA_HEAP_OPTS="-Xmx256M -Xms128M" \
          wurstmeister/kafka

Prometheus部署

下载镜像

docker pull prom/prometheus

启动镜像

docker run -d --name prometheus -p 9090:9090 prom/prometheus

创建文件夹

mkdir conf
mkdir data
chmod 777 -R data

拷贝配置文件

docker cp prometheus:/etc/prometheus/prometheus.yml conf/

修改配置文件

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
      labels:
        instance: prometheus

重新启动镜像

docker stop prometheus
docker rm prometheus
docker run \
        -p 9090:9090 \
        -v $PWD/conf/prometheus.yml:/etc/prometheus/prometheus.yml \
        -v $PWD/data:/prometheus \
        --name prometheus \
        -d prom/prometheus \
        --config.file=/etc/prometheus/prometheus.yml

Grafana部署

直接运行

docker run -d \
      -p 3000:3000 \
      --name=grafana \
      -v $PWD/conf/grafana.ini:/etc/grafana/grafana.ini/grafana.ini \
      -v $PWD/plugins/:/var/lib/grafana/plugins \
      -e "GF_SECURITY_ADMIN_PASSWORD=admin" \
      -e "GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource,raintank-worldping-app,grafana-piechart-panel" \
      -v $PWD/data:/var/lib/grafana \
      grafana/grafana

你可能感兴趣的:(Docker安装及应用(mysql,redis,elk,zookeeper,kafka …)部署)