首页 > 其他分享 >eladmin前后端分离jenkins自动发版

eladmin前后端分离jenkins自动发版

时间:2024-10-08 19:44:32浏览次数:8  
标签:set dist 100.100 eladmin proxy jenkins 发版 root

CICD&前后端自动发版

一、初步部署

VM 主机名 IP
gitlab gitlab 100.100.137.3/24 8/8/100
jenkens jenkins 100.100.137.4/24 8/8/100
前端 node-1 100.100.137.5/24 2/2/25
后端 node-2 100.100.137.6/24 2/2/25
MySQL mysql 100.100.137.7/24 2/2/25
Redis redis 100.100.137.8/24 2/2/25

账号:zhangyu
密码:Ifcfg-ens224

新系统初始化

#修改时区
timedatectl set-timezone Asia/Shanghai
#更换APT源地址

cat <<'EOF' > /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirror.nju.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirror.nju.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirror.nju.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirror.nju.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirror.nju.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirror.nju.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
# deb https://mirror.nju.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src https://mirror.nju.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirror.nju.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirror.nju.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
EOF

#打通所有主机sshkey验证
vim /etc/ssh/ssh_config

  StrictHostKeyChecking no
  PasswordAuthentication no
  
  
 

vim /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication no
ChallengeResponseAuthentication no

#修改后重启
systemctl restart  ssh






修改数据库连接配置

eladmin-system/src/main/resources/config/application-prod.yml

image-20241002105240451

eladmin-system/src/main/resources/config/application.yml

image-20241002105323035

修改前端默认连接路径

.env.production

image-20241002105134789

修改后端代码

gitlab

#下载git安装包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/jammy/main/g/gitlab-ce/gitlab-ce_17.4.1-ce.0_amd64.deb
#安装
dakg -i gitlab-ce_17.4.1-ce.0_amd64.deb
#修改访问域名或ip
vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.zhang.com'
#重载配置文件
gitlab-ctl reconfigure
#查看首次登录密码,首次使用该密码登录后需立即设置密码
cat /etc/gitlab/initial_root_password

Password: bi09K8pa0DVWXT/UI73wOlblviRmpKyLOPotrJEID8g=






开启gitlab 仓库导入权限

image-20241002003800757

image-20241002015110432

Jenkins

#下载各种依赖包 Jenkins安装包
apt update && apt install maven mysql-client net-tools npm


wget https://mirrors.bfsu.edu.cn/jenkins/debian-stable/jenkins_2.462.2_all.deb

dpkg -i jenkins_2.462.2_all.deb

#修改启动用户为root/重启
vim /lib/systemd/system/jenkins.service

systemctl daemon-reload 

systemctl restart jenkins.service

#查看首次登录密码
cat /var/lib/jenkins/secrets/initialAdminPassword
#首次登录下载插件后 设置登录密码

#后端执行脚本(注意路径变化)
root@jenkins:/data/eladmin# cat eladmin.sh 
#!/bin/bash
mvn clean package -Dmaven.test.skip=true
scp -r /var/lib/jenkins/workspace/eladmin/eladmin-system/target/eladmin-system-2.7.jar 100.100.137.6:/data/eladmin/
ssh [email protected] '/root/stop.sh'
ssh [email protected] '/root/start.sh'
#前端执行脚本(注意路径变化)

root@jenkins:/data/eladmin# cat eladmin-web.sh 
#!/bin/bash
npm install --registry=https://registry.npmmirror.com
npm run build:prod
ssh [email protected] 'rm -rf /root/data/eladmin/dist '
scp -r /var/lib/jenkins/workspace/myeladmin/dist 100.100.137.5:/data/eladmin/

#MYSQL主机准备好之后执行下列操作
#准备表
apt -y install mysql-client
mysql -ueladmin -p123456 -h100.100.137.7

#导入表
mysql> use eladmin;
mysql> source /var/lib/jenkins/workspace/eladmin/sql/eladmin.sql;
mysql> show tables;

前端

#安装nginx
apt install nginx -y
#nginx代理配置(注意路径变化)
root@node-1:~# cat /etc/nginx/sites-enabled/eladmin.conf 
server
    {
        listen 80;
        server_name 100.100.137.5;
        index index.html;
        root  /data/eladmin/dist/;  #dist上传的路径

        # 避免访问出现 404 错误
        location / {
          try_files $uri $uri/ @router;
          index  index.html;
        }

        location @router {
          rewrite ^.*$ /index.html last;
        }

        # 接口
        location /api {
          proxy_pass http://100.100.137.6:8000;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header X-Forwarded-Port $server_port;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        }

        # 授权接口
        location /auth {
          proxy_pass http://100.100.137.6:8000;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header X-Forwarded-Port $server_port;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        }

        # WebSocket 服务
        location /webSocket {
          proxy_redirect off;
          proxy_pass http://100.100.137.6:8000/webSocket;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_connect_timeout 60s;
          proxy_read_timeout 86400s;
          proxy_send_timeout 60s;
        }

        # 头像
        location /avatar {
          proxy_pass http://100.100.137.6:8000;
        }

        # 文件
        location /file {
          proxy_pass http://100.100.137.6:8000;
        }
    }
#创建默认页面路径目录
mkdir -pv /data/eladmin/
#重启服务
systemctl restart nginx



后端

#安装Maven(其中包含Java程序)
apt update && apt install maven -y
#后端停止脚本
root@node-2:~# cat stop.sh 
PID=$(ps -ef | grep eladmin-system-2.7.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo Application is already stopped
else
echo kill -9 $PID
kill -9 $PID
fi
#启动脚本(注意路径、版本变化)、如果启动失败注意进程运行情况,可能端口被占用
nohup java -jar /data/eladmin/eladmin-system-2.7.jar --spring.profiles.active=prod > nohup.out 2>&1 &

MySQL

#安装MySQL
apt install mysql-server
#开启远程连接
    sed -i '/127.0.0.1/s/^/#/' /etc/mysql/mysql.conf.d/mysqld.cnf
#重启服务
systemctl restart mysql
#创建用户 库
mysql> create database eladmin;
mysql> create user eladmin@'%' identified by '123456';
mysql> grant all on eladmin.* to eladmin@'%';


Redis

#安装
apt update && apt install redis -y
#修改默认配置
sed -i 's/^bind .*/bind 0.0.0.0/' /etc/redis/redis.conf
systemctl restart redis

二、简单部署后优化

内存优化

#当前使用版本gitlab-ce_17.4.1-ce.0_amd64.deb

vim /etc/gitlab/gitlab.rb

prometheus['enable'] = false
prometheus['monitor_kubernetes'] =false
alertmanager['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
gitlab_exporter['enable'] = false
prometheus_monitoring['enable'] =false
grafana['enable'] = false  #此版本无此项内容

gitlab邮件通知

image-20241003161141508

用户注册限制

image-20241003161305735

前端加速以及版本秒级回滚

#nginx配置文件
server
    {
        listen 80;
        server_name node-1.zy-98.cn;
        index index.html;
        root  /var/html/dist;  #dist上传的路径

标签:set,dist,100.100,eladmin,proxy,jenkins,发版,root
From: https://www.cnblogs.com/zy-98/p/18452365

相关文章

  • Jenkins之插件Snyk
    参考文档:JenkinspluginintegrationwithSnyk|SnykUserDocsFollowthestepsineachsectionofthisdocumenttousetheSnykJenkinsplugin: InstalltheSnykSecurityJenkinsPlugin. ConfigureaSnykinstallation. ConfigureaSnykAPItokencre......
  • Jenkins拉取代码报错通过git配置浅克隆
    在Linux中,使用gitconfig命令配置depth为1意味着你想要为你的Git仓库设置一个浅克隆(shallowclone)。浅克隆会克隆仓库的历史记录中的一个极简版本,通常只包含最近的一次提交。这样做可以节省带宽和时间,特别是对于那些不需要完整历史记录的项目。要配置深度为1的浅克隆,你可以使用以......
  • jenkins项目发布基础
             随着软件开发需求及复杂度的不断提高,团队开发成员之间如何更好地协同工作以确保软件开发的质量已经慢慢成为开发过程中不可回避的问题。Jenkins自动化部署可以解决集成、测试、部署等重复性的工作,工具集成的效率明显高于人工操作;并且持续集成可以更早的......
  • Jenkins安装
    目录1、什么是Jenkins2、Jenkins的作用3、什么是CI/CD4、Jenkins的应用场景5、Jenkins特性6、安装Jenkins1、上传文件2、安装Jenkins3、修改启动用户为root4、启动jenkins5、报错,检查配置文件java的配置6、启动前查看该目录是空的,启动后会生成相应的文件【用来检......
  • jenkins 搭建 uniapp h5部署服务
    项目中需要适用jenkins搭建uniapph5部署服务,初次接触,踩了很多坑,记录下主要分为两步骤:1.创建uniapp打包环境由于创建打包环境的步骤有手动确定项目,所以不能通过jenkins自动创建,需要先到目录中手动配置环境2.搭建jenkins自动化部署步骤任务把jenkins工作目录配置为刚才的环......
  • Jenkins备份和恢复
    Jenkins备份和恢复一、插件备份和恢复1.安装备份插件重启系统后查看2.配置周期备份点击进入,点击SettingsBackuponlybuildsmarkedtokeep,如果启用此选项,则仅备份标记为“永久保留此生成”的生成结果/项目。如下图BackupuserContentfolder ~......
  • jenkins API实践
    一、jenkins PythonAPI在线文档:https://python-jenkins.readthedocs.io/en/latest/项目地址:https://pypi.org/project/python-jenkins/1.注意支持的Python版本目前只支持到3.62.简单示例pip3installpython-jenkinsimportjenkinsserver=jenkins.Jenkins('http://192.168.1......
  • 【随手记录】docker部署jenkins,集成maven、spring项目
    1、下载镜像文件到服务器dockerpulljenkins/jenkins:lts-jdk17或离线导入镜像:dockerload-ijenkins-lts-jdk17检查镜像是否导入:dockerimages|grepjenkinsjenkins/jenkinslts-jdk177a7add0bf3da2weeksago470MB2024年6月以后国内很多大型的Dock......
  • jenkins 2.463安装-教你如何全部下载新手入门插件
    1jkd17上传到服务器并配置2防火墙放行8080firewall-cmd--permanent--zone=public--add-port=8080/tcpsystemctlreloadfirewalld3安装gityuminstallgit4下载jenkins安装包。下载地址:https://get.jenkins.io/redhat/把rpm包上传到服务器5安装:sudorpm-ihje......
  • Jenkins 基于 Docker 部署
    1、Docker、Docker-Compose安装https://www.cnblogs.com/a120608yby/p/9883175.htmlhttps://www.cnblogs.com/a120608yby/p/14582853.html2、基于Docker-Compose部署Jenkins#vimdocker-jenkins/docker-compose.ymlservices:jenkins:image:jenkins/jenkins:lts......