centos 7 compile install deploy zabbix-server side

Posted by fatal on Thu, 06 Jun 2019 18:12:44 +0200

Compile and install the zabbix-server side of the deployment in the CentOs 7.0 environment

  • First you need to close selinux
[root@bogon ~]# sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config 
[root@bogon ~]# setenforce 0
  • Close Firewall
[root@bogon ~]# systemctl stop firewalld.service

About zabbix and related service software versions

Linux: centos 7 
nginx: 1.9.15 
MySQL: 5.5.49 
PHP: 5.5.35

1. Install nginx:

Install dependent packages:

yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel

Create user:

/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www
useradd nginx -s /sbin/nologin -M

Download the nginx package and enter the directory:

wget http://nginx.org/download/nginx-1.9.15.tar.gz && tar xvf nginx-1.9.15.tar.gz && cd nginx-1.9.15

Compile:

./configure --prefix=/usr/local/product/nginx1.9.14 --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre

make && make install
ln -s /usr/local/product/nginx1.9.14 /usr/local/nginx    ==>Create soft links

Explanation of parameters:

- with-http_stub_status_module: supports nginx status queries
- with-http_ssl_module: supports https
- with-http_spdy_module: spdy for google, to know Baidu spdy, this must have ssl support
- with-pcre: PCRE must be developed to support rewrite rewrite rewrite

2. Install PHP

Download PHP installation package

wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror

Unzip and compile:

mv mirror php-5.5.35.tar.gz && tar xvf php-5.5.35.tar.gz && cd php-5.5.35

./configure --prefix=/usr/local/product/php-5.5.35 --with-config-file-path=/usr/local/product/php-5.5.35/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath

make && make install
ln -s /usr/local/product/php-5.5.35 /usr/local/php

cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc/

cp php-fpm.conf.default php-fpm.conf

Modify php.ini parameters: (parameters that need to be modified for the zabbix environment)

max_execution_time = 300 
memory_limit = 128M 
post_max_size = 16M 
upload_max_filesize = 2M 
max_input_time = 300 
date.timezone = PRC

3. Install MySQL

Add the MySQL user and create a data directory for mysql:

groupadd mysql
mkdir -pv /data/mysql
useradd -r -g mysql -d /data/mysql -s /sbin/nologin mysql
chown -R mysql.mysql /data/mysql

Install cmake and dependencies:

yum install cmake gcc* ncurses-devel -y

Download MySQL installation package

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz

Compile and install MySQL

tar -xvf mysql-5.5.49.tar.gz && cd mysql-5.5.49

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/product/mysql5.5.49 -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci

make && make install
ln -s /usr/local/product/mysql5.5.49 /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql

Copy the configuration file for mysql:

cd /usr/local/mysql/support-files/

cp my-medium.cnf /data/mysql/my.cnf

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

chmod +x /etc/init.d/mysqld

Initialize MySQL

cd /usr/local/mysql/scripts
./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/

Modify the data directory in my.cnf MySQL configuration file

vim /data/mysql/my.cnf
datadir=/data/mysql/   ===>Newly added

Rm-rf/etc/my.cnf may need to be removed from the virtual machine (if necessary)

Start MYSQL

 /etc/init.d/mysqld start
Starting MySQL... SUCCESS!

Configuring environment variables
vim /etc/profile
PATH=${PATH}:/usr/local/mysql/bin=== New

Log in to the database and create the zabbix database with the user name and password:

mysql> create database zabbix default charset utf8;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| zabbix             |
+--------------------+
5 rows in set (0.00 sec)

If you have problems logging into the database:

[root@zabbix ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)


//Solution:

[root@zabbix ~]# ln -s /tmp/mysql.sock /var/lib/mysql/

Create a password for the root of the database:

mysqladmin -uroot password  "zabbix"

IV. Install zabbix server

wget http://pkgs.fedoraproject.org/repo/pkgs/zabbix/zabbix-3.0.3.tar.gz/7c45d37000e67d75042695344c9937e0/zabbix-3.0.3.tar.gz
tar zxf zabbix-3.0.3.tar.gz && cd zabbix-3.0.3

//Compile zabbix:

./configure --prefix=/usr/local/zabbix-3.0.3/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

make && make install

If there are errors during compilation:

Failure:
checking for mysql_config... no
configure: error: MySQL library not found

//Solve:
yum install mysql-devel -y

//Failure:
checking for net-snmp-config... no
configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

//Solve:
yum install net-snmp-devel -y

Create zabbix user

groupadd zabbix
useradd -s /sbin/nologin -M -g zabbix

zabbix server needs to import three sql files:

 mysql -uroot -pzabbix zabbix < database/mysql/schema.sql 
 mysql -uroot -pzabbix zabbix < database/mysql/images.sql 
 mysql -uroot -pzabbix zabbix < database/mysql/data.sql 

 pwd
 /root/zabbix-3.0.3

5. zabbix Administration Site Configuration (nginx):

mkdir /data/web/zabbix.localhost.com -p

mkdir /data/logs/zabbix -p

Copy the front-end file to the project directory:

cp -rp frontends/php/* /data/web/zabbix.localhost.com/

Edit nginx virtual host:

 mkdir extra
 cd extra/
 vim zabbix.conf

server {
listen 8027;
server_name zabbix.localhost.com;
access_log /data/logs/zabbix/zabbix.localhost.com.access.log main;
index index.html index.php index.html;
root /data/web/zabbix.localhost.com;

location /{
       try_files $uri $uri/ /index.php?$args;
}

location ~ ^(.+.php)(.*)$ {
       fastcgi_split_path_info ^(.+.php)(.*)$;
       include fastcgi.conf;
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_param PATH_INFO $fastcgi_path_info;
}

}

Edit the nginx.conf configuration file:

vim nginx.conf

user  nginx;
worker_processes  1;

#error_log  logs/error.log warning;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    include extra/*.conf;

}

Edit the zabbix_server.conf file:

pwd
/usr/local/zabbix-3.0.3/etc
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
BHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

6. Start Services

Start nginx:

/usr/local/nginx/sbin/nginx

Start PHP

/usr/local/php/sbin/php-fpm

Start zabbix server:

/usr/local/zabbix-3.0.3/sbin/zabbix_server
If an error occurs at startup:
/usr/local/zabbix-3.0.3/sbin/zabbix_server

/usr/local/zabbix-3.0.3/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/

Add/etc/hosts file

IP address zabbix.localhost.com

View service ports:

netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1029/sshd           
tcp        0      0 0.0.0.0:8027                0.0.0.0:*                   LISTEN      3730/nginx          
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      3743/zabbix_server  
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      3736/php-fpm        
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      24922/mysqld        
tcp        0      0 :::22                       :::*                        LISTEN      1029/sshd           
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               880/dhclient

If you query the port information and find that there is no 10051, the zabbix-server port, querying the zabbxi log found an error.

tail -fn20 /tmp/zabbix_server.log 
 80529:20170809:113913.699 using configuration file: /usr/local/zabbix-3.0.3/etc/zabbix_server.conf

 80529:20170809:113913.701 [Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
80570:20170809:113958.028 Cannot connect to the database. Exiting...

//Solution:

ln -s  /tmp/mysql.sock /var/lib/mysql/mysql.sock

Add services to boot-up self-start:

echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local 
echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local 
echo "/etc/init.d/mysqld start" >>/etc/rc.local
echo "/usr/local/zabbix-3.0.3/sbin/zabbix_server" >>/etc/rc.local

7. web-side configuration of zabbix

Files need to be downloaded and uploaded to the specified server directory.
Modify property chown-R UID.GID zabbix.conf.php

Modify the interface to Chinese

The default login interface is English

To prevent Chinese scrambling, upload local user fonts to the zabbix-server side

Upload fonts to the appropriate directory

mv SIMSUN.TTC /data/web/zabbix.localhost.com/fonts/
cd /data/web/zabbix.lifec.com/fonts/

ls
DejaVuSans.ttf  SIMSUN.TTC

mv SIMSUN.TTC DejaVuSans.ttf 
chown UID.GID DejaVuSans.ttf 

Topics: MySQL Zabbix PHP Nginx