How to Install Zabbix Server, MySQL, Nginx, PHP, and Elasticsearch on CentOS
This comprehensive tutorial walks you through adding the Zabbix repository, installing Zabbix server and web interface, setting up MySQL 5.7, configuring Nginx and PHP from source, deploying the Zabbix agent, installing Elasticsearch with the head plugin, and finally storing Zabbix history data in Elasticsearch on a CentOS system.
Install Zabbix Server
Add Zabbix repository
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
yum -y install yum-utils
yum-config-manager --enable rhel-7-server-optional-rpmInstall Zabbix server and web
yum install zabbix-server-mysql
yum install zabbix-web-mysqlInstall MySQL 5.7
Remove MariaDB packages
rpm -qa | grep mariadb # check installed mariadb packages
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64 # uninstall mariadbDownload and extract MySQL source
wget https://dev.mysql.com/get/archives/mysql-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
tar -xzvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysqlCreate MySQL user and set permissions
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql.mysql mysql/Create MySQL configuration file
cat >>/etc/my.cnf <<EOF
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
EOFInitialize database
touch /var/log/mysqld.log
chmod 777 /var/log/mysqld.log
chown mysql.mysql mysqld.log
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/dataFind initial password
cat /var/log/mysqld.log | grep root@localhostStart MySQL service and set permissions
mkdir /var/run/mysqld
touch /var/run/mysqld/mysqld.pid
chmod -R 777 /var/run/mysqld
chown -R mysql.mysql /var/run/mysqld
/usr/local/mysql/support-files/mysql.server startChange MySQL root password
vim /etc/my.cnf # edit configuration
skip-grant-tables # skip password authentication
default_password_lifetime=360 # extend password lifetime /usr/local/mysql/bin/mysql -uroot -p # login
use mysql;
update mysql.user set authentication_string = password('root'), host='%' where user='root';
flush privileges;Add MySQL to PATH
echo 'PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
ln -s /usr/local/mysql/support-files/mysql.server /usr/local/mysql/bin/Create Zabbix database and user
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
mysql> flush privileges;Edit Zabbix server configuration
DBName=zabbix
DBHost=192.168.179.132
DBUser=zabbix
DBPassword=zabbix
systemctl enable zabbix-server
systemctl start zabbix-serverInstall Nginx
Disable firewall and SELinux
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disable/g' /etc/selinux/configInstall dependencies
yum -y install wget vim lsof lrzsz pcre-devel zlib-devel make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel libmcrypt libmcrypt-devel mcrypt mhash net-snmp-devel
yum -y install gcc bison bison-devel openssl-devel readline-devel libedit-devel sqlite-devel freetype freetype-devel libevent-devel mysql-develConfigure Nginx yum repository
cat >>/etc/yum.repos.d/nginx.repo <<EOF
[nginx]
name=nginx.repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
skip_if_unavailable = 1
keepcache = 0
EOFStart Nginx
nginx -t # test configuration
systemctl start nginx
systemctl enable nginxInstall PHP
Add PHP user
useradd -s /sbin/nologin php-fpmInstall PHP dependencies and compile
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
wget http://mirrors.sohu.com/php/php-7.2.6.tar.gz
tar zxvf php-7.2.6.tar.gz
cd php-7.2.6
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext
make && make install
echo $?
cp php.ini-production /usr/local/php/etc/php.iniAdjust PHP configuration
sed -i 's/post_max_size = 8M/post_max_size = 32M/g' /usr/local/php/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini
sed -i 's/;date.timezone =/date.timezone =PRC/' /usr/local/php/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 600/g' /usr/local/php/etc/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /usr/local/php/etc/php.iniStart php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.confDeploy Zabbix web files
cp -r /usr/share/zabbix/.* /usr/share/nginx/html/Configure Nginx for PHP
server {
listen 80;
server_name 192.168.179.132;
access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 404 /404.html;
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}Fix permissions for Zabbix web
chmod -R 777 /etc/zabbix/webInstall Zabbix Agent
yum install zabbix-agent
vim /etc/zabbix/zabbix-agentd.conf # set Server and ServerActive to the Zabbix server IPInstall Elasticsearch 6.1
Download and extract
yum install java
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.4.tar.gz
tar -xvf elasticsearch-6.1.4.tar.gzAdjust system limits
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096 vm.max_map_count=655360Start Elasticsearch
cd elasticsearch-6.1.4/bin
./elasticsearch # run as a non‑root userInstall head plugin
Install Node.js and Grunt
yum groupinstall "Development Tools"
wget https://nodejs.org/dist/v8.11.4/node-v8.11.4.tar.gz
tar -zxvf node-v8.11.4.tar.gz
cd node-v8.11.4
./configure && make && make install
echo $?
npm install -g grunt-cliClone and build head
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head/
npm install
npm install [email protected] --ignore-scriptsEnable CORS in Elasticsearch
vim /root/elasticsearch-6.1.4/config/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"Run head plugin
npm run start # then open http://192.168.179.133:9100/Store Zabbix history in Elasticsearch
Configure Zabbix server
HistoryStorageURL=192.168.179.133:9200
HistoryStorageTypes=str,text,log,uint,dbl
HistoryStorageDateIndex=1Configure Zabbix web PHP file
global $DB, $HISTORY;
$HISTORY['url'] = 'http://192.168.179.133:9200';
$HISTORY['types'] = ['str','text','log','uint','dbl'];Restart services
systemctl restart zabbix-serverAll steps above complete the installation and integration of Zabbix monitoring with MySQL, Nginx, PHP, and Elasticsearch on a CentOS host.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
