> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lwops.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 8.10. 达梦数据库

### 8.10.1. 安装达梦数据库驱动

```plain theme={null}
# 挂载iso镜像
mount dm7_setup_rh7_64_ent_7.6.1.60_20200603.iso /mnt
# 默认安装路径为/opt/dmdbms ，先创建文件夹
mkdir /opt/dmdbms
cd /mnt
#安装
./DMInstall.bin -i
Please select the installer's language (E/e:English C/c:Chinese) [E/e]:c
是否输入Key文件路径? (Y/y:是 N/n:否) [Y/y]:n
是否设置时区? (Y/y:是 N/n:否) [Y/y]:y
请选择设置时区 [21]:21
安装类型:
1 典型安装
2 服务器
3 客户端
4 自定义
请选择安装类型的数字序号 [1 典型安装]:4
1 服务器组件
2 客户端组件
2.1 DM管理工具
2.2 DM性能监视工具
2.3 DM数据迁移工具
2.4 DM控制台工具
2.5 DM审计分析工具
2.6 SQL交互式查询工具
3 驱动
4 用户手册
5 数据库服务
5.1 实时审计服务
5.2 作业服务
5.3 实例监控服务
5.4 辅助插件服务
请选择安装组件的序号 (使用空格间隔) [1 2 3 4 5]:3
所需空间: 336M

请选择安装目录 [/opt/dmdbms]:
可用空间: 38G
是否确认安装路径(/opt/dmdbms)? (Y/y:是 N/n:否)  [Y/y]:y

安装前小结
安装位置: /opt/dmdbms
所需空间: 336M
可用空间: 38G
版本信息:
有效日期:
安装类型: 自定义
是否确认安装? (Y/y:是 N/n:否):y
2021-06-07 18:27:00
[INFO] 安装达梦数据库...
2021-06-07 18:27:01
[INFO] 安装基础 模块...
2021-06-07 18:27:04
[INFO] 安装驱动 模块...
2021-06-07 18:27:07
[INFO] 移动ant日志文件。
2021-06-07 18:27:07
[INFO] 创建dmdba系统管理员完成。
2021-06-07 18:27:07
[INFO] 安装达梦数据库完成。
```

### 8.10.2. 配置环境（ITOPS用户下）

```plain theme={null}
vim ~/.bash_profile
export PATH="/opt/dmdbms/bin:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/dmdbms/bin"
export DM_HOME="/opt/dmdbms"
source ~/.bash_profile
```

### 8.10.3. 安装python驱动

在刚刚安装的达梦驱动的路径下找到python模块驱动 解压dmPython.zip 联系技术中心获取对应zip包

```plain theme={null}
chown itops: -R /opt/dmdbs/
su - itops
find /opt/dmdbms/ -name dmPython
cd /opt/dmdbms/drivers/python/dmPython
python3 setup.py install

#如提示gcc问题，执行
yum install -y gcc-c++ python3-devel
```

测试驱动模块文件

```plain theme={null}
python3 -c 'import dmPython'
```

### 8.10.4. 监控模板和脚本导入

参考oracle监控改版，去除没有的监控项和方法 联系技术中心获取对应资源

pydm.py 达梦数据库模板.xml pydm

### 8.10.5. 监控用户权限

```plain theme={null}
CREATE USER ZABBIX IDENTIFIED BY zabbix123;
grant select on DBA_CONSTRAINTS to zabbix;
grant select on DBA_DATA_FILES to zabbix;
grant select on DBA_FREE_SPACE to zabbix;
grant select on DBA_INDEXES to zabbix;
grant select on DBA_OBJECTS to zabbix;
grant select on DBA_TABLESPACES to zabbix;
grant select on DBA_TRIGGERS to zabbix;
grant select on DBA_USERS to zabbix;
grant select on V$ASMGROUP to zabbix;
grant select on V$MEM_POOL to zabbix;
grant select on V$RECOVER_STATUS to zabbix;
grant select on V$RLOG to zabbix;
grant select on V$SESSIONS to zabbix;
grant select on V$SESSION_SYS to zabbix;
grant select on V$SQL_STAT to zabbix;
grant select on DBA_CONSTRAINTS to zabbix;
grant select on V$WAIT_CLASS to zabbix;
grant select on V$SYSTEMINFO to zabbix;
grant select on V$SYSSTAT to zabbix;
grant select on V$LOCK to zabbix;
grant select on V$SYSTEM_EVENT to zabbix;
grant select on V$DM_ARCH_INI to zabbix;
grant select on V$EVENT_NAME to zabbix;
grant select on V$DATAFILE to zabbix;
grant select on V$RLOGFILE to zabbix;
```

### 8.10.6. 脚本连接测试

```plain theme={null}
[root@zabbix etc]# python3 /itops/zabbix/scripts/pydm.py --username "zabbix" --password "zabbix123" --address IP --port 5237 uptime
```

### 8.10.7. 添加监控：

![8.10. 达梦数据库 操作截图 1](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/dameng-db/image-01.png)

![8.10. 达梦数据库 操作截图 2](https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/dameng-db/image-02.png)

# 异常处理

命令行测试正常，zabbix监控请求或页面测试提示报错 ImportError: libdmdpi.so: cannot open shared object file: No such file or directory 方法1： 需要重启server，令server读取到 \~/.bash\_profile环境变量 方法2： 在pydm的shell脚本中加入source \~/.bash\_profile的操作

执行脚本提示 DeprecationWarning: inspect.getargspec() is deprecated since Python 3.0, use inspect.signature() or inspect.getfullargspec()。

修改代码中的inspect.getfullargspec(method)改为inspect.getfullargspec(method) <img src="https://lwweb.oss-cn-shenzhen.aliyuncs.com/docs/images/yuque/dameng-db/image-03.png" alt="8.10. 达梦数据库 操作截图 3" />
