CentOS7.2下部署zabbix4.0

總體部署採用centos7+php+apache+mariadb

關閉防火牆

[root@monitor_53 ~]$ systemctl stop firewalld
[root@monitor_53 ~]$ systemctl disable firewalld

關閉selinux

[root@monitor_53 ~]$ setenforce 0
[root@monitor_53 ~]$ sed -i "s#enforcing#disabled#g" /etc/sysconfig/selinux

下載官方源

[root@monitor_53 ~]$ wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
[root@monitor_53 ~]$ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 
[root@monitor_53 ~]$ yum clean all
[root@monitor_53 ~]$ yum makecache
[root@monitor_53 ~]$ yum update -y

安裝擴展和依賴

[root@monitor_53 ~]$ yum install -y php-mysql php-gd php-bcmath php-common php-xml php-mbstring php-cli pcre glibc gcc livevent zlib libcurl-devel curl-devel OpenIPMI-devel libssh2 fping net-snmp-devel perl-DBI openssl-devel iksemel libxml2

安裝LNMP環境

[root@monitor_53 ~]$ yum install -y httpd php mariadb mariadb-server ntp

配置時間同步

[root@monitor_53 ~]$ ntpdate -u asia.pool.ntp.org
[root@monitor_53 ~]$ systemctl enable ntpd
[root@monitor_53 ~]$ echo '* /30 * * * * /usr/sbin/ntpdate -u asia.pool.ntp.org > /dev/null 2>&1' >>/var/spool/cron/root

配置數據庫

[root@monitor_53 ~]$ mkdir -p /home/mysql/{data,logs}
[root@monitor_53 ~]$ touch /home/mysql/logs/slow_query_log.log
[root@monitor_53 ~]$ touch /home/mysql/logs/error.log
[root@monitor_53 ~]$ chown -R mysql:mysql /home/mysql
[root@monitor_53 ~]$ cp /etc/my.cnf /etc/my.cnf.bak
[root@monitor_53 ~]$ cat /etc/my.cnf
[mysqld]
user = mysql
port = 3306
datadir    = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
pid-file = /var/run/mariadb/mariadb.pid
log-error = /home/mysql/logs/error.log
slow_query_log = on
slow_query_log_file = /home/mysql/logs/slow_query_log.log
long_query_time = 0.1
log_queries_not_using_indexes =1
long_query_time=2
character_set_server=utf8

[client]
port = 3306
socket = /var/lib/mysql/mysql.sock

[mysqldump]
quick
max_allowed_packet = 32M

初始化數據庫

[root@monitor_53 ~]$ systemctl enable mariadb
[root@monitor_53 ~]$ systemctl start mariadb
[root@monitor_53 ~]$ mysql_secure_installation #初始化,配置完成root密碼後,一路按Y便可
[root@monitor_53 ~]$ mysql_secure_installation 
Enter current password for root (enter for none): 回車
Set root password? [Y/n] 回車
New password: 123456
Re-enter new password: 123456
Remove anonymous users? [Y/n] 回車
Disallow root login remotely? [Y/n] 回車
Remove test database and access to it? [Y/n] 回車
Reload privilege tables now? [Y/n] 回車
Thanks for using MariaDB!

啓動http

[root@monitor_53 ~]$ systemctl start httpd
[root@monitor_53 ~]$ systemctl enable httpd
[root@monitor_53 ~]$ netstat -ntap | egrep '(80|3306)'

安裝Zabbix-server,Web前端,zabbix-agent

[root@monitor_53 ~]$ rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@monitor_53 ~]$ yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent

建立zabbix數據庫

[root@monitor_53 ~]$ mysql -uroot -p123456
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to 'zabbix'@'10.0.0.53' identified by 'zabbix';
mysql> flush privileges;
mysql> quit;

導入初始架構和數據

[root@monitor_53 ~]$ zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -h 10.0.0.53 -uzabbix -p zabbix

爲Zabbix-server配置數據庫

[root@monitor_53 ~]$ cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak
[root@monitor_53 ~]$ cat /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
DebugLevel=3
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=10.0.0.53
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000

爲Zabbix-server配置PHP

[root@monitor_53 ~]$ cp /etc/httpd/conf.d/zabbix.conf /etc/httpd/conf.d/zabbix.conf.bak
[root@monitor_53 ~]$ vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Europe/Riga

修改zabbix-agent配置文件

[root@monitor_53 ~]$ cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
[root@monitor_53 ~]$ cat /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
ListenPort=10050
Server=10.0.0.53
ServerActive=10.0.0.53
Hostname=10.0.0.53
Include=/etc/zabbix/zabbix_agentd.d/*.conf
HostMetadataItem=system.uname
StartAgents=1
RefreshActiveChecks=120
BufferSize=200
Timeout=10

啓動Zabbix-server和zabbix-agent進程

[root@monitor_53 ~]$ systemctl restart zabbix-server zabbix-agent httpd
[root@monitor_53 ~]$ systemctl enable zabbix-server zabbix-agent httpd

查看全部服務端口

[root@monitor_53 ~]$ netstat -tnlp | egrep '(80|3306|10050|10051)'

配置Zabbix前端

瀏覽器鏈接到新安裝的Zabbix前端: http://10.0.0.53/zabbixphp

Database type   MySQL
Database server   10.0.0.53
Database port   3306
Database name   zabbix
Database user   zabbix
Database password   zabbix
Zabbix server   10.0.0.53
Zabbix server port   10051
Zabbix server name   運維監控前端

相關文章
相關標籤/搜索