Linux系统安装docker请参考:https://mp.csdn.net/mp_blog/creation/editor/128176825
1、拉镜像:docker pull mysql:8.0.26
2、创建数据目录:
mkdir -p /mnt/data/mysql/data
mkdir -p /mnt/data/mysql/logs
mkdir -p /mnt/data/mysql/mysql-files
mkdir -p /mnt/data/mysql/conf
3、在/mnt/data/mysql/conf下创建my.cnf配置文件,配置文件如下:
# 对本地的mysql客户端的配置
[client]
default-character-set = utf8mb4
# 对其他远程连接的mysql客户端的配置
[mysql]
default-character-set = utf8mb4
# 本地mysql服务的配置
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
# 禁用DNS
skip-name-resolve
default-time-zone = '+8:00'
4、赋权限:chmod -R 777 /mnt/data/mysql/
5、创建自定义网络:docker network create mynetwork
6、创建容器并启动:
docker run -itd --network mynetwork --restart=always --privileged=true --name=mysql8 -p 3306:3306 -v /mnt/data/mysql/mysql-files:/var/lib/mysql-files/ -v /mnt/data/mysql/data:/var/lib/mysql -v /mnt/data/mysql/logs:/var/log/mysql -v /mnt/data/mysql/conf/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=root mysql:8.0.26
1、拉镜像:docker pull mongo:6.0
2、创建数据目录:mkdir -p /mnt/data/mongo/data
3、赋权限:chmod -R 777 /mnt/data/mongo/
4、创建容器并启动:
docker run -d --name mongo6 --restart always --network mynetwork --privileged=true -p 27017:27017 -v /mnt/data/mongo/data:/data/db -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=admin mongo:6.0 --auth
5、创建用户并赋权:
#创建超级管理员用户
use admin;
db.createUser({user: 'admin', pwd: 'admin', roles: [{role: 'root', db: 'admin'}]});
#创建应用数据库用户
use mydb;
db.createUser({user: 'tom', pwd: 'tom', roles: [{role: 'dbOwner', db: 'mydb'}]});
1、拉镜像:docker pull redis:6.0.9
2、创建数据目录:
mkdir -p /mnt/data/redis/data
mkdir -p /mnt/data/redis/conf
3、在/mnt/data/redis/conf下创建redis.conf配置文件,配置文件主要修改下面内容:
# bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
save 900 1
save 300 10
save 60 10000
rdbcompression yes
requirepass 123456
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly no
appendfsync everysec
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
4、赋权限:chmod -R 777 /mnt/data/redis/
5、创建容器并启动:
docker run -d --name redis6 --restart=always --privileged=true --network mynetwork -p 6379:6379 -v /mnt/data/redis/conf/redis.conf:/redis.conf -v /mnt/data/redis/data:/data --requirepass 123456 redis:6.0.9 redis-server --appendonly yes
注意:如果安装的redis版本支持requirepass 参数,尽量启动时设置密码;如果版本不支持,需要在redis启动后,进入控制台,按照下一步用命令设置密码,否则配置文件redis.conf里设置的密码不生效;
6、设置密码(很重要)
用docker命令进入容器内部:docker exec -it 容器ID /bin/bash
进入redis目录:cd /usr/local/bin
运行命令进入客户端:redis-cli
或者通过redis客户端连接工具进入redis控制台,然后通过下面命令查看设置密码:
查看当前redis密码:config get requirepass
设置redis密码:config set requirepass ******
若出现(error) NOAUTH Authentication required.错误,则使用 auth 密码 来认证密码
可以发现,在设置密码前,即便我们在redis.conf中配置了密码,但这里仍然显示密码为空:
1、拉镜像:docker pull elasticsearch:8.1.2
2、创建数据目录:
mkdir -p /mnt/data/elasticsearch/data
mkdir -p /mnt/data/elasticsearch/plugins
mkdir -p /mnt/data/elasticsearch/config
3、在/mnt/data/elasticsearch/config下创建elasticsearch.yml配置文件,配置文件如下:
单机部署:
node.name: node1
network.host: 0.0.0.0
network.publish_host: localhost
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.seed_hosts: ["localhost:9300"]
transport.profiles.default.port: 9300
xpack.security.enabled: false
集群部署:
节点1 | 节点2 | 节点3 |
cluster.name: es-cluster node.name: node1 network.host: 0.0.0.0 network.publish_host: 192.168.4.103 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" cluster.initial_master_nodes: node1 discovery.seed_hosts: ["192.168.4.103:9300"] transport.profiles.default.port: 9300 xpack.security.enabled: false |
cluster.name: es-cluster node.name: node2 network.host: 0.0.0.0 network.publish_host: 192.168.4.103 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" cluster.initial_master_nodes: node1 discovery.seed_hosts: ["192.168.4.103:9300"] transport.profiles.default.port: 9300 xpack.security.enabled: false |
cluster.name: es-cluster node.name: node3 network.host: 0.0.0.0 network.publish_host: 192.168.4.103 http.port: 9200 http.cors.enabled: true http.cors.allow-origin: "*" cluster.initial_master_nodes: node1 discovery.seed_hosts: ["192.168.4.103:9300"] transport.profiles.default.port: 9300 xpack.security.enabled: false |
4、赋权限:chmod -R 777 /mnt/data/elasticsearch/
5、创建容器并启动:
docker run --name es8 -p 9200:9200 -p 9300:9300 --restart always --network mynetwork --privileged=true -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms1024m -Xmx1024m" -v /mnt/data/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /mnt/data/elasticsearch/data:/usr/share/elasticsearch/data -v /mnt/data/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:8.1.2
1、拉镜像:docker pull nginx
2、创建数据目录:
mkdir -p /mnt/data/nginx/logs
mkdir -p /mnt/data/nginx/html
mkdir -p /mnt/data/nginx/conf
3、在/mnt/data/nginx/conf下创建nginx.conf配置文件,配置文件如下:
worker_processes 4;
worker_rlimit_nofile 655350;
events {
worker_connections 100000;
}
stream {
upstream plcserver{
#least_conn; # 把请求分派给连接数最少的服务器
server 172.18.0.1:2526;
server 172.18.0.2:2526;
#hash $remote_addr consistent;
#server 127.0.0.1:6000 weight=1 max_fails=3 fail_timeout=30s;
#server 127.0.0.1:6002 weight=1 max_fails=3 fail_timeout=30s;
}
server {
listen 2526;
proxy_pass plcserver;
tcp_nodelay on;
proxy_connect_timeout 1s;
#proxy_timeout 3s;
# 开启代理协议,通过协议发送真实IP
proxy_protocol on;
}
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
# 开启gzip压缩
gzip on;
# 不压缩临界值,大于1K的才压缩,一般不用改
gzip_min_length 1k;
# 压缩缓冲区
gzip_buffers 16 64K;
# 压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
gzip_http_version 1.1;
# 压缩级别,1-10,数字越大压缩的越好,时间也越长
gzip_comp_level 5;
# 进行压缩的文件类型
gzip_types text/plain
application/x-javascript
text/css
application/xml
application/javascript;
# 跟Squid等缓存服务有关,on的话会在Header里增加"Vary: Accept-Encoding"
gzip_vary on;
# IE6对Gzip不怎么友好,不给它Gzip了
gzip_disable "MSIE [1-6]\.";
upstream myserver {
server 172.18.0.2:8888; #前端请求经过nginx代理后到后台的服务IP和端口
}
server {
listen 80;
#填写证书绑定的域名
server_name 172.18.0.2;
#将所有HTTP请求通过rewrite指令重定向到HTTPS
rewrite ^(.*)$ https://$host$1;
location / {
root /mnt/project/frontend/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
}
server {
listen 443 ssl;
# server_name 172.18.0.2;
ssl_certificate cert/1111111_xxxxxxx.cn.pem;
ssl_certificate_key cert/1111111_xxxxxxx.cn.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root /mnt/project/frontend/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /profile {
alias /mnt/uploadPath/;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://myserver;
}
location /vue/ {
alias /mnt/project/frontend/vue;
}
location /vue/lbx/ {
alias /mnt/project/frontend/h5/;
}
location /web-api/ {
proxy_pass http://myserver;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# MP_verify_vxs6TlQn9pENraPp.txt
location = /MP_verify_sdfsfsfsfsf.txt {
alias /mnt/uploadPath/MP_verify_sdfsfsfsfsf.txt;
}
}
#nginx优化----------------------
#隐藏版本号
server_tokens on;
#优化服务器域名的散列表大小
server_names_hash_bucket_size 64;
server_names_hash_max_size 2048;
#开启高效文件传输模式
#sendfile on;
#减少网络报文段数量
#tcp_nopush on;
#提高I/O性能
tcp_nodelay on;
#连接超时 时间定义 默认秒 默认65秒
#keepalive_timeout 60;
#读取客户端请求头数据的超时时间 默认秒 默认60秒
client_header_timeout 15;
#读取客户端请求主体的超时时间 默认秒 默认60秒
client_body_timeout 15;
#响应客户端的超时时间 默认秒 默认60秒
send_timeout 25;
#上传文件的大小限制 默认1m
client_max_body_size 8m;
}
4、赋权限:chmod -R 777 /mnt/data/nginx/
5、创建容器并启动:
docker run --name nginx -m 500m -p 80:80 --restart always --network mynetwork -v /mnt/data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /mnt/data/nginx/logs:/var/log/nginx -v /mnt/data/nginx/html:/usr/share/nginx/html -v /mnt/project/frontend/build:/mnt/project/frontend/build -e TZ=Asia/Shanghai --privileged=true -d nginx