拉取镜像
docker pull mysql:5.7 # 拉取 mysql 5.7
检查是否拉取成功
docker images
创建MySql容器
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
# 或者
docker run -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
如果报错invalid reference format,可能是因为复制后格式不对导致的,需要手动敲一下命令,尤其是里边的横杠;
检查容器是否正确运行
docker container ls
可以看到容器ID,容器的源镜像,启动命令,创建时间,状态,端口映射信息,容器名字
本地使用Navicat链接MySql
配置用户名是root,密码是root的用户可以远程连接可(不配置的话,项目启动报错,但是navicat可以连接)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;
下边的内容可以不做
进入运行MySQL的docker容器
docker exec ‐it mysql /bin/bash
使用MySQL命令打开客户端
mysql ‐uroot ‐proot ‐‐default‐character‐set=utf8
创建mall数据库:
create database mall character set utf8
安装上传下载插件,并将document/sql/mall.sql上传到Linux服务器上:
yum ‐y install lrzsz
拉取镜像
docker pull mysql:8.0.16 # 拉取 mysql
新建目录用来存放配置文件和目录
mkdir -p /usr/docker/mysql/conf && mkdir -p /usr/docker/mysql/datadir
启动容器
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.16
把容器里的配置文件复制出来
docker cp mysql:/etc/mysql/my.cnf /usr/docker/mysql/conf
停止并删除容器
docker stop mysql && docker rm mysql
重新新建并启动容器
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --mount type=bind,src=/usr/docker/mysql/conf/my.cnf,dst=/etc/mysql/my.cnf --mount type=bind,src=/usr/docker/mysql/datadir,dst=/var/lib/mysql --restart=on-failure:3 -d mysql:8.0.16
解决navicat连接mysql8.x报错问题
进入容器
docker exec -it mysql bash
进入mysql编辑命令界面
mysql -uroot -proot;
use mysql;
ALTER USER 'root'@'%' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY 'root';
#使修改生效
flush privileges;
如果项目里报错如下:
#2 of SELECT list is not in GROUP BY clause and contains nonaggregated column …
解决办法:
解决方式:执行以下sql
set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
最后打开你的my.ini(mysql8.x版本后是my.cnf文件)文件在[mysqld]
下面加上:
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
重启mysql即可;
docker pull redis:5;
docker run -p 6379:6379 --name redis -v /mydata/redis/data:/data -d redis:5 --appendonly yes
进入Redis容器使用redis-cli命令进行连接
docker exec -it redis redis-cli
# 下载镜像
docker pull rabbitmq:3.7.15;
# 创建容器
docker run -p 5672:5672 -p 15672:15672 --name rabbitmq -d rabbitmq:3.7.15
进入容器并开启管理功能:
# 进入容器
docker exec -it rabbitmq /bin/bash
# 开启管理功能
rabbitmq-plugins enable rabbitmq_management
关闭防火墙
firewall-cmd --zone=public --add-port=15672/tcp --permanent
浏览器即可访问
http://192.168.199.128:15672/
账号密码:guest 、guest
docker pull elasticsearch:7.6.2;
修改虚拟内存区域大小,否则会因为过小而无法启动:
sysctl -w vm.max_map_count=262144
使用如下命令启动Elasticsearch服务:
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single‐node" -e "cluster.name=elasticsearch" -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data -d elasticsearch:7.6.2
# 进入容器
docker exec -it elasticsearch /bin/bash;
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip;
docker pull kibana:7.6.2
docker run --name kibana -p 5601:5601 --link elasticsearch:es -e "elasticsearch.hosts=http://es:9200" -d kibana:7.6.2
访问:http://虚拟机IP:5601
docker pull logstash:7.6.2
修改Logstash的配置文件logstash.conf中output节点下的Elasticsearch连接地址为es:9200,配置文件地址:
input {
tcp {
mode => "server"
host => "0.0.0.0"
port => 4560
codec => json_lines
type => "debug"
}
tcp {
mode => "server"
host => "0.0.0.0"
port => 4561
codec => json_lines
type => "error"
}
tcp {
mode => "server"
host => "0.0.0.0"
port => 4562
codec => json_lines
type => "business"
}
tcp {
mode => "server"
host => "0.0.0.0
port => 4563
codec => json_lines
type => "record"
}
}
filter{
if [type] == "record" {
mutate {
remove_field => "port"
remove_field => "host"
remove_field => "@version"
}
json {
source => "message"
remove_field => ["message"]
}
}
}
output {
elasticsearch {
hosts => "192.168.50.66:9200"
index => "mall‐%{type}‐%{+YYYY.MM.dd}"
}
}
创建/mydata/logstash目录,并将Logstash的配置文件logstash.conf拷贝到该目录;
mkdir /mydata/logstash
docker run --name logstash -p 4560:4560 -p 4561:4561 -p 4562:4562 -p 4563:4563 --link elasticsearch:es -v /mydata/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf -d logstash:7.6.2
进入容器内部安装插件
docker exec -it logstash/bin/bash;
logstash-plugin install logstash-codec-json_lines
docker pull mongo:4.2.5
docker run -p 27017:27017 --name mongo -v /mydata/mongo/db:/data/db -d mongo:4.2.5