目录
导读
我们在开发中需要随时监听服务的状态,以便我们精确查找问题,包括进程、线程、垃圾回收、内存等等,在运营期间我们不可能随时盯着服务器,在服务发生异常崩溃时自动邮件提醒也是非常必要的。在Multienty项目的multienty-admin模块既可,其实multienty-admin就是Spring Boot Admin的封装,让我们可以更简单的使用它。
在使用之前请先拉取Multienty最新代码
https://github.com/kutasms/multienty
或者
同样的,您可以从下面的地址拉取本系列demo源代码
https://github.com/kutasms/saas-demo
或者
修改multienty-admin配置
修改multienty-admin的bootstrap.yml文件
server:
port: 9986
logging:
config: classpath:logback-spring.xml
spring:
application:
name: multienty-admin
cloud:
nacos:
discovery:
# 以下内容根据实际情况配置
server-addr: nacos.xxxx.cn:xxxxx
namespace: xxxx-xxx-xxx-xxxxx
username: xxxx
password: xxxx
metadata:
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
namespace: ${spring.cloud.nacos.discovery.namespace}
username: ${spring.cloud.nacos.discovery.username}
password: ${spring.cloud.nacos.discovery.password}
file-extension: yml
extension-configs[0]:
data-id: multienty.yml
group: DEFAULT_GROUP
refresh: true
然后启动multienty-admin(您也可以修改server.port)
修改saasdemo项目配置
saasdemo-master, saasdemo-order, saasdemo-user 三个子模块的bootstrap.yml配置文件增加
spring.cloud.nacos.discovery.metadata节点,如下:
spring:
application:
name: saasdemo-master
cloud:
nacos:
discovery:
server-addr: nacos.xxxx.cn:xxxx
namespace: xxxxx-xxx-xxx-xxxxx
username: xxxx
password: xxxx
metadata:
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
修改nacos配置
修改multienty.yml配置
增加spring.security、spring.boot.admin和management节点
spring:
security:
user:
# 这里可以设置成您自己的用户名和密码
name: "admin"
password: "admin123"
boot:
admin:
discovery:
enabled: true
client:
enabled: true
url: http://localhost:9986
username: ${spring.security.user.name}
password: ${spring.security.user.password}
instance:
name: ${spring.application.name}
metadata:
user.name: ${spring.security.user.name}
user.password: ${spring.security.user.password}
management:
health:
redis:
enabled: false
sentinel:
enabled: false
ldap:
enabled: false
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
新增multienty-admin-dev.yml配置
spring:
boot:
admin:
notify:
mail:
to: xxx@163.com
from: xxx@qq.com
mail:
default-encoding: UTF-8
# 邮件服务器
host: smtp.qq.com
# 用户名
username: "xxxx@qq.com"
# 注意这里的密码要用授权码
password: "xxxxxx"
properties:
mail:
debug: false
smtp:
port: 465
auth: true
ssl:
enable: true
socket-factory: sf
测试
启动saasdemo-master、saasdemo-user、saasdemo-order三个子模块
访问localhost:9986
然后我们可以看Email通知