🌸🌸 Linux安装- docker/docker-compose/nginx 优雅部署 🌸🌸
一、一键安装jdk
yum install -y java-1.8.0-openjdk.x86_64
- 验证
二、安装docker
yum list docker-ce --showduplicates | sort -r
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum install docker-ce
sudo service docker start
- 验证
三、安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- 验证
docker-compose --version
- 不推荐(
github
不稳定时,容易下载失败,docker-compose
里的内容会各种错误)
- 不推荐(
- 若下载失败则手动安装(推荐,可以自己选择适配的)
- 下载后放入指定位置,如
/usr/local/bin
,(GitHub不稳定开下梯子) - 更改二进制文件名字,
mv docker-compose-linux-x86_64 docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- 验证
docker-compose --version
- 下载后放入指定位置,如
四、docker
编排安装nginx
- 配置文件参考:RuoYi-Vue-Plus
- 文件放置,注意授权
chmod -R 777 /docker/
nginx.conf
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 限制body大小
client_max_body_size 100m;
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 /var/log/nginx/access.log main;
server {
listen 188;
server_name localhost;
# 限制外网访问内网 actuator 相关路径
location ~ ^(/[^/]*)?/actuator(/.*)?$ {
return 403;
}
location / {
root /usr/share/nginx/pig/html;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name localhost;
# 限制外网访问内网 actuator 相关路径
location ~ ^(/[^/]*)?/actuator(/.*)?$ {
return 403;
}
location / {
root /usr/share/nginx/html; # docker映射路径 不允许更改
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
docker-compose
version: '3'
services:
nginx-web:
image: nginx:1.23.4
container_name: nginx-web
environment:
# 时区上海
TZ: Asia/Shanghai
ports:
- "80:80"
- "443:443"
volumes:
# 证书映射
- /docker/nginx/cert:/etc/nginx/cert
# 配置文件映射
- /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
# 页面目录
- /docker/nginx/html:/usr/share/nginx/html
- /docker/nginx/pig/html:/usr/share/nginx/pig/html
# 日志目录
- /docker/nginx/log:/var/log/nginx
privileged: true
network_mode: "host"
-
注意
nginx
和docker-compose
的配置要对应 -
将前端文件放入***
宿主机
***指定位置- 不要按照容器的地址放在宿主机地址了,那样不会找到前端文件的,可能会报
403
,因为找不到文件
- 不要按照容器的地址放在宿主机地址了,那样不会找到前端文件的,可能会报
-
验证