案例1:数据库服务部署
MySQL部署
#安装MySQL服务
[root@Services ~]# yum clean all; yum repolist -v
...
Total packages: 8,265
[root@Services ~]# yum -y install mysql.x86_64 mysql-server.x86_64 mysql-devel.x86_64
...
Complete!
[root@Services ~]#
#启动MySQL服务
[root@Services ~]# systemctl enable mysqld #设置MySQL服务开机自启动
[root@Services ~]# systemctl start mysqld #启动MySQL服务
[root@Services ~]# ss -antpul | grep mysql #确认3306端口被监听
tcp LISTEN 0 70 *:33060 *:* users:(("mysqld",pid=6875,fd=22))
tcp LISTEN 0 128 *:3306 *:* users:(("mysqld",pid=6875,fd=25))
[root@Services ~]#
#初始化MySQL服务
[root@Services ~]# mysql
mysql> ALTER USER root@'localhost' IDENTIFIED BY 'Tarena'; #设置root用户密码
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@Services ~]# mysql -hlocalhost -uroot -p'Tarena' -e "STATUS;"
mysql: [Warning] Using a password on the command line interface can be insecure.
--------------
mysql Ver 8.0.26 for Linux on x86_64 (Source distribution)
Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.26 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Binary data as: Hexadecimal
Uptime: 2 min 0 sec
Threads: 2 Questions: 9 Slow queries: 0 Opens: 130 Flush tables: 3 Open tables: 46 Queries per second avg: 0.075
--------------
[root@Services ~]#
#创建HIS项目数据库
[root@Services ~]# mysql -hlocalhost -uroot -p'Tarena'
mysql> CREATE DATABASE his; #创建his库
Query OK, 1 row affected (0.00 sec)
mysql> CREATE USER 'his'@'192.168.88.60' IDENTIFIED BY 'hisadmin'; #创建his用户
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL ON his.* TO 'his'@'192.168.88.60'; #授权his用户
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW GRANTS FOR 'his'@'192.168.88.60'; #查看his用户权限
+----------------------------------------------------------+
| Grants for his@192.168.88.60 |
+----------------------------------------------------------+
| GRANT USAGE ON *.* TO `his`@`192.168.88.60` |
| GRANT ALL PRIVILEGES ON `his`.* TO `his`@`192.168.88.60` |
+----------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> exit
Bye
[root@Services ~]#
#导入HIS项目SQL
[root@Services ~]# ls his.sql
his.sql
[root@Services ~]# mysql -hlocalhost -uroot -p'Tarena' his < his.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@Services ~]# mysql -hlocalhost -uroot -p'Tarena' -e "SHOW TABLES FROM his;"
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------------------------------+
| Tables_in_his |
+----------------------------------+
| bms_bills_record |
| bms_invoice_exp |
| bms_invoice_record |
| bms_operator_settle_record |
| bms_settlement_cat |
| dms_case_history |
| dms_case_model |
| dms_case_model_catalog |
| dms_dise |
| dms_dise_catalog |
| dms_dosage |
| dms_drug |
| dms_drug_model |
| dms_drug_refund_item_record |
| dms_herbal_item_record |
| dms_herbal_model_item |
| dms_herbal_prescription_record |
| dms_medicine_item_record |
| dms_medicine_model_item |
| dms_medicine_prescription_record |
| dms_non_drug |
| dms_non_drug_item_record |
| dms_non_drug_model |
| dms_registration |
| pms_patient |
| sms_dept |
| sms_description |
| sms_frequent_used |
| sms_login_log |
| sms_permission |
| sms_registration_rank |
| sms_role |
| sms_role_permission_relation |
| sms_skd |
| sms_skd_rule |
| sms_skd_rule_item |
| sms_staff |
| sms_workload_record |
+----------------------------------+
[root@Services ~]#
Redis部署
#安装Redis服务
[root@Services ~]# yum -y install redis.x86_64
#配置Redis服务
[root@Services ~]# vim /etc/redis.conf
[root@Services ~]# sed -rn '69p;88p;507p' /etc/redis.conf
bind 0.0.0.0 #监听本地所有网络
protected-mode no #关闭保护模式
requirepass hisadmin #设置redis访问密码
[root@Services ~]#
#启动Redis服务
[root@Services ~]# systemctl enable redis.service #设置Redis服务开机自启动
[root@Services ~]# systemctl start redis.service #启动Redis服务
[root@Services ~]# ss -antpul | grep redis #确认6379端口被监听
tcp LISTEN 0 128 0.0.0.0:6379 0.0.0.0:* users:(("redis-server",pid=7839,fd=6))
[root@Services ~]#
#测试Redis服务
[root@Services ~]# redis-cli -h localhost -p 6379 -a hisadmin info
案例2:Jenkins全局工具配置
配置JDK环境
配置Git工具
配置Maven工具
#Jenkins主机安装Maven
[root@Jenkins ~]# ls apache-maven-3.6.3-bin.tar.gz
apache-maven-3.6.3-bin.tar.gz
[root@Jenkins ~]# tar -xf apache-maven-3.6.3-bin.tar.gz #解包
[root@Jenkins ~]# mv apache-maven-3.6.3 /usr/local/maven #移动到指定目录
[root@Jenkins ~]# ls /usr/local/maven/
bin boot conf lib LICENSE NOTICE README.txt
[root@Jenkins ~]#
#配置Maven环境变量
[root@Jenkins ~]# vim /etc/bashrc #修改bash环境配置
[root@Jenkins ~]# tail -2 /etc/bashrc
export MAVEN_HOME="/usr/local/maven/" #声明MAVEN_HOME变量
export PATH=${MAVEN_HOME}/bin/:$PATH #将MAVEN命令加入PATH
[root@Jenkins ~]# source /etc/bashrc #刷新bash环境
[root@Jenkins ~]# echo ${MAVEN_HOME} #测试变量声明
/usr/local/maven/
[root@Jenkins ~]# mvn -v #测试mvn命令
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/maven
Java version: 11.0.15, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.el8_5.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-372.9.1.el8.x86_64", arch: "amd64", family: "unix"
[root@Jenkins ~]#
#部署Maven本地仓库
[root@Jenkins ~]# ls repository.tar.gz
repository.tar.gz
[root@Jenkins ~]# tar -xPpf repository.tar.gz -C / #解压Maven仓库
[root@Jenkins ~]# ls /var/lib/jenkins/.m2/
repository
[root@Jenkins ~]# ls /var/lib/jenkins/.m2/repository/
aopalliance classworlds commons-beanutils commons-io de joda-time net
backport-util-concurrent cn commons-codec commons-lang io junit org
ch com commons-collections commons-logging javax mysql
[root@Jenkins ~]#
配置邮件工具
#启动邮件服务
[root@Jenkins ~]# systemctl enable postfix.service
[root@Jenkins ~]# systemctl start postfix
[root@Jenkins ~]# ss -antpul | grep master
tcp LISTEN 0 100 127.0.0.1:25 0.0.0.0:* users:(("master",pid=1203,fd=13))
tcp LISTEN 0 100 [::1]:25 [::]:* users:(("master",pid=1203,fd=14))
[root@Jenkins ~]#
#确认邮件接收情况
[root@Jenkins ~]# yum -y install mailx #安装邮件客户端命令
Complete!
[root@Jenkins ~]# mail -u root #查看root用户邮件
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/mail/root": 1 message 1 new
>N 1 没有配置邮箱地址 Fri Feb 24 12:04 18/640 "Test email #4"
& 1
Message 1: #查看邮件内容
From nobody@nowhere Fri Feb 24 12:04:20 2023
Return-Path: <nobody@nowhere>
X-Original-To: root
Delivered-To: root@Jenkins.localdomain
Date: Fri, 24 Feb 2023 12:04:20 +0800 (CST)
From: 没有配置邮箱地址 <nobody@nowhere>
To: root@Jenkins.localdomain
Subject: Test email #4
Content-Type: text/plain; charset=UTF-8
Status: R
This is test email #4 sent from Jenkins
& quit
Held 1 message in /var/mail/root
[root@Jenkins ~]#
案例3:Jenkins后端工程构建
Jenkins中创建HIS-BACKEND工程
#Maven打包参数:Maven执行打包操作时需要调用pom.xml文件,所以需要指定pom.xml文件位置
clean package -Dmaven.test.skip=true #清理旧文件、跳过测试直接打包
测试HIS-BACKEND工程构建
#Jenkins主机确认HIS-BACKEND构建情况
[root@Jenkins ~]# ls /var/lib/jenkins/workspace/ #确认拉取HIS-BACKEND代码
HIS-BACKEND HIS-FONTEND
[root@Jenkins ~]# ls /var/lib/jenkins/workspace/HIS-BACKEND/
HIS-api HIS-common HIS-demo HIS-mbg HIS-service pom.xml
[root@Jenkins ~]# ls /var/lib/jenkins/workspace/HIS-BACKEND/HIS-api/
mvnw mvnw.cmd pom.xml src target
[root@Jenkins ~]# ls /var/lib/jenkins/workspace/HIS-BACKEND/HIS-api/target/ #确认打包
classes generated-sources HIS-api-1.0-SNAPSHOT.jar HIS-api-1.0-SNAPSHOT.jar.original maven-archiver maven-status
[root@Jenkins ~]#
#清理HIS-BACKEND本次构建
[root@Jenkins ~]# rm -rf /var/lib/jenkins/workspace/HIS-BACKEND/
[root@Jenkins ~]#
案例4:Jenkins后端自动发布
添加SSH服务器
HIS-BACKEND工程配置自动发布
Backend主机部署
-
部署OpenJDK环境
#安装OpenJDK-1.8
[root@Backend ~]# yum clean all; yum repolist -v
...
Total packages: 8,265
[root@Backend ~]# yum -y install java-1.8.0-openjdk-devel.x86_64 #安装jdk-1.8#配置JDK环境变量
[root@Backend ~]# ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-1.el8_5.x86_64/ /usr/lib/jvm/jdk #制作软链接
[root@Backend ~]# vim /etc/bashrc #配置JAVA相关环境变量
[root@Backend ~]# tail -3 /etc/bashrc
export JAVA_HOME="/usr/lib/jvm/jdk/" #声明JAVA_HOME
export PATH={JAVA_HOME}/bin/:PATH #将JAVA_HOME加入PATH
export CLASSPATH=. #声明类库路径
[root@Backend ~]# source /etc/bashrc #刷新bash环境
[root@Backend ~]# echo ${JAVA_HOME} #测试变量声明
/usr/lib/jvm/jdk/
[root@Backend ~]# java -version
openjdk version "1.8.0_332"
OpenJDK Runtime Environment (build 1.8.0_332-b09)
OpenJDK 64-Bit Server VM (build 25.332-b09, mixed mode)
[root@Backend ~]# -
部署jar包运行配置文件
#HIS项目采用外置配置文件方式
[root@Backend ~]# mkdir /opt/his/
[root@Backend ~]# scp 192.168.88.10:/root/HIS/HIS-CONFIG/*.yml /opt/his/
application-prod.yml 100% 2690 912.9KB/s 00:00
application.yml 100% 257 374.1KB/s 00:00
[root@Backend ~]# ls /opt/his/
application-prod.yml application.yml
[root@Backend ~]#
HIS-BACKEND工程自动发布测试
#Jenkins主机确认HIS-BACKEND打包成功
[root@Jenkins ~]# ls /var/lib/jenkins/workspace/HIS-BACKEND/HIS-api/target/HIS-api-1.0-SNAPSHOT.jar
/var/lib/jenkins/workspace/HIS-BACKEND/HIS-api/target/HIS-api-1.0-SNAPSHOT.jar
[root@Jenkins ~]#
#Backend主机确认jar包发布情况
[root@Backend ~]# ls /opt/his/
application-prod.yml application.yml HIS-api-1.0-SNAPSHOT.jar
[root@Backend ~]#
#手工运行jar包测试HIS后端程序
[root@Backend his]# java -jar HIS-api-1.0-SNAPSHOT.jar #前台进程
/opt/his/.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE)
...
2023-02-24 13:00:24.881 INFO 9629 --- [ main] com.neu.his.HisApiApplication : Started HisApiApplication in 13.82 seconds (JVM running for 14.352)
#另开终端验证
[root@Backend ~]# ss -antpu | grep :8888 #确认8888端口被监听
tcp LISTEN 0 100 *:8888 *:* users:(("java",pid=9629,fd=63))
[root@Backend ~]# ss -antpu | grep java
#访问测试
[root@Backend ~]# curl http://localhost:8888
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>HIS</h1>
</body>
</html>[root@Backend ~]# curl http://localhost:8888/actuator/health?pretty
{"status":"UP","details":{"rabbit":{"status":"UP","details":{"version":"3.11.5"}},"diskSpace":{"status":"UP","details":{"total":10725883904,"free":8431407104,"threshold":10485760}},"db":{"status":"UP","details":{"database":"MySQL","hello":1}},"elasticsearch":{"status":"UP","details":{"clusterName":"elasticsearch","numberOfNodes":1,"numberOfDataNodes":1,"activePrimaryShards":22,"activeShards":22,"relocatingShards":0,"initializingShards":0,"unassignedShards":20}},"elasticsearchRest":{"status":"UP","details":{"cluster_name":"elasticsearch","status":"yellow","timed_out":false,"number_of_nodes":1,"number_of_data_nodes":1,"active_primary_shards":22,"active_shards":22,"relocating_shards":0,"initializing_shards":0,"unassigned_shards":20,"delayed_unassigned_shards":0,"number_of_pending_tasks":0,"number_of_in_flight_fetch":0,"task_max_waiting_in_queue_millis":0,"active_shards_percent_as_number":52.38095238095239}},"redis":{"status":"UP","details":{"version":"5.0.3"}}}}[root@Backend ~]#
案例5:HIS项目展示
配置Nginx前后端交互
#修改his.conf虚拟主机配置
[root@Fontend ~]# vim /etc/nginx/conf.d/his.conf
[root@Fontend ~]# cat /etc/nginx/conf.d/his.conf
server {
listen 80 default_server;
server_name __;
access_log "/opt/his/log/$host.log";
location / {
root "/opt/his/web/";
index index.html index.htm;
}
#配置api转发
location /prod-api/ {
proxy_pass http://192.168.88.60:8888/;
}
}
[root@Fontend ~]# systemctl restart nginx.service #重启nginx服务
[root@Fontend ~]# ss -antpul | grep nginx
tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=952,fd=6),("nginx",pid=951,fd=6),("nginx",pid=950,fd=6))
[root@Fontend ~]#
HIS效果展示
#确保HIS后端程序正常运行
[root@Fontend ~]# curl http://192.168.88.60:8888/
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>HIS</h1>
</body>
</html>
[root@Fontend ~]#
#浏览器访问HIS前端页面:http://192.168.88.70/
案例6:HIS项目全流程
清理Jenkins工作目录
#手工清理Jenkins工作目录
[root@Jenkins ~]# rm -rf /var/lib/jenkins/workspace/*
[root@Jenkins ~]#
前端全流程
#更新HIS-FONTEND工程
1、构建前清理/opt/his/web/下原有代码
2、构建后自动解压fontend.tar.gz压缩包
3、删除fontend.tar.gz压缩包
#构建前操作
rm -rf /opt/his/web/* #清理旧版本文件
#构建后操作
cd /opt/his/web/ #切换到前端代码存放目录
tar -xf fontend.tar.gz #解压fontend.tar.gz压缩包
rm -rf fontend.tar.gz #清理fontend.tar.gz压缩包
后端全流程
#更新HIS-FONTEND工程
1、构建前终止HIS后端jar进程
2、清理/opt/his/目录下原有jar包
3、发送jar后远程启动jar包
#构建前操作
jps | grep jar | awk '{print $1}' | xargs kill #查找HIS后端jar包pid并杀死进程
rm -rf /opt/his/HIS-api-1.0-SNAPSHOT.jar #清理旧版本jar包
#构建后操作
cd /opt/his/ #切换到jar包目录
nohup java -jar HIS-api-1.0-SNAPSHOT.jar > ./his.log 2>&1 & #后台启动jar包
CI/CD全流程测试
-
前端全流程测试
#查看现有首页内容,注意title内容为"东软云"
[root@Fontend ~]# vim /opt/his/web/index.html
[root@Fontend ~]##Programer主机更新前端代码,title更新为"达内云"
[root@Programer HIS-FONTEND]# vim index.html #修改title内容
[root@Programer HIS-FONTEND]#[root@Programer HIS-FONTEND]# git add ./ #添加修改到暂存区
[root@Programer HIS-FONTEND]# git commit -m "modify index.html" #生成新版本
[master 33da040] modify index.html
1 file changed, 1 insertion(+), 1 deletion(-)
[root@Programer HIS-FONTEND]# git tag v2 #打v2标签
[root@Programer HIS-FONTEND]# git push #推送分支到服务器
枚举对象中: 5, 完成.
对象计数中: 100% (5/5), 完成.
使用 2 个线程进行压缩
压缩对象中: 100% (3/3), 完成.
写入对象中: 100% (3/3), 345 字节 | 345.00 KiB/s, 完成.
总共 3(差异 1),复用 0(差异 0),包复用 0
To http://192.168.88.20/devops/HIS-FONTEND.git
2c9f9bb..33da040 master -> master
[root@Programer HIS-FONTEND]# git push --tags #推送标签到服务器
总共 0(差异 0),复用 0(差异 0),包复用 0
To http://192.168.88.20/devops/HIS-FONTEND.git- [new tag] v2 -> v2
[root@Programer HIS-FONTEND]#
- [new tag] v2 -> v2
#Fontend主机验证构建结果
[root@Fontend ~]# ls /opt/his/web/ #确认fontend.tar.gz清理情况
favicon.ico index.html static
[root@Fontend ~]# vim /opt/his/web/index.html #查看页面内title内容是否为"达内云"
[root@Fontend ~]#
#Jenkins主机确认自动清理工作目录
[root@Jenkins ~]# ls /var/lib/jenkins/workspace/
[root@Jenkins ~]#
-
后端全流程测试
#此时HIS后端jar包应为之前的手工启动前台进程
<!DOCTYPE html> <html lang="cn"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body>
[root@Fontend ~]# curl http://192.168.88.60:8888/HIS
#页面展示为HIS </body> </html>[root@Fontend ~]##Programer主机更新HIS-BACKEND代码
<!DOCTYPE html> <html lang="cn"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body>
[root@Programer ~]# cd HIS/HIS-BACKEND/
[root@Programer HIS-BACKEND]# vim HIS-api/src/main/resources/static/index.html
[root@Programer HIS-BACKEND]# cat HIS-api/src/main/resources/static/index.html医疗信息系统
#修改后端首页内容 </body> </html> [root@Programer HIS-BACKEND]# git add . #添加修改到暂存区 [root@Programer HIS-BACKEND]# git commit -m "modify index.html" #生成版本库 [master 8343263] modify index.html 1 file changed, 2 insertions(+), 2 deletions(-) [root@Programer HIS-BACKEND]# git tag v2 #打v2标签 [root@Programer HIS-BACKEND]# git push --all #推送所有分支到服务器 枚举对象中: 15, 完成. 对象计数中: 100% (15/15), 完成. 使用 2 个线程进行压缩 压缩对象中: 100% (6/6), 完成. 写入对象中: 100% (8/8), 607 字节 | 607.00 KiB/s, 完成. 总共 8(差异 4),复用 0(差异 0),包复用 0 To http://192.168.88.20/devops/HIS-BACKEND.git f582569..8343263 master -> master [root@Programer HIS-BACKEND]# git push --tags #推送所有标签到服务器 总共 0(差异 0),复用 0(差异 0),包复用 0 To http://192.168.88.20/devops/HIS-BACKEND.git * [new tag] v2 -> v2 [root@Programer HIS-BACKEND]#
#确认结果
2023-02-24 15:29:58.229 INFO 9629 --- [ Thread-5] AnnotationNacosInjectedBeanPostProcessor : class com.alibaba.nacos.spring.beans.factory.annotation.AnnotationNacosInjectedBeanPostProcessor was destroying!
[root@Backend his]# #手工运行jar包的前台进程退出
#确认jar包后台运行
[root@Backend his]# ss -antpu | grep :8888
tcp LISTEN 0 100 *:8888 *:* users:(("java",pid=9934,fd=63))
[root@Backend his]#
#测试访问后台首页
[root@Backend his]# curl http://localhost:8888/
<!DOCTYPE html>
<html lang="cn">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>医疗信息系统</h1>
</body>
</html>
[root@Backend his]#