一、后端部署
1、点击配置
2、配置jenkins,略。填写shell脚本(放在jenkins服务器)绝对路径。
3、脚本(放于jenkins服务器。jenkins与项目部署服务器不在同一台服务器,通过scp传输文件,ssh远程执行脚本)
SRC_DIR=/data/build/work/jobs/${JOB_NAME}/workspace
MAVEN_HOME=/data/build/apache-maven-3.3.9_dev
cd ${SRC_DIR}
${MAVEN_HOME}/bin/mvn -DskipTests=true clean -P test
${MAVEN_HOME}/bin/mvn -DskipTests=true package -P test
scp aaa-gateway/target/aaa-gateway.jar root@10.xxx.xxx.1:/data/app/aaa/test/aaa-gateway
ssh -p 22 -o StrictHostKeyChecking=no -o ConnectTimeout=100 10.xxx.xxx.1 sh /data/app/aaa/test/aaa-gateway/shutdown.sh
ssh -p 22 -o StrictHostKeyChecking=no -o ConnectTimeout=100 10.xxx.xxx.1 sh /data/app/aaa/test/aaa-gateway/startup.sh
scp aaa-auth/target/aaa-auth.jar root@10.xxx.xxx.1:/data/app/aaa/test/aaa-auth
ssh -p 22 -o StrictHostKeyChecking=no -o ConnectTimeout=100 10.xxx.xxx.1 sh /data/app/aaa/test/aaa-auth/shutdown.sh
ssh -p 22 -o StrictHostKeyChecking=no -o ConnectTimeout=100 10.xxx.xxx.1 sh /data/app/aaa/test/aaa-auth/startup.sh
scp aaa-upms/aaa-upms-biz/target/aaa-upms-biz.jar root@10.xxx.xxx.1:/data/app/aaa/test/aaa-upms-biz
ssh -p 22 -o StrictHostKeyChecking=no -o ConnectTimeout=100 10.xxx.xxx.1 sh /data/app/aaa/test/aaa-upms-biz/shutdown.sh
ssh -p 22 -o StrictHostKeyChecking=no -o ConnectTimeout=100 10.xxx.xxx.1 sh /data/app/aaa/test/aaa-upms-biz/startup.sh
?4、start.sh/shutdown.sh(放于项目部署服务器。这里只列举一个服务,其他服务类似)
start.sh
#!/bin/bash
export BASE_DIR=`cd $(dirname $0); pwd`
target="${BASE_DIR}/xxx-auth"
source /etc/profile
nohup java -jar ${target}.jar > ${BASE_DIR}/logs/start.out 2>&1 &
echo "${target} is starting,you can check the ${BASE_DIR}/logs/start.out"
?shutdown.sh
#!/bin/bash
export BASE_DIR=`cd $(dirname $0); pwd`
target="${BASE_DIR}/xxx-auth"
pid=`ps ax | grep java | grep -v grep | grep ${target} | awk '{print $1}'`
if [ -z "$pid" ] ; then
echo "No ${target} running."
exit -1;
fi
echo "The ${target} (${pid}) is running..."
kill -9 ${pid}
echo "Send shutdown request to ${target} (${pid}) OK"
二、前端部署
1、jenkins配置脚本
2、脚本(放于jenkins服务器)
SRC_DIR=/data/build/work/jobs/${JOB_NAME}/workspace
NAME=`echo "${JOB_NAME}"|awk -F_ '{print $2}'`
# aaa-vue3.0 项目名
cd ${SRC_DIR}/xxx-vue3.0
# 私有仓库
npm install -g cnpm -registry=http://10.xxx.xxx.1:8081/repository/npm-group/
cnpm install
npm run build:test
cd dist
zip -r ${NAME}.zip *
echo "scp zip file"
scp ${NAME}.zip root@10.xxx.xxx.1:/www/wwwroot/
echo "sh,unzip aaa-web.zip"
ssh -p 22 -o StrictHostKeyChecking=no -o ConnectTimeout=100 10.xxx.xxx.1 sh /data/www/wwwroot/desploy-aaa-web.sh
?desploy-aaa-web.sh(放于项目服务器)
rm -rf xxx.com/
unzip -o /data/www/wwwroot/xxx-web.zip -d /data/www/wwwroot/xxx.com/
sleep 2
三、配置nginx
user root;
worker_processes auto;
error_log /www/wwwlogs/nginx_error.log crit;
pid /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
#include luawaf.conf;
include proxy.conf;
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
server
{
listen 888;
server_name phpmyadmin;
index index.html index.htm index.php;
root /www/server/phpmyadmin;
#error_page 404 /404.html;
#AUTH_START
auth_basic "Authorization";
auth_basic_user_file /www/server/pass/phpmyadmin.pass;
#AUTH_END
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /www/wwwlogs/access.log;
}
include /www/server/panel/vhost/nginx/*.conf;
}
前端的配置放于:include /www/server/panel/vhost/nginx/xxx.com.conf;这个配置。
上边的配置全局的就行。
xxx.com.conf:
server
{
listen 80;
server_name 10.xxx.xxx.1;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/xxx.com;
# 注意维护新增微服务,gateway 路由前缀
location ~* ^/(code|auth|admin|gen) {
proxy_pass http://127.0.0.1:10001;
#proxy_set_header Host $http_host;
proxy_connect_timeout 15s;
proxy_send_timeout 15s;
proxy_read_timeout 15s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
}
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-00.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/xxx.com.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log /dev/null;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log /dev/null;
access_log /dev/null;
}
access_log /www/wwwlogs/xxx.com.log;
error_log /www/wwwlogs/xxx.com.error.log;
}
|