การ Access Mysql / Mariadb Server ด้วย Zabbix agent

ในขณะที่เปิด SELinux (CentOS) ทำให้ใช้งาน Zabbix Server ในขณะที่เปิด Selinux ได้ แต่ยังติดปัญหาเรื่อง Agent

ไม่สามารถ Access (Local Access)ไปยัง mysql/mariadb Server ได้  จึงต้องทำการ add policy selinux

เนื่องจากผมได้ศึกษาบทความของพี่ Krit
https://www.zabbixinthailand.com/2020/01/08/how-to-add-policy-selinux/
ทำให้ใช้งาน Zabbix Server ในขณะที่เปิด SELinux ได้ แต่ยังติดปัญหาเรื่อง Agent ไม่สามารถ Access (Local Access)ไปยัง mysql/mariadb Server ได้  จึงต้องทำการ add policy selinux ดังนี้

1.Create file ชื่อ zabbix_mysql.te

module zabbix_mysql 1.0;
require {
        type unconfined_t;
        type mysqld_var_run_t;
        type mysqld_etc_t;
        type mysqld_t;
        type zabbix_var_lib_t;
        type zabbix_agent_t;
        class sock_file write;
        class unix_stream_socket connectto;
        class file { read relabelto open };
        class dir relabelto;
}

#============= unconfined_t ==============
allow unconfined_t zabbix_agent_t:dir relabelto;
allow unconfined_t zabbix_agent_t:file relabelto;

#============= zabbix_agent_t ==============
allow zabbix_agent_t mysqld_etc_t:file { read open };
#!!!! This avc can be allowed using the boolean ‘daemons_enable_cluster_mode’
allow zabbix_agent_t mysqld_t:unix_stream_socket connectto;
allow zabbix_agent_t mysqld_var_run_t:sock_file write;
allow zabbix_agent_t zabbix_var_lib_t:file { read open };

2.Run Command ตามนี้

checkmodule -M -m -o zabbix_mysql.mod zabbix_mysql.te

semodule_package -o zabbix_mysql.pp -m zabbix_mysql.mod

semodule -i zabbix_mysql.pp

3.Restart zabbix_agent  ก็สามารถ Access mysql/mariadb ที่เครื่องตัวเองได้แล้วครับ ถ้า Add Template DB MySQL เอาไว้ก่อนแล้ว ก็จะเห็นว่าสมารถดูข้อมูลได้แล้วครับ