IP机器与部署组件
部署思路顺序:
1 安装mysql
wget https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
systemctl enable mysqld --now
systemctl status mysqld
#默认密码
cat /var/log/mysqld.log | awk '/password/ {print $NF}'
mysql -uroot -p'hWgmWK.r=6%I'
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> set password = password("123456");
mysql> flush privileges;
grant all privileges on *.* to 'root'@'192.168.%.%' identified by '123456';
2 安装redis
yum install epel-release -y
yum install redis -y
systemctl enable redis --now
systemctl status redis
改/etc/redis.conf
bind 0.0.0.0
设置redis的访问密码
部署微服务治理层
0 安装 java 1.8.0_262 和 maven3.8.8 (略)
/etc/profile最后面
export JAVA_HOME=/opt/software/jdk1.8
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export MAVEN_HOME=/opt/software/maven3.8
export PATH=$PATH:$MAVEN_HOME/bin
1 部署nacos (单机版) (端口8848)
wget https://linux.oldxu.net/nacos-mysql.sql
wget https://linux.oldxu.net/nacos-server-2.1.1.tar.gz
mysql -uroot -p123456 -e "create database nacos;"
mysql -uroot -p123456 nacos < nacos-mysql.sql
cd /root/k8sFile/project/microServer/nacos/nacos/conf
#修改数据库配置信息
vim application.properties
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456
#单机模式启动nacos-server
cd /root/k8sFile/project/microServer/nacos/nacos/bin
[root@node5-db bin]# sh startup.sh -m standalone
/opt/software/jdk1.8/bin/java -Djava.ext.dirs=/opt/software/jdk1.8/jre/lib/ext:/opt/software/jdk1.8/lib/ext -Xms512m -Xmx512m -Xmn256m -Dnacos.standalone=true -Dnacos.member.list= -Xloggc:/root/k8sFile/project/microServer/nacos/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/root/k8sFile/project/microServer/nacos/nacos/plugins/health,/root/k8sFile/project/microServer/nacos/nacos/plugins/cmdb,/root/k8sFile/project/microServer/nacos/nacos/plugins/selector -Dnacos.home=/root/k8sFile/project/microServer/nacos/nacos -jar /root/k8sFile/project/microServer/nacos/nacos/target/nacos-server.jar --spring.config.additional-location=file:/root/k8sFile/project/microServer/nacos/nacos/conf/ --logging.config=/root/k8sFile/project/microServer/nacos/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
nacos is starting with standalone
nacos is starting,you can check the /root/k8sFile/project/microServer/nacos/nacos/logs/start.out
访问nacos的 http://192.168.79.35:8848/nacos/#/login 账号密码 nacos/nacos
2 部署sentinel (限流组件)(jar包) (业务8718 、API调用8719)
wget https://linux.oldxu.net/sentinel-dashboard-1.8.5.jar
运行sentinel,-Dserver.port=8718 用来指定sentinel控制台访问端口:
nohup java -Dserver.port=8718 \
-Dcsp.sentinel.dashboard.server=localhost:8718 \
-Dproject.name=sentinel-dashboard \
-Dcsp.sentinel.api.port.port=8719 \
-jar sentinel-dashboard-1.8.5.jar &> /var/log/sentinel.log &
访问sentinel,通过http://IP:8718 ,登录用户名及密码均为 sentinel
2.1 应用使用sentinel,需要先添加依赖 (开发)
为pom.xml 添加依赖
2.2 、为应用添加sentinel配置,(服务配置一般保存在nacos中,在nacos对应配置添加如下字段即可)
例如:
spring:
application:
name: ruoyi-auth # 应用名称
cloud:
sentinel: # 取消控制台懒加载
eager: true
transport:
dashboard: 127.0.0.1:8718 # 控制台地址
3 部署skywalking链路追踪组件 (收集器(11800端口),web页面(8080端口))
wget https://linux.oldxu.net/apache-skywalking-apm-8.8.1.tar.gz
tar xf apache-skywalking-apm-8.8.1.tar.gz
#运行skywalking,它会运行两个组件,一个收集器(11800端口),一个web页面(8080端口)
cd /root/k8sFile/project/microServer/03-skywalking/apache-skywalking-apm-bin/bin
[root@node5-db bin]# sh startup.sh
SkyWalking OAP started successfully!
SkyWalking Web Application started successfully!
访问skywalking,通过 http://IP:8080
3.1 如果项目需要使用skywalking,需要在启动业务时加载skywalking-agent的jar包
示例如下
wget https://linux.oldxu.net/apache-skywalking-java-agent-8.8.0.tgz
tar xf apache-skywalking-java-agent-8.8.0.tgz
[root@node5-db 03-skywalking]# ls skywalking-agent/
activations bootstrap-plugins config LICENSE licenses logs NOTICE optional-plugins optional-reporter-plugins plugins skywalking-agent.jar
# 运行java应用,而后指定
java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-auth \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-har ruoyi-auth/target/ruoyi-auth.jar &
4 部署微服务组件
#79.34操作
#git clone https://gitee.com/y_project/RuoYi-Cloud 或者使用oldxu的:
wget https://linux.oldxu.net/RuoYi-Cloud-20220814.zip
unzip RuoYi-Cloud-20220814.zip
[root@node4 danji-ruoyi]# cd RuoYi-Cloud
[root@node4 RuoYi-Cloud]# ls
bin docker LICENSE pom.xml README.md ruoyi-api ruoyi-auth ruoyi-common ruoyi-gateway ruoyi-modules ruoyi-ui ruoyi-visual sql
scp -r sql/ 192.168.79.35:/root
4.1 创库,导入sql
RuoYi-Cloud项目所需的数据文件
mysql -uroot -p
mysql> create database `ry-cloud` charset utf8;
mysql> show database;
[root@node5-db sql]# ls
quartz.sql ry_20220814.sql ry_config_20220510.sql ry_seata_20210128.sql
[root@node5-db sql]# mysql -uroot -p123456 ry-cloud < ry_20220814.sql
#检查
mysql> use ry-cloud;
mysql> show tables;
+--------------------+
| Tables_in_ry-cloud |
+--------------------+
| 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 |
+--------------------+
19 rows in set (0.00 sec)
创ry-config库。导入ruoyi-config配置的sql文件。
mysql -uroot -p
mysql> create database `ry-config` charset utf8;
mysql -uroot -p123456 ry-config < ry_config_20220510.sql
然后修改 nacos 的 conf/application.properties 配置文件,将默认nacos库指向新的ry-config库
### Count of DB:
db.num=1
### Connect URL of DB:
#db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.url.0=jdbc:mysql://127.0.0.1:3306/ry-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456
#重启nacos
sh shutdown.sh
sh startup.sh -m standalone
检查nacos是否已经注入了业务所需的配置文件相关数据;
打包项目
#79.34操作
cd RuoYi-Cloud/
mvn clean package -Dmaven.test.skip=true
#打包完成后,整个约有620MB大小
对单独某模块打包操作
#比如 单独对 ruoyi-auth模块打包
cd RuoYi-Cloud/
mvn package -Dmaven.test.skip=true -pl ruoyi-auth -am
4.2 部署system组件
#机器79.34
cd /root/k8sFile/project/danji-ruoyi/guanWang
wget https://linux.oldxu.net/apache-skywalking-java-agent-8.8.0.tgz
tar xf apache-skywalking-java-agent-8.8.0.tgz
[root@node4 guanWang]# ls
RuoYi-Cloud skywalking-agent
1、修改system连接数据库信息,信息都存储在nacos组件中,需要登录nacos修改ruoyi-system-dev.yml
ruoyi-system-dev.yml 。 注意cloud是与redis同级的 (配置sentinel的)
# spring配置
spring:
redis:
host: 192.168.79.35
port: 6379
password:
cloud:
sentinel:
eager: true
transport:
dashboard: 192.168.79.35:8718
datasource:
druid:
stat-view-servlet:
enabled: true
loginUsername: admin
loginPassword: 123456
dynamic:
druid:
initial-size: 5
min-idle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,slf4j
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
# 主库数据源
master:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.79.35:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: 123456
# 从库数据源
# slave:
# username:
# password:
# url:
# driver-class-name:
# seata: true # 开启seata代理,开启后默认每个数据源都代理,如果某个不需要代理可单独关闭
# seata配置
seata:
# 默认关闭,如需启用spring.datasource.dynami.seata需要同时开启
enabled: false
# Seata 应用编号,默认为 ${spring.application.name}
application-id: ${spring.application.name}
# Seata 事务组编号,用于 TC 集群名
tx-service-group: ${spring.application.name}-group
# 关闭自动代理
enable-auto-data-source-proxy: false
# 服务配置项
service:
# 虚拟组和分组的映射
vgroup-mapping:
ruoyi-system-group: default
config:
type: nacos
nacos:
serverAddr: 127.0.0.1:8848
group: SEATA_GROUP
namespace:
registry:
type: nacos
nacos:
application: seata-server
server-addr: 127.0.0.1:8848
namespace:
# mybatis配置
mybatis:
# 搜索指定包别名
typeAliasesPackage: com.ruoyi.system
# 配置mapper的扫描,找到所有的mapper.xml映射文件
mapperLocations: classpath:mapper/**/*.xml
# swagger配置
swagger:
title: 系统模块接口文档
license: Powered By ruoyi
licenseUrl: https://ruoyi.vip
启动ruoyi-system
#启动ruoyi-system
nohup java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-system \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-Dspring.profiles.active=dev \
-Dspring.cloud.nacos.config.file-extension=yml \
-Dspring.cloud.nacos.discovery.server-addr=192.168.79.35:8848 \
-Dspring.cloud.nacos.config.server-addr=192.168.79.35:8848 \
-jar RuoYi-Cloud/ruoyi-modules/ruoyi-system/target/ruoyi-modules-system.jar &>/var/log/system.log &
ruoyi-system已注册到nacos:
4.3 部署auth组件
1、修改auth连接redis信息,信息都存储在nacos组件中,需要登录nacos修改ruoyi-auth-dev.yml
ruoyi-auth-dev.yml
spring:
redis:
host: 192.168.79.35
port: 6379
password:
cloud:
sentinel:
eager: true
transport:
dashboard: 192.168.79.35:8718
启动ruoyi-auth
#启动ruoyi-auth
nohup java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-auth \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-Dspring.profiles.active=dev \
-Dspring.cloud.nacos.config.file-extension=yml \
-Dspring.cloud.nacos.discovery.server-addr=192.168.79.35:8848 \
-Dspring.cloud.nacos.config.server-addr=192.168.79.35:8848 \
-jar RuoYi-Cloud/ruoyi-auth/target/ruoyi-auth.jar &>/var/log/auth.log &
4.4 部署gateway组件
1、修改gateway连接redis信息,信息都存储在nacos组件中,需要登录nacos修改ruoyi-gateway-dev.yml
ruoyi-gateway-dev.yml
spring:
redis:
host: 192.168.79.35
port: 6379
password:
cloud:
sentinel:
eager: true
transport:
dashboard: 192.168.79.35:8718
gateway:
discovery:
locator:
lowerCaseServiceId: true
enabled: true
routes:
# 认证中心
- id: ruoyi-auth
uri: lb://ruoyi-auth
predicates:
- Path=/auth/**
filters:
# 验证码处理
- CacheRequestFilter
- ValidateCodeFilter
- StripPrefix=1
# 代码生成
- id: ruoyi-gen
uri: lb://ruoyi-gen
predicates:
- Path=/code/**
filters:
- StripPrefix=1
# 定时任务
- id: ruoyi-job
uri: lb://ruoyi-job
predicates:
- Path=/schedule/**
filters:
- StripPrefix=1
# 系统模块
- id: ruoyi-system
uri: lb://ruoyi-system
predicates:
- Path=/system/**
filters:
- StripPrefix=1
# 文件服务
- id: ruoyi-file
uri: lb://ruoyi-file
predicates:
- Path=/file/**
filters:
- StripPrefix=1
# 安全配置
security:
# 验证码
captcha:
enabled: true
type: math
# 防止XSS攻击
xss:
enabled: true
excludeUrls:
- /system/notice
# 不校验白名单
ignore:
whites:
- /auth/logout
- /auth/login
- /auth/register
- /*/v2/api-docs
- /csrf
启动ruoyi-gateway
nohup java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-gateway \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-Dspring.profiles.active=dev \
-Dspring.cloud.nacos.config.file-extension=yml \
-Dspring.cloud.nacos.discovery.server-addr=192.168.79.35:8848 \
-Dspring.cloud.config.server-addr=192.168.79.35:8848 \
-jar RuoYi-Cloud/ruoyi-gateway/target/ruoyi-gateway.jar &>/var/log/gateway.log
备注:会一直报这个127.0.0.1:9848。但已注册到nacos 、sentinel 、skywalking。 可暂时忽略
后面已处理,详细看:https://blog.csdn.net/Nightwish5/article/details/130303765
4.5 部署gateway组件
1、修改monitor,信息都存储在nacos组件中,需要登录nacos修改ruoyi-monitor-dev.yml
# spring
spring:
security:
user:
name: ruoyi
password: 123456
boot:
admin:
ui:
title: 若依服务状态监控
2、启动ruoyi-monitor
nohup java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-monitor \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-Dspring.profiles.active=dev \
-Dspring.cloud.nacos.config.file-extension=yml \
-Dspring.cloud.nacos.discovery.server-addr=192.168.79.35:8848 \
-Dspring.cloud.nacos.config.server-addr=192.168.79.35:8848 \
-jar RuoYi-Cloud/ruoyi-visual/ruoyi-monitor/target/ruoyi-visual-monitor.jar &>/var/log/monitor.log &
访问监控页面 192.168.79.34:9100
4.6 部署微服务前端UI
#安装nodejs , npm
sudo curl -sL -o /etc/yum.repos.d/khara-nodejs.repo https://copr.fedoraproject.org/coprs/khara/nodejs/repo/epel-7/khara-nodejs-epel-7.repo
sudo yum install -y nodejs nodejs-npm
#安装nginx
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum -y install nginx
1、修改配置
# 修改ui连接gateway地址
cd /root/k8sFile/project/danji-ruoyi/guanWang/RuoYi-Cloud/ruoyi-ui
vim vue.config.js
// webpack-dev-server 相关配置
devServer: {
host: '0.0.0.0',
port: port,
open: true,
proxy: {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `http://192.168.79.34:8080`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
},
disableHostCheck: true
},
2、编译项目
#注意 一定要进入对应的前端目录 。否则执行npm会报错
cd /root/k8sFile/project/danji-ruoyi/guanWang/RuoYi-Cloud/ruoyi-ui
[root@node4 ruoyi-ui]# ls
babel.config.js bin build package.json public README.md src vue.config.js
npm install --registry=https://registry.npmmirror.com
npm run build:prod
3、拷贝编译后的代码至于Nginx站点目录
cd /root/k8sFile/project/danji-ruoyi/guanWang/RuoYi-Cloud/ruoyi-ui
[root@node4 ruoyi-ui]# ls dist/
favicon.ico html index.html index.html.gz robots.txt static
mkdir -p /code
cp -r dist/* /code
4、编写Nginx配置文件
[root@node4 conf.d]# cat ruoyi.oldxu.net.conf
server {
listen 20080;
server_name ruoyi.oldxu.net;
charset utf-8;
root /code;
location / {
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.79.84:8080/;
}
}
5、打开浏览器,输入:http://192.168.79.34:20080 默认账户/密码admin/admin123
END
其他
#启动所有微服务脚本:
#!/bin/bash
cd /root/k8sFile/project/danji-ruoyi/guanWang
#1 ruoyi-system
nohup java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-system \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-Dspring.profiles.active=dev \
-Dspring.cloud.nacos.config.file-extension=yml \
-Dspring.cloud.nacos.discovery.server-addr=192.168.79.35:8848 \
-Dspring.cloud.nacos.config.server-addr=192.168.79.35:8848 \
-jar RuoYi-Cloud/ruoyi-modules/ruoyi-system/target/ruoyi-modules-system.jar &>/var/log/system.log &
sleep 45
#2 ruoyi-auth
nohup java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-auth \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-Dspring.profiles.active=dev \
-Dspring.cloud.nacos.config.file-extension=yml \
-Dspring.cloud.nacos.discovery.server-addr=192.168.79.35:8848 \
-Dspring.cloud.nacos.config.server-addr=192.168.79.35:8848 \
-jar RuoYi-Cloud/ruoyi-auth/target/ruoyi-auth.jar &>/var/log/auth.log &
sleep 45
#3 gateway
nohup java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-gateway \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-Dspring.profiles.active=dev \
-Dspring.cloud.nacos.config.file-extension=yml \
-Dspring.cloud.nacos.discovery.server-addr=192.168.79.35:8848 \
-Dspring.cloud.config.server-addr=192.168.79.35:8848 \
-jar RuoYi-Cloud/ruoyi-gateway/target/ruoyi-gateway.jar &>/var/log/gateway.log &
sleep 45
#4 monitor
nohup java -javaagent:./skywalking-agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=ruoyi-monitor \
-Dskywalking.collector.backend_service=192.168.79.35:11800 \
-Dspring.profiles.active=dev \
-Dspring.cloud.nacos.config.file-extension=yml \
-Dspring.cloud.nacos.discovery.server-addr=192.168.79.35:8848 \
-Dspring.cloud.nacos.config.server-addr=192.168.79.35:8848 \
-jar RuoYi-Cloud/ruoyi-visual/ruoyi-monitor/target/ruoyi-visual-monitor.jar &>/var/log/monitor.log &