jenkins部署若依项目

准备项目代码

10.0.0.8虚拟机拉取项目

准备数据库
下载代码
[root@rocky8 ]git@gitlab.wang.org:devops/RuoYi-Vue.git
[root@rocky8 RuoYi-Vue]#vim ruoyi-admin/src/main/resources/application.yml
定义了怎么去连接mysql信息
[root@rocky8 ~]#head -n11 RuoYi-Vue/ruoyi-admin/src/main/resources/application-druid.yml 
# 数据源配置
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: com.mysql.cj.jdbc.Driver
        druid:
            # 主库数据源
            master:
                url: jdbc:mysql://mysql.wang.org:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                username: root
                password: password

定义了连接的用户名和密码

gitlab上面安装mysql
准备mysql:

[root@gitlab ~]#apt install mysql-server -y
#打开远程连接能力
[root@gitlab ~]#sed -i '/127.0.0.1/s/^/#/' /etc/mysql/mysql.conf.d/mysqld.cnf
#创建表准备连接
[root@gitlab ~]#mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.39-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database ry;
Query OK, 1 row affected (0.01 sec)

mysql> create user ry@'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all on ry.* to ry@'10.0.0.%';
Query OK, 0 rows affected (0.01 sec)

mysql> exit





#本机是DNS服务器
修改DNS
[root@gitlab ~]#vim /etc/bind/wang.org.zone 

$TTL 1D
@   IN SOA  master admin (
                    1   ; serial
                    1D  ; refresh
                    1H  ; retry
                    1W  ; expire
                    3H )    ; minimum
        NS       master
master  A        10.0.0.200
gitlab  A    10.0.0.200
jenkins     A    10.0.0.210
nysql   A    10.0.0.200


[root@gitlab ~]#rndc reload
server reload successful



修改web服务器上面的DNS,让他指向10.0.0.200上面的DNS解析器
10.0.0.201上面
[root@ubuntu2204 ~]#vim /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
      - 10.0.0.201/24
      gateway4: 10.0.0.2
      nameservers:
        addresses: [10.0.0.200]
[root@ubuntu2204 ~]#netplan apply 

10.0.0.202上面
[root@ubuntu2204 ~]#vim /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
      - 10.0.0.201/24
      gateway4: 10.0.0.2
      nameservers:
        addresses: [10.0.0.200]
[root@ubuntu2204 ~]#netplan apply 
                                 

把若依项目推送到远程的数据中10.0.0.200

[root@rocky8 ~]#mysql -ury -p123456 -h10.0.0.200 ry < RuoYi-Vue/sql/quartz.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@rocky8 ~]#mysql -ury -p123456 -h10.0.0.200 ry < RuoYi-Vue/sql/ry_20231130.sql 
mysql: [Warning] Using a password on the command line interface can be insecure.
确认数据库表生成:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| ry                 |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use ry;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+--------------------------+
| Tables_in_ry             |
+--------------------------+
| QRTZ_BLOB_TRIGGERS       |
| QRTZ_CALENDARS           |
| QRTZ_CRON_TRIGGERS       |
| QRTZ_FIRED_TRIGGERS      |
| QRTZ_JOB_DETAILS         |
| QRTZ_LOCKS               |
| QRTZ_PAUSED_TRIGGER_GRPS |
| QRTZ_SCHEDULER_STATE     |
| QRTZ_SIMPLE_TRIGGERS     |
| QRTZ_SIMPROP_TRIGGERS    |
| QRTZ_TRIGGERS            |
| gen_table                |
| gen_table_column         |
| sys_config               |
| sys_dept                 |
| sys_dict_data            |
| sys_dict_type            |
| sys_job                  |
| sys_job_log              |
| sys_logininfor           |
| sys_menu                 |
| sys_notice               |
| sys_oper_log             |
| sys_post                 |
| sys_role                 |
| sys_role_dept            |
| sys_role_menu            |
| sys_user                 |
| sys_user_post            |
| sys_user_role            |
+--------------------------+
30 rows in set (0.00 sec)

mysql> exit
#jenkis主机上 安装 maven
[root@jenkins ~]#apt update && apt -y install maven

#后端两台服务器上面准备环境

[root@ubuntu2204 ~]#apt update && apt -y install openjdk-11-jdk
[root@ubuntu2204 ~]#java -version 
openjdk version "11.0.24" 2024-07-16
OpenJDK Runtime Environment (build 11.0.24+8-post-Ubuntu-1ubuntu322.04)
OpenJDK 64-Bit Server VM (build 11.0.24+8-post-Ubuntu-1ubuntu322.04, mixed mode, sharing)
[root@ubuntu2204 ~]#mkdir -p /data/ruoyi
检查域名是否能够解析ruoyi项目的域名
[root@ubuntu2204 ~]#ping mysql.wang.org
PING mysql.wang.org (10.0.0.200) 56(84) bytes of data.
64 bytes from 10.0.0.200 (10.0.0.200): icmp_seq=1 ttl=64 time=0.198 ms
64 bytes from 10.0.0.200 (10.0.0.200): icmp_seq=2 ttl=64 time=0.426 ms
^C
--- mysql.wang.org ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.198/0.312/0.426/0.114 ms
准备 Jenkins 任务所需的 shell 脚本

#!/bin/bash
#
#********************************************************************
#Author: 
#********************************************************************

# 应用名称
APP=ruoyi
# 应用路径
APP_PATH=/data/$APP
# 监听端口
PORT=80

# 主机列表
HOST_LIST="
10.0.0.201
10.0.0.202
"

# 清理并打包项目
mvn clean package -Dmaven.test.skip=true

# 遍历主机列表
for host in $HOST_LIST; do
    # 在目标主机上杀死所有java进程
    ssh root@$host "killall -9 java" &> /dev/null
    
    # 将新的jar包复制到目标主机的应用路径下
    scp ruoyi-admin/target/*.jar root@$host:${APP_PATH}/${APP}.jar
    
    # 在目标主机上启动应用
    ssh root@$host "nohup java -jar ${APP_PATH}/${APP}.jar \
        --server.port=${PORT} &> /dev/null &"
done

配置任务

验证结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值