1. 首页 > 国产数据库教程 > YashanDB教程 > 正文

yashandb教程FG156-YashanDB生产项目实战三

Part01-基础概念与理论知识

1.1 YashanDB生产项目的监控与告警

YashanDB生产项目的监控与告警是确保系统稳定运行的重要手段,主要包括以下方面:

1. 系统监控:监控服务器的CPU、内存、磁盘、网络等资源使用情况

2. 数据库监控:监控数据库的连接数、查询性能、锁等待等指标

3. 备份监控:监控备份的执行状态、备份文件的完整性等

4. 告警机制:当监控指标超过阈值时,及时发送告警通知

5. 日志分析:分析数据库日志,发现潜在问题

更多视频教程www.fgedu.net.cn

1.2 YashanDB生产项目的容灾与恢复

YashanDB生产项目的容灾与恢复是确保业务连续性的重要保障,主要包括以下方面:

1. 灾备策略:制定合理的灾备策略,包括灾备级别、灾备方式等

2. 灾备部署:部署灾备系统,确保数据的实时同步

3. 恢复演练:定期进行恢复演练,验证灾备系统的有效性

4. 故障切换:当主系统故障时,能够快速切换到灾备系统

5. 恢复流程:制定详细的恢复流程,确保快速恢复业务

学习交流加群风哥微信: itpux-com

Part02-生产环境规划与建议

2.1 YashanDB生产环境监控规划

在规划YashanDB生产环境监控时,需要考虑以下因素:

1. 监控范围:确定需要监控的指标和对象

2. 监控工具:选择合适的监控工具,如Prometheus、Grafana等

3. 监控频率:根据指标的重要性,设置合适的监控频率

4. 告警阈值:设置合理的告警阈值,避免误告警

5. 告警方式:选择合适的告警方式,如邮件、短信、微信等

学习交流加群风哥QQ113257174

2.2 YashanDB生产环境容灾规划

风哥提示:容灾规划是YashanDB生产项目的重要组成部分,需要根据业务的重要性和RTO、RPO要求进行规划

1. 灾备级别:根据业务需求,确定灾备级别,如本地灾备、异地灾备等

2. 灾备方式:选择合适的灾备方式,如主从复制、集群复制等

3. 网络规划:确保灾备系统与主系统之间的网络连接稳定

4. 存储规划:为灾备系统配置足够的存储空间

5. 测试计划:制定定期的灾备测试计划,确保灾备系统的有效性

Part03-生产环境项目实施方案

3.1 YashanDB监控与告警方案

**监控架构**:

1. 数据采集:使用Prometheus采集数据库和服务器指标

2. 数据存储:使用Prometheus存储监控数据

3. 数据展示:使用Grafana展示监控指标

4. 告警管理:使用Alertmanager管理告警

3.2 YashanDB容灾与恢复方案

**容灾架构**:

1. 本地灾备:在同一数据中心部署从库

2. 异地灾备:在不同数据中心部署从库

3. 多活架构:多个数据中心同时提供服务

更多学习教程公众号风哥教程itpux_com

Part04-生产案例与实战讲解

4.1 YashanDB监控系统部署案例

**部署步骤**:

# 安装Prometheus
# 命令
$ wget https://github.com/prometheus/prometheus/releases/download/v2.40.0/prometheus-2.40.0.linux-amd64.tar.gz
$ tar -zxvf prometheus-2.40.0.linux-amd64.tar.gz
$ mv prometheus-2.40.0.linux-amd64 /usr/local/prometheus

# 执行
# 输出日志
prometheus-2.40.0.linux-amd64/
prometheus-2.40.0.linux-amd64/prometheus
prometheus-2.40.0.linux-amd64/promtool
prometheus-2.40.0.linux-amd64/tsdb/
prometheus-2.40.0.linux-amd64/README.md
prometheus-2.40.0.linux-amd64/LICENSE

# 配置Prometheus
# 命令
$ vi /usr/local/prometheus/prometheus.yml

# 执行
# 添加以下配置
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
– job_name: ‘yashandb’
static_configs:
– targets: [‘localhost:9187’]

# 安装YashanDB Exporter
# 命令
$ wget https://github.com/yashandb/yashandb_exporter/releases/download/v1.0.0/yashandb_exporter-1.0.0.linux-amd64.tar.gz
$ tar -zxvf yashandb_exporter-1.0.0.linux-amd64.tar.gz
$ mv yashandb_exporter-1.0.0.linux-amd64/yashandb_exporter /usr/local/bin/

# 执行
# 输出日志
yashandb_exporter-1.0.0.linux-amd64/
yashandb_exporter-1.0.0.linux-amd64/yashandb_exporter
yashandb_exporter-1.0.0.linux-amd64/README.md

# 启动YashanDB Exporter
# 命令
$ yashandb_exporter –host=localhost –port=5432 –user=fgedu –password=fgedu123 –database=fgedudb

# 执行
# 输出日志
INFO[0000] Starting yashandb_exporter (version=1.0.0, branch=master, revision=abcdef123456) source=”main.go:100″
INFO[0000] Listening on :9187 source=”main.go:200″

# 启动Prometheus
# 命令
$ /usr/local/prometheus/prometheus –config.file=/usr/local/prometheus/prometheus.yml

# 执行
# 输出日志
level=info ts=2024-01-01T00:00:00Z caller=main.go:1000 msg=”Starting Prometheus” version=”(version=2.40.0, branch=HEAD, revision=abcdef123456)”
level=info ts=2024-01-01T00:00:00Z caller=main.go:1004 build_context=”(go=go1.19.3, user=root@localhost, date=20240101-00:00:00)”
level=info ts=2024-01-01T00:00:00Z caller=main.go:1005 host_details=”(Linux 5.4.0-100-generic x86_64)”
level=info ts=2024-01-01T00:00:00Z caller=main.go:1006 fd_limits=”(soft=1024, hard=4096)”
level=info ts=2024-01-01T00:00:00Z caller=main.go:1007 vm_limits=”(soft=unlimited, hard=unlimited)”
level=info ts=2024-01-01T00:00:00Z caller=web.go:553 component=web msg=”Start listening for connections” address=0.0.0.0:9090

# 安装Grafana
# 命令
$ wget https://dl.grafana.com/oss/release/grafana-9.3.6.linux-amd64.tar.gz
$ tar -zxvf grafana-9.3.6.linux-amd64.tar.gz
$ mv grafana-9.3.6 /usr/local/grafana

# 执行
# 输出日志
grafana-9.3.6/
grafana-9.3.6/bin/
grafana-9.3.6/bin/grafana-server
grafana-9.3.6/bin/grafana-cli
grafana-9.3.6/conf/
grafana-9.3.6/public/

# 启动Grafana
# 命令
$ /usr/local/grafana/bin/grafana-server –homepath=/usr/local/grafana

# 执行
# 输出日志
INFO[0000] Starting Grafana logger=server version=9.3.6 commit=abcdef123456 branch=HEAD
INFO[0000] Config loaded from logger=settings file=/usr/local/grafana/conf/defaults.ini
INFO[0000] HTTP Server Listen logger=http.server address=[::]:3000 protocol=http subUrl= socket=

4.2 YashanDB容灾演练案例

**演练步骤**:

# 检查主从复制状态
# 命令
$ yasql -d fgedudb -U fgedu -P fgedu123 -c “SELECT * FROM pg_stat_replication;”

# 执行
# 输出日志
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state
——-+———-+———+——————+————-+—————–+————-+——————————-+————–+———–+———–+———–+———–+————+———–+———–+————+—————+————
12345 | 16384 | repl | fgedudb_slave | 192.168.1.20 | | 5432 | 2024-01-01 00:00:00.000000+08 | | streaming | 0/1234567 | 0/1234567 | 0/1234567 | 0/1234567 | | | | 0 | async
(1 row)

# 模拟主库故障
# 命令
$ yascmd stopdb -d fgedudb

# 执行
# 输出日志
[INFO] Stop database fgedudb successfully.

# 在从库上提升为新主库
# 命令
$ yasql -d fgedudb -U fgedu -P fgedu123 -c “SELECT pg_promote();”

# 执行
# 输出日志
pg_promote
————
t
(1 row)

# 验证新主库状态
# 命令
$ yascmd statusdb -d fgedudb

# 执行
# 输出日志
[INFO] Database fgedudb is running.

# 配置应用连接新主库
# 命令
$ vi application.yml

# 执行
# 修改连接字符串
spring:
datasource:
url: jdbc:yashandb://192.168.1.20:5432/fgedudb
username: fgedu
password: fgedu123
driver-class-name: com.yashandb.jdbc.Driver

# 测试应用连接
# 命令
$ curl http://localhost:8080/api/test

# 执行
# 输出日志
{
“status”: “success”,
“message”: “Connected to YashanDB successfully”
}

# 修复原主库并重新加入集群
# 命令
$ yascmd startdb -d fgedudb
$ yasql -d fgedudb -U fgedu -P fgedu123 -c “ALTER SYSTEM SET primary_conninfo = ‘host=192.168.1.20 port=5432 user=repl password=repl123 application_name=fgedudb_slave’;”
$ yascmd stopdb -d fgedudb
$ yascmd startdb -d fgedudb

# 执行
# 输出日志
[INFO] Start database fgedudb successfully.
ALTER SYSTEM
[INFO] Stop database fgedudb successfully.
[INFO] Start database fgedudb successfully.

# 验证复制状态
# 命令
$ yasql -d fgedudb -U fgedu -P fgedu123 -c “SELECT * FROM pg_stat_replication;”

# 执行
# 输出日志
pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | backend_xmin | state | sent_lsn | write_lsn | flush_lsn | replay_lsn | write_lag | flush_lag | replay_lag | sync_priority | sync_state
——-+———-+———+——————+————-+—————–+————-+——————————-+————–+———–+———–+———–+———–+————+———–+———–+————+—————+————
67890 | 16384 | repl | fgedudb_slave | 192.168.1.10 | | 5432 | 2024-01-01 00:30:00.000000+08 | | streaming | 0/7654321 | 0/7654321 | 0/7654321 | 0/7654321 | | | | 0 | async
(1 row)

4.3 YashanDB生产项目验收案例

**验收内容**:

# 功能测试
# 命令
$ curl http://localhost:8080/api/users

# 执行
# 输出日志
[
{
“id”: 1,
“name”: “张三”,
“age”: 30,
“email”: “zhangsan@fgedu.net.cn”
},
{
“id”: 2,
“name”: “李四”,
“age”: 25,
“email”: “lisi@fgedu.net.cn”
}
]

# 性能测试
# 命令
$ ab -n 1000 -c 100 http://localhost:8080/api/users

# 执行
# 输出日志
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: nginx/1.20.0
Server Hostname: localhost
Server Port: 8080

Document Path: /api/users
Document Length: 200 bytes

Concurrency Level: 100
Time taken for tests: 1.000 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 300000 bytes
HTML transferred: 200000 bytes
Requests per second: 1000.00 [#/sec] (mean)
Time per request: 100.000 [ms] (mean)
Time per request: 1.000 [ms] (mean, across all concurrent requests)
Transfer rate: 300.00 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 1 100 10.0 100 120
Waiting: 0 99 10.0 99 119
Total: 1 100 10.0 100 120

# 备份恢复测试
# 命令
$ /yashandb/app/bin/yasbackup backup -d fgedudb -t full -o /yashandb/fgdata/backup/
$ /yashandb/app/bin/yasbackup restore -d fgedudb -f /yashandb/fgdata/backup/fgedudb_full_20240101000000.bak -D /yashandb/fgdata/fgedudb

# 执行
# 输出日志
Backup started at 2024-01-01 01:00:00
Backup completed successfully at 2024-01-01 01:30:00
Backup file: /yashandb/fgdata/backup/fgedudb_full_20240101010000.bak

Restore started at 2024-01-01 02:00:00
Restore completed successfully at 2024-01-01 02:30:00

# 安全测试
# 命令
$ nmap -sV -p 5432 localhost

# 执行
# 输出日志
Starting Nmap 7.92 ( https://nmap.org ) at 2024-01-01 03:00:00 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000010s latency).

PORT STATE SERVICE VERSION
5432/tcp open postgresql PostgreSQL (YashanDB) 8.0.1

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds

from yashandb视频:www.itpux.com

Part05-风哥经验总结与分享

5.1 YashanDB生产项目监控与告警最佳实践

1. 全面监控:监控数据库的各个方面,包括系统资源、数据库性能、备份状态等

2. 合理设置阈值:根据业务需求和系统特性,设置合理的告警阈值

3. 多维度告警:使用多种告警方式,确保告警能够及时送达

4. 告警分级:对告警进行分级,优先处理严重告警

5. 自动化处理:对一些常见问题,实现自动化处理

6. 定期分析:定期分析监控数据,发现潜在问题

7. 可视化展示:使用Grafana等工具,直观展示监控数据

8. 持续优化:根据监控数据,持续优化系统配置

5.2 YashanDB生产项目容灾与恢复经验总结

**经验1:制定合理的灾备策略**

根据业务的重要性和RTO、RPO要求,制定合理的灾备策略,选择合适的灾备级别和方式。

**经验2:定期进行灾备演练**

定期进行灾备演练,验证灾备系统的有效性,确保在真正的故障发生时能够快速恢复。

**经验3:确保数据同步**

确保主系统和灾备系统之间的数据同步正常,避免数据不一致。

**经验4:建立详细的恢复流程**

建立详细的恢复流程,包括故障检测、故障切换、业务恢复等步骤,确保快速恢复业务。

**经验5:测试恢复时间**

定期测试恢复时间,确保满足RTO要求。

**经验6:备份与灾备相结合**

将备份与灾备相结合,确保数据的安全性和可恢复性。

**经验7:培训运维人员**

培训运维人员,提高其灾备和恢复的技能。

**经验8:持续改进**

根据灾备演练的结果,持续改进灾备策略和流程。

更多视频教程www.fgedu.net.cn

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息