zabbix可以监控服务器的各种参数,确保服务器正常运行,同时提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
本次安装环境为centos7.6,安装zabbix需要先配置LNMP环境。
更多安装说明请到官网:https://www.zabbix.com/download
安装Zabbix源
rpm -Uvh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-1.el7.noarch.rpm yum clean all
yum安装zabbix、php和nginx
yum -y install zabbix-server-mysql zabbix-web-mysql nginx
编译安装mysql
groupadd mysql useradd -s /sbin/nologin -g mysql mysql yum install -y gcc gcc-c++ bison-devel ncurses-devel perl cmake pcre pcre-devel mkdir -p /usr/local/mysqlcd /usr/src && wget https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.5/mysql-5.5.60.tar.gz tar -zxvf mysql-5.5.60.tar.gz cd mysql-5.5.60 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 make && make install chown -R mysql:mysql /usr/local/mysql ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql ln -s /usr/local/mysql/bin/mysqlcheck /usr/bin/mysqlcheck ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql cd /usr/local/mysql && ./script/mysql_installdb /etc/init.d/mysql start
设置mysql的root账户密码
mysqladmin -uroot password New password:新密码
创建zabbix数据库和帐号
mysql -uroot -p password: mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '新密码'; mysql> quit;
导入sql文件
cd /usr/share/doc/zabbix-server-mysql* gunzip create.sql.gz mysql -uroot -p zabbix <create.sql Enter password:
搭建web界面,并配置nginx
cp -r /usr/share/zabbix /var/www/html/ chown -R nginx:nginx /var/www/html/zabbix chown -R nginx:nginx /etc/zabbix/web
编辑zabbix-server配置文件
vi /etc/zabbix/zabbix_server.conf LogFile=/var/log/zabbix/zabbix_server.log ListenPort=自定义监听端口 DBHost=localhost DBName=zabbix DBPassword=数据库密码 DBSocket=/tmp/mysql.sock DBPort=3306
编辑zabbix.conf.php
vi /etc/zabbix/web/zabbix.conf.php <?php // Zabbix GUI configuration file. global $DB; $DB['TYPE'] = 'MYSQL'; $DB['SERVER'] = 'localhost'; $DB['PORT'] = '3306'; $DB['DATABASE'] = '数据库名称'; $DB['USER'] = '数据库用户'; $DB['PASSWORD'] = '数据库密码'; // Schema name. Used for IBM DB2 and PostgreSQL. $DB['SCHEMA'] = ''; $ZBX_SERVER = 'localhost'; $ZBX_SERVER_PORT = '监听端口'; $ZBX_SERVER_NAME = '服务器名称'; $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
启动zabbix-server和nginx
systemctl start zabbix-server systemctl start nginx