准备工作:
购买服务器、购买域名并备案、解析出需要用的域名
h5:h5.xxx.cn
平台端:adminplat.xxx.cn
商户端:adminmer.xxx.cn
front api:api.front.xxxcn
admin api:api.admin.xxx.cn
连接上服务器后的第一步先重装一下docker,因为购买服务器选择的docker版本低,运行java容器可能会报内存不足。
重装docker
卸载:
sudo yum install -y yum-utils
sudo yum remove docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
安装:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
- 设置开机自启:
systemctl enable docker.service
在拉取镜像的时候如果报错了可以配置一下镜像仓库
vi /etc/docker/daemon.json
阿里云内容如下:
{
"registry-mirrors":["https://6kx4zyno.mirror.aliyuncs.com"]
}
重启
systemctl daemon-reload
systemctl restart docker
部署
后端准备
1.创建docker网络:
docker network create crmeb
2.创建mysql服务
docker run -d --name mysql -v mysqldata:/var/lib/mysql -v mysqlconf:/etc/mysql/conf.d -v mysqllog:/var/log/mysql -p 3306:3306 --network crmeb -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7
-d 后台运行
–name 容器名
-v 数据卷
-p 端口映射
–network 网络指定
-e 环境配置,这里指定了root用户的密码
3.创建redis服务
docker run --name redis --network crmeb -p 6379:6379 -d -e REDIS_PASSWORD=123456@1234 redis:latest
要远程连接mysql、redis。需要去把服务器的安全组把3306,6379端口放出来才能访问。不使用就禁用否则不安全
4.java应用镜像构建:
创建一个Dockerfile的文件(名字必须叫这个)内容如下:
# 基础镜像
FROM eclipse-temurin:8
# 作者
MAINTAINER HDQ
# 工作目录
WORKDIR /usr/local/java
# 同步docker内部的时间
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 设置时区
ENV TZ=Asia/Shanghai
EXPOSE 20700
# 复制jar包到/user/local/java下
ARG JAR_FILE
ADD ${JAR_FILE} ./Crmeb-admin.jar
ENTRYPOINT ["nohup","java","-Dspring.profiles.active=prod","-Dspring.config.location=/usr/local/java/application.yml,/usr/local/java/application-prod.yml","-jar","/usr/local/java/Crmeb-admin.jar",">","/usr/local/java/crmeb.log","&>","&"]
需要创建两个,分别是admin和front的,改一下工作目录和jar包的名字就可以了
5.Java项目打包
修改后打包生成
在服务器创建两个文件夹分别是Java和Java1用来放打包后的jar包,Dockerfile和yml配置文件
上传文件后在服务器上的java目录和Java1目录下,执行该命令
docker build -t crmeb:1 .
运行admin
docker run -d -it --name crmeb --network crmeb -v /usr/local/java:/usr/local/java -p 20700:20700 crmeb:1
运行front
docker run -d -it --name crmeb2 --network crmeb -v /usr/local/java1:/usr/local/java1 -p 20710:20710 crmeb2:1
前端准备
1.项目打包
平台端和商户端一样的打包,需要先npm install安装依赖然后在npm run build:prod打包
2.部署nginx
先在服务器上创建文件夹nginx和html
nginx配置:
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
server {
listen 80;
server_name adminplat.xxx.cn;
root /usr/share/nginx/html/dist;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
root /usr/share/nginx/html/dist;
expires 30d;
access_log off;
}
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
}
server {
listen 80;
server_name adminmer.xxx.cn;
root /usr/share/nginx/html/dist1;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
root /usr/share/nginx/html/dist1;
expires 30d;
access_log off;
}
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
}
server {
listen 80;
server_name api.admin.xxx.cn;
location / {
proxy_pass http://41.11.192.0:20700;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
}
#}
server {
listen 80;
server_name h5.xxx.cn;
root /usr/share/nginx/html/h5;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
root /usr/share/nginx/html/h5;
expires 30d;
access_log off;
}
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
}
server {
listen 80;
server_name api.front.xxx.cn;
location / {
proxy_pass http://41.11.192.0:20710;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
}
}
运行nginx容器
docker run -d --name nginx --network crmeb -v /usr/local/nginx/html:/usr/share/nginx/html -v /usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf -p 80:80 nginx:latest
运行的所有容器
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}