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 |
+----------------------------------+
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访问密码
#启动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))
#测试Redis服务
[root@Services ~]# redis-cli -h localhost -p 6379 -a hisadmin info
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 ~]# 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 ~]# 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
Jenkins后端工程构建
#Maven打包参数:Maven执行打包操作时需要调用pom.xml文件,所以需要指定pom.xml文件位置
clean package -Dmaven.test.skip=true #清理旧文件、跳过测试直接打包
#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/
Jenkins后端自动发布
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
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"}}}}
HIS项目展示
#修改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 __;
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))
#浏览器访问HIS前端页面:http://192.168.88.70/