Zabbix Server和MPM(monitor for mysql)的快速部署,zabbixmpm

來源:互聯網
上載者:User

Zabbix Server和MPM(monitor for mysql)的快速部署,zabbixmpm
1. 前言        zabbix作為開源免費的監視軟體,其易於管理配置和可視化的視圖、曆史資料的定期維護、模板化的監控項目越來越受到廣大IT營運人員的喜愛。這裡主要是總結了下Zabbix Server和MPM使用yum進行快速部署。其更加詳細的東西,大家還是看官方文檔吧。我們首先把環境搭起來!2. 環境1)Zabbix Server
Os:Redhat6.5 i686(vmware)        ipaddr:192.168.8.3        hostname:linux-zabbix        MySQL :5.6.23        MEM:1G
2)監控端
        Os:CentOS 6.4 x64(vmware)        ipaddr:192.168.8.5        hostname:oneproxy-vm        MEM:1G
3. Zabbix Server部署3.1 yum環境配置這裡的yum源使用的是163的CentOS6.6和zabbix官網的源。由於我的server安裝的是rehat,所以首先要把redhat的yum卸載掉,安裝centOS的yun軟體。3.1.1 下載centos yum軟體

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpmwget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpmwget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-40.el6.centos.noarch.rpmwget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm

3.1.2 卸載redhat的yum包
rpm -qa|grep -i yum|xargs rpm -e --nodeps

3.1.3 安裝centOS的yum包
rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpmrpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpmrpm -ivh yum-3.2.29-40.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm

3.1.4 配置163的CentOS6.6的yum
[root@linux-zabbix yum.repos.d]# cd /etc/yum.repos.d[root@linux-zabbix yum.repos.d]# cat CentOS6-Base-163.repo # CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client.  You should use this for CentOS updates# unless you are manually picking other mirrors.## If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead.##[base]name=CentOS-6.6 - Base - 163.combaseurl=http://mirrors.163.com/centos/6.6/os/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6.6&arch=$basearch&repo=osgpgcheck=1gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6#released updates [updates]name=CentOS-6.6 - Updates - 163.combaseurl=http://mirrors.163.com/centos/6.6/updates/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6.6&arch=$basearch&repo=updatesgpgcheck=1gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6#additional packages that may be useful[extras]name=CentOS-6.6 - Extras - 163.combaseurl=http://mirrors.163.com/centos/6.6/extras/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6.6&arch=$basearch&repo=extrasgpgcheck=1gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6#additional packages that extend functionality of existing packages[centosplus]name=CentOS-6.6 - Plus - 163.combaseurl=http://mirrors.163.com/centos/6.6/centosplus/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6.6&arch=$basearch&repo=centosplusgpgcheck=1enabled=0gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6#contrib - packages by Centos Users[contrib]name=CentOS-6.6 - Contrib - 163.combaseurl=http://mirrors.163.com/centos/6.6/contrib/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6.6&arch=$basearch&repo=contribgpgcheck=1enabled=0gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

3.1.5 配置zabbix的yum源
wget http://repo.zabbix.com/zabbix/2.4/rhel/6/i386/zabbix-release-2.4-1.el6.noarch.rpmrpm -ivh zabbix-release-2.4-1.el6.noarch.rpm
[root@linux-zabbix yum.repos.d]# cat zabbix.repo [zabbix]name=Zabbix Official Repository - $basearchbaseurl=http://repo.zabbix.com/zabbix/2.4/rhel/6/$basearch/enabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX[zabbix-non-supported]name=Zabbix Official Repository non-supported - $basearch baseurl=http://repo.zabbix.com/non-supported/rhel/6/$basearch/enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIXgpgcheck=1

3.2 Zabbix Server安裝3.2.1 安裝mysql資料庫
yum remove mysql-libs-5.1.71-1.el6.i686rpm -ivh MySQL-server-advanced-5.6.23-1.el6.i686.rpmrpm -ivh MySQL-client-advanced-5.6.23-1.el6.i686.rpmrpm -ivh MySQL-shared-compat-advanced-5.6.23-1.el6.i686.rpm MySQL-shared-advanced-5.6.23-1.el6.i686.rpm MySQL-devel-advanced-5.6.23-1.el6.i686.rpm

3.2.2 配置mysql設定檔/etc/my.cnf
[root@linux-zabbix etc]# cat my.cnf[client]port = 3306socket = /tmp/mysql.sock#The MySQL Server#########Basic######[mysqld]server-id = 1port = 3306user = mysqlbasedir = /usr/ datadir = /var/lib/mysqltmpdir = /var/lib/mysql/tmpsocket = /tmp/mysql.sockskip-external-lockingskip-name-resolvedefault-storage-engine = INNODBcharacter-set-server = utf8wait_timeout = 100connect_timeout = 20interactive_timeout = 100back_log = 500event_scheduler = onexplicit_defaults_for_timestamp#skip-grant-tables #############binlog##############log-bin = /var/lib/mysql/logs/mysql-binbinlog_format = rowmax_binlog_size = 128Mbinlog_cache_size = 4Mexpire_logs_days = 5 ##############Slow log####################slow_query_log = 1slow_query_log_file = /var/lib/mysql/logs/mysql.slowlong_query_time = 2###############Per_Thread_Buffers########################max_connections = 1024max_user_connections = 1000max_connect_errors = 10000key_buffer_size = 32Mmax_allowed_packet = 128Mtable_open_cache = 3096table_definition_cache = 4096sort_buffer_size = 512Kread_buffer_size = 512Kread_rnd_buffer_size = 512Kjoin_buffer_size = 512Ktmp_table_size = 16Mmax_heap_table_size = 16Mquery_cache_type = 0query_cache_size = 0bulk_insert_buffer_size = 16Mthread_cache_size = 64thread_stack = 256K################InnoDB#########################innodb_data_home_dir = /var/lib/mysqlinnodb_autoinc_lock_mode = 2innodb_log_group_home_dir = /var/lib/mysql/logsinnodb_data_file_path = ibdata1:1G:autoextendinnodb_buffer_pool_size = 256Minnodb_buffer_pool_instances = 1innodb_log_file_size = 64Minnodb_log_buffer_size = 4Minnodb_flush_log_at_trx_commit = 2innodb_lock_wait_timeout = 10innodb_sync_spin_loops = 40innodb_max_dirty_pages_pct = 90innodb_support_xa = 1innodb_thread_concurrency = 0innodb_thread_sleep_delay = 500innodb_file_io_threads = 4innodb_concurrency_tickets = 1000log_bin_trust_function_creators = 1innodb_flush_method = O_DIRECTinnodb_file_per_tableinnodb_read_io_threads = 4innodb_write_io_threads = 4innodb_io_capacity = 2000innodb_file_format = Barracudainnodb_purge_threads = 1innodb_purge_batch_size = 32innodb_old_blocks_pct = 75innodb_change_buffering = alltransaction_isolation = READ-COMMITTED
[mysqldump]quickmax_allowed_packet = 64M[mysql]no-auto-rehash[myisamchk]key_buffer_size = 32Msort_buffer_size = 256Kread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout[mysqld_safe]open-files-limit=28192[mysql]host=localhostuser=zabbixpassword=zabbixsocket=/tmp/mysql.sock[mysqladmin]host=localhostuser=zabbixpassword=zabbixsocket=/tmp/mysql.sock
建立目錄
mkdir -p /var/lib/mysql/tmpmkdir -p /var/lib/mysql/logschown -R mysql:mysql /var/lib/mysql
初始化mysql
mysql_install_db --defaults-file=/etc/my.cnf --datadir=/var/lib/mysql/
啟動資料庫後,建立zabbix資料庫,設定root密碼
service mysql startmysql> create database zabbix default charset utf8;
mysql> grant all on *.* to 'root'@'localhost' identified by '123456';
mysql> grant all on *.* to 'root'@'%' identified by '123456';

mysql> flush privileges;
3.2.3 安裝zabbix
yum install zabbix-server-mysql zabbix-web-mysqlyum install zabbix-get
yum會自動的將apache和php安裝配置好。
3.2.4 初始化zabbix資料庫
cd /usr/share/doc/zabbix-server-mysql-2.4.5/create
[root@linux-zabbix create]# mysql -p123456 -uroot zabbix < schema.sql[root@linux-zabbix create]# mysql -p123456 -uroot zabbix < images.sql [root@linux-zabbix create]# mysql -p123456 -uroot zabbix < data.sql 
3.2.5 修改zabbix server設定檔
cat /etc/zabbix/zabbix_server.confDBHost=localhostDBName=zabbixDBUser=rootDBPassword=123456
3.2.6 修改php設定檔
php_value max_execution_time 300php_value memory_limit 128Mphp_value post_max_size 16Mphp_value upload_max_filesize 2Mphp_value max_input_time 300date.timezone = PRC
3.2.7 啟動服務
service zabbix-server startservivce httpd start

3.2.8 配置頁面開啟 http://192.168.8.3/zabbix 後,配置相關選項安裝要求檢查


資料庫配置

zabbix-server

安裝預覽

完成後,可以使用預設管理使用者admin/zabbix進行登入

4. 配置Zabbix Agent和MPM4.1 zabbix agent配置yum的配置上一部分已經說了,直接安裝
yum install zabbix-agentyum install zabbix-sender
配置/etc/zabbix/zabbix_agentd.conf
Server=192.168.8.3ServerActive=192.168.8.3Hostname=oneproxy-vm

4.2 MPM安裝配置4.2.1 安裝依賴包
yum install perl-File-Which perl-libwww-perl perl-Digest-SHA perl-DBD-MySQL perl-Time-HiRes perl-Crypt-SSLeay

4.2.2 軟體介紹        到官網http://www.fromdual.com/ 下載MPM的相關版本,這裡我使用的是mysql_performance_monitor-0.9.3.tar.gz。(PS:最新的0.10版本沒有相關文檔,簡直坑啊!)解壓縮軟體包後,會發現有兩個檔案mysql_performance_monitor_agent-0.9.3.tar.gz和mysql_performance_monitor_templates-0.9.3.tar.gz。其中mysql_performance_monitor_agent-0.9.3.tar.gz是放在監控機器上的配置資訊,mysql_performance_monitor_templates-0.9.3.tar.gz則是要讓我們匯入到zabbix server的模板資料。
4.2.3 模板匯入登入到我們的zabbix server伺服器上,通過Configuration-->Templates-->Import進行模板匯入
將mysql_performance_monitor_templates-0.9.3.tar.gz解壓縮後Template_FromDual.MySQL.mpm.xml是必須匯入的,我們優先匯入。其他的大家根據需求進行匯入。我這裡是將所有模板匯入了。
4.2.4 建立監控host通過Configuration-->Host groups建立一個使用者組。我這裡建立名稱為mpm的使用者組。

通過Configuration-->Hosts建立一個使用者,將其加入到mpm使用者組中,關聯的Template使用我們匯入的。


關聯Template


ok,我們的server端就配置完畢了。
4.2.5 MPM agent配置解壓縮我們的agent軟體包mysql_performance_monitor_agent-0.9.3.tar.gz,將其放到/opt目錄下
mv mysql_performance_monitor_agent-0.9.3 /opt/mysql_performance_monitor_agent
cd /opt/mysql_performance_monitor_agent/etccp FromDualMySQLagent.conf.template /etc/zabbix/FromDualMySQLagent.confmkdir -p /var/log/zabbix /var/log/zabbix/cachechown -R zabbix: /var/log/zabbix /var/log/zabbix/cache

編輯/etc/zabbix/zabbix-agent.conf,添加
UserParameter=FromDual.MySQL.check,/opt/mysql_performance_monitor_agent/FromDualMySQLagent.pl /etc/zabbix/FromDualMySQLagent.conf

修改MPM設定檔
[root@oneproxy-vm zabbix]# cat /etc/zabbix/FromDualMySQLagent.conf[default]# Type of section:# mysqld for a normal MySQL database# ndbd   for a MySQL clusterType         = mysqld# Debug levels are:# 1 is logging only errors# 2 is logging errors and warnings (this is the default)# 3 logs some informations messages as well# 4 logs everything (for debugging purposes only)Debug         = 2LogFile       = /var/log/zabbix/FromDualMySQLagent.log# Directory where the Cache files should be written to:CacheFileBase = /var/log/zabbix/cache/FromDualAgentCache# If you agent is not located in the same time zone as your server# For US something like -6.0 to our MaaS Server# For Asia something like +7.0 to our MaaS Server# TimeShift = +0.0# Information for MySQL connections:Username     = rootPassword     = 123456MysqlHost    = 127.0.0.1MysqlPort    = 3306# Zabbix Server IP addressZabbixServer = 192.168.8.3
</pre><pre name="code" class="html"># If section is disabledDisabled     = false# Possible modules for databases are:# process mysql myisam aria innodb pbxt ndb master slave drbd galera memcache# Possible modules for servers are:# mpm server# Usual modules areModules      = process mysql myisam innodb[oneproxy-vm]          # This MUST match Hostname in Zabbix!Type         = mysqldUsername     = rootPassword     = 123456MysqlHost    = 127.0.0.1MysqlPort    = 3306Modules      = process mysql myisam innodbPidFile      = /data/mysql_3306/mysql.pid

其中default欄位是預設的,oneproxy-vm欄位必須與zabbix-server中配置的hosts名稱相等。其他的根據自己的本地mysql環境進行配置。給予zabbix對pid檔案的讀許可權和MPM日誌的許可權
chmod o+r /data/mysql_3306/mysql.pid
touch /var/log/zabbix/FromDualMySQLagent.log
chown -R zabbix:zabbix /var/log/zabbix
啟動zabbix-agent即可
service zabbix-agent start


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.