公司監控體系之---Zabbix

一個公司的運維基礎,監控體系是必不可少的,常用的有很多,如:nagios\\catai\\zabbix等,今天我來分享一個zabbix 建立的過程:


一.安裝mysql

1.建立Mysql賬號

groupadd mysql

useradd -s /sbin/nologin -g mysql -M mysql

2.創建mysql軟件目錄並修改權限


mkdir -p /usr/local/mysql


mkdir -p /data/mysql


chown -R root:mysql /usr/local/mysql


chown -R mysql:mysql /data/mysql


3.安裝依賴包


yum -y install make gcc-c++ cmake bison-devel ncurses-devel


4.下載源碼包並解壓


http://mirrors.sohu.com/mysql/


cd /usr/local/src


tar -zxf mysql-5.7.11.tar.gz


cd mysql-5.7.11


5.編譯


cmake \\

> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \\

> -DMYSQL_DATADIR=/data/mysql \\


> -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \\

> -DDEFAULT_CHARSET=utf8 \\

> -DDEFAULT_COLLATION=utf8_general_ci \\

> -DEXTRA_CHARSETS=all \\

> -DENABLED_LOCAL_INFILE=1 \\

> -DDOWNLOAD_BOOST=1 \\

> -DWITH_BOOST=/usr/local/boost


6.安裝

make && make install


7. 初始化MySQL


cd /usr/local/mysql/bin

./mysqld --initialize --user=mysql --datadir=/mysql/data --basedir=/usr/local/mysql --socket=/var/lib/mysql/mysql.sock


8. 添加MySQL服務並設置開機啟動


cd /usr/local/mysql/support-files

cp mysql.server /etc/init.d/mysqld

cd /etc/init.d/


chkconfig --add mysqld


chkconfig --level 2345 mysqld on


vi /etc/my.cnf


[mysqld]


port = 3306


socket = /var/lib/mysql/mysql.sock


user = mysql


basedir = /usr/local/mysql


datadir = /data/mysql


log-error = /var/log/mysql/mysqld.log


skip-external-locking


key_buffer_size = 16M


max_allowed_packet = 1M


table_open_cache = 64


sort_buffer_size = 512K


net_buffer_length = 8K


read_buffer_size = 256K


read_rnd_buffer_size = 512K


myisam_sort_buffer_size = 8M


thread_cache_size = 8


query_cache_size = 8M


tmp_table_size = 16M


#skip-networking


max_connections = 500


max_connect_errors = 100


open_files_limit = 65535


log-bin=mysql-bin


binlog_format = mixed


server-id = 1


expire_logs_days = 10


[mysqldump]


quick


max_allowed_packet = 16M


[mysql]


no-auto-rehash


[myisamchk]


key_buffer_size = 20M


sort_buffer_size = 20M


read_buffer = 2M


write_buffer = 2M


[mysqlhotcopy]


interactive-timeout


10. 重啟MySQL

/etc/init.d/mysql start

Starting MySQL.. SUCCESS!


11. 登錄MySQL

cd ../bin/

./mysql -uroot -p //第一次登錄MySQL,密碼文件在,也可以從make install 最後的一行看到密碼,若看不到可以參考以下修改密碼的步驟

Enter password:


12.忘記root密碼可通過以下方法修改


vi /etc/my.cnf


[mysqld]


skip-grant-tables


重啟mysqld服務,重新登陸已不需要密碼


13.修改root密碼


use mysql


update user set authentication_string=PASSWORD(‘zabbix‘) where User=‘root‘;


14.退出刪除mysql.cnf中的skip-grant-tables,以新密碼重新登陸即可


15.首次登陸需要重新設置一下新密碼,否則任何命令都會提示:


ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


set password for root@localhost = password(‘zabbix‘);


16.創建zabbix數據庫


create database zabbix character set utf8 collate utf8_bin;


grant all privileges on zabbix.* to zabbix@localhost identified by ‘zabbix‘;


二.安裝Zabbix


1.安裝官方的yum源


rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm


2.yum安裝zabbix-server\\zabbix-web\\zabbix-agent


yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent


3.初始化數據庫


cd /usr/share/doc/zabbix-server-mysql-3.0.*


zcat create.sql.gz | mysql -uroot -pzabbix zabbix


4.編輯zabbix server配置文件


vi /etc/zabbix/zabbix_server.conf


DBHost=localhost


DBName=zabbix


DBUser=zabbix


DBPassword=zabbix


5.開啟zabbix server以及agent服務並設置開機啟動


systemctl start zabbix-server


systemctl enable zabbix-server


systemctl start zabbix-agent


systemctl enable zabbix-agent


6.確保php的配置符合zabbix的要求(默認已含下列配置),並修改timezone為PRC


vi /etc/httpd/conf.d/zabbix.conf


php_value max_execution_time 300


php_value memory_limit 128M


php_value post_max_size 16M


php_value upload_max_filesize 2M


php_value max_input_time 300


php_value always_populate_raw_post_data -1


php_value date.timezone Asia/Shanghai


7.開啟Apache服務並設置開機啟動


systemctl start httpd

systemctl enable httpd


8.打開zabbix頁面http://10.10.10.110/zabbix/,首次要求初始化,一路next配置下去就行

注意:確保mysql.sock協議文件在/var/lib/mysql/下,如果不在可通過my.cnf修改


9.修改語言

Zabbix 3.0.3可以直接在界面上修改為簡體中文


三.Agent安裝(客戶端,內網IP需要修改成外網IP)

groupadd zabbix

useradd zabbix -g zabbix -s /sbin/nologin

cd /usr/local/src/

wget http://ufpr.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz

tar -xzvf zabbix-3.0.3.tar.gz

cd zabbix-3.0.3

./configure --prefix=/usr/local/zabbix/ --enable-agent

make

make install

sed -i ‘s/^Server=.*/Server=10.10.10.110/g‘ /usr/local/zabbix/etc/zabbix_agentd.conf

sed -i ‘s/^ServerActive=.*/ServerActive=10.10.10.110/g‘ /usr/local/zabbix/etc/zabbix_agentd.conf

sed -i ‘s/^Hostname=.*/Hostname=TestHost/g‘ /usr/local/zabbix/etc/abbix_agentd.conf


啟動agent服務


/usr/local/zabbix/sbin/zabbix_agentd start


設置開機啟動


vi /etc/rc.d/rc.local


添加以下內容


/usr/local/zabbix/sbin/zabbix_agentd start


四.附加配置


1.開放系統防火牆端口


firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.17.0/24" port protocol="tcp" port="80" accept"


firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.17.0/24" port protocol="tcp" port="10050" accept"


firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="192.168.17.0/24" port protocol="tcp" port="10051" accept"


firewall-cmd --reload



分享到:


相關文章: