摘要:利用gitlab自带的cicd来部署。
Linux环境配置:
1、创建站点所需空目录:mkdir -p /var/www/boost
2、创建各个站点对应的目录:
2.1 创建webapi站点目录
mkdir -p /var/www/boost/medusa.api/src
2.2 配置webapi站点starter.sh,此处的dll名需换成真实的名称
echo '#!/bin/bash dotnet /var/www/boost/medusa.service.platform/src/Medusa.Service.Platform.Entrance.dll' >starter.sh
2.3 创建gateway站点目录
mkdir -p /var/www/boost/medusa.gateway/src
2.4 创建业务前台站点目录
mkdir -p /var/www/boost/medusa.customer/src
3、部署Nginx
3.1 配置nginx.conf文件
进入 /etc/nginx/nginx.conf文件,并配置如下
user root; worker_processes 1; pid /run/nginx.pid; events { use epoll; #worker_connections auto; multi_accept on; } http { map $http_upgrade $connection_upgrade { default upgrade; '' close; } underscores_in_headers on; client_max_body_size 100m; client_header_buffer_size 4k; ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf;
include /etc/nginx/conf.d/boost/*.conf;
#include /etc/nginx/sites-enabled/*; }
把备份好的/etc/nginx/conf.d/boost文件夹还原到新服务器上
把备份好的/etc/nginx/cors_params和/etc/nginx/proxy_params还原到服务器上
3.2 为各个站点配置文件
3.2.1 创建webapi对应的config文件
touch /etc/nginx/conf.d/api.conf
并写入内容:
server { listen 172.20.182.252:5101; server_name _; location / { proxy_pass http://127.0.0.1:5101; include /etc/nginx/proxy_params; } }
3.2.2 创建业务前台对应的config文件
touch /etc/nginx/conf.d/web.conf
并写入内容
server { listen 80; server_name _; location /file/ { alias /var/www/uploads/; } location / { proxy_pass http://127.0.0.1:4100; include /etc/nginx/proxy_params; } }
3.3 重启 Nginx
nginx -s reload
3.4 查看服务状态(注意,刚初始化代码还没有部署上来时状态应该都是error)
pm2 -status (如果一直用的是sudo,那么这边也得改成sudo pm2 -status,下同)
PS:如果已经部署好了,要新增一个应用进来,那么操作顺序如下:
- 先去对应的文件夹下把发布包部署好
- 在对应的地方加入starter.sh
- 去/var/www/ecosystem.config.js下按照格式加入新项目的配置
- 使用pm2 start /var/www/ecosystem.config.js 重新运行 (如果一直用的是sudo,那么这边也得改成sudo pm2 start,否则会出现2个pm2,一个是pm2,一个是sudo pm2,下同)
- 运行pm2 startup
- 运行pm2 save,确保重启服务器的时候这个项目还能正常启动