Docker容器中安装MySQL、Redis、Nginx、RabbitMQ、MongoDB、Elasticsearch、Logstash、Kibana,基于CentOS7.6。
1.Docker环境安装
1
| yum install -y yum-utils device-mapper-persistent-data lvm2
|
1
| yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
|
2.Java安装
1 2 3 4 5 6 7
| /** ** run 启动一个镜像容器 ** -d 后台运行该容器 ** -I 以交互模式运行容器,通常与 -t 同时使用 ** -t 为容器重新分配一个伪输入终端 */ docker run -d -it --name java java:8
|
3.MySQL安装
1 2 3 4 5 6
| docker run -p 3306:3306 --name=mysql \ -v /data/mysql/log:/var/log/mysql \ -v /data/mysql/data:/var/lib/mysql \ -v /data/mysql/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.7
|
- 参数说明
- -p 3306:3306:将容器的3306端口映射到主机的3306端口
- -v /data/mysql/conf:/etc/mysql:将配置文件夹挂在到主机
- -v /data/mysql/log:/var/log/mysql:将日志文件夹挂载到主机
- -v /data/mysql/data:/var/lib/mysql/:将数据文件夹挂载到主机
- -e MYSQL_ROOT_PASSWORD=root:初始化root用户的密码
- 进入运行MySQL的docker容器:
1
| docker exec -it mysql /bin/bash
|
1
| mysql -uroot -proot --default-character-set=utf8
|
1
| create database mall character set utf8
|
- 安装上传下载插件,并将document/sql/mall.sql上传到Linux服务器上:
- 将mall.sql文件拷贝到mysql容器的/目录下:
1
| docker cp /mydata/mall.sql mysql:/
|
1
| use mall; source /mall.sql;
|
- 创建一个reader:123456帐号并修改权限,使得任何ip都能访问:
1
| grant all privileges on *.* to 'reader' @'%' identified by '123456';
|
4.Redis安装
1 2 3
| docker run -p 6379:6379 --name=redis \ -v /data/redis/data:/data \ -d redis:5 redis-server --appendonly yes
|
- 进入Redis容器使用redis-cli命令进行连接:
1
| docker exec -it redis redis-cli
|
5.Nginx安装
1 2 3 4
| docker run -p 80:80 --name=nginx \ -v /data/nginx/html:/usr/share/nginx/html \ -v /data/nginx/logs:/var/log/nginx \ -d nginx:1.10
|
1
| docker container cp nginx:/etc/nginx /data/nginx/
|
1
| docker stop nginx docker rm nginx
|
1 2 3 4 5 6
| docker run -p 80:80 --name=nginx \ -v /data/nginx/html:/usr/share/nginx/html \ -v /data/nginx/logs:/var/log/nginx \ -v /data/nginx/conf:/etc/nginx \ -d nginx:1.10
|
6.RabbitMQ安装
- 下载rabbitmq3.7.15的docker镜像:
1
| docker pull rabbitmq:3.7.15
|
1
| docker run -p 5672:5672 -p 15672:15672 --name=rabbitmq \ -d rabbitmq:3.7.15
|
1
| docker exec -it rabbitmq /bin/bash
|
1
| rabbitmq-plugins enable rabbitmq_management
|
- 开启防火墙:
- 查看开启端口列表
firewall-cmd --list-ports
- 查看firewalld状态:
systemctl status firewalld
,如果是dead状态,即防火墙未开启
- 开启防火墙
systemctl start firewalld
- 确认firewalld状态:
systemctl status firewalld
1
| firewall-cmd --zone=public --add-port=15672/tcp --permanent firewall-cmd --reload
|
- 输入账号密码并登录:guest guest
- 创建帐号并设置其角色为管理员:mall mall
7.Elasticsearch安装
- 下载Elasticsearch7.6.2的docker镜像:
1
| docker pull elasticsearch:7.6.2
|
1
| sysctl -w vm.max_map_count=262144
|
1 2 3 4
| mkdir -p /data/elasticsearch/config mkdir -p /data/elasticsearch/data echo "http.host: 0.0.0.0" >/data/elasticsearch/config/elasticsearch.yml chmod -R 777 /data/elasticsearch/
|
1 2 3 4 5 6
| docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \ -e "discovery.type=single-node" \ -e "cluster.name=elasticsearch" \ -v /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins \ -v /data/elasticsearch/data:/usr/share/elasticsearch/data \ -d elasticsearch:7.6.2
|
1 2
| docker: Error response from daemon: driver failed programming external connectivity on endpoint elasticsearch (b4ed5b4df7d4d6c9847f111162ffb9bd34cd2fc3cd11fe047a72e3ca1175a0fb): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 9300 -j DNAT --to-destination 172.17.0.6:9300 ! -i docker0: iptables: No chain/target/match by that name. (exit status 1)).
|
1 2
| iptables -t filter -F iptables -t filter -X
|
1
| systemctl restart docker
|
- 使用上述命令重启es,
docker ps
查看进程,有如下信息说明启动成功
1 2 3
| [root@root elasticsearch]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 743f299c8c90 elasticsearch:7.6.2 "/usr/local/bin/dock…" 7 seconds ago Up 5 seconds 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch
|
1
| docker exec -it elasticsearch /bin/bash
|
1 2 3
| #此命令需要在容器中运行 elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip
|
1
| docker restart elasticsearch
|
1
| firewall-cmd --zone=public --add-port=9200/tcp --permanent firewall-cmd --reload
|
8.Logstash安装
- 下载Logstash7.6.2的docker镜像:
1
| docker pull logstash:7.6.2
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| input { file { #标签 type => "systemlog-localhost" #采集点 path => "/var/log/messages" #开始收集点 start_position => "beginning" #扫描间隔时间,默认是1s,建议5s stat_interval => "5" } }
output { elasticsearch { hosts => "es:9200" index => "logstash-system-localhost-%{+YYYY.MM.dd}" } }
|
1 2 3 4
| docker run -p 4560:4560 -p 4561:4561 -p 4562:4562 -p 4563:4563 --name logstash \ --link elasticsearch:es \ -v /data/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf \ -d logstash:7.6.2
|
1
| docker exec -it logstash /bin/bash
|
1
| logstash-plugin install logstash-codec-json_lines
|
9.Kibana安装
1
| docker pull kibana:7.6.2
|
1 2 3 4
| docker run --name kibana -p 5601:5601 \ --link elasticsearch:es \ -e "elasticsearch.hosts=http://es:9200" \ -d kibana:7.6.2
|
开启防火墙:
1
| firewall-cmd --zone=public --add-port=5601/tcp --permanent
|
重启防火墙:
10.MongoDB安装
1 2 3
| docker run -p 27017:27017 --name mongo \ -v /data/mongo/db:/data/db \ -d mongo:4.2.5
|