zabbix monitoring Grafana building

zabbix monitoring Grafana building

zabbix grafana construction steps

1. Install nignx

nginx: http://nginx.org/    ##nginx official website
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.16.1.tar.gz    ##Download nginx source package
yum install -y gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel ##Dependent environment
tar -zaf nginx-1.16.1.tar.gz 
cd nginx-1.16.1
./configure --prefix=/usr/local/nginx ##(the advantage of installing to this directory is that the configuration file log files are all in it.)
make && make install ##Start compilation and installation 

1.1 add nginx environment variable to start and verify nginx service

vim /etc/profile 
export PATH=$PATH:/usr/local/nginx/sbin  ##Add to environment variable profile  
source /etc/profile
nginx -t  ##Test whether the configuration file is normal
nginx  ##start nginx
nginx -s stop
ps auxfww | grep nginx  View process
netstat -tulnp | grep nginx View listening port
tail -f /usr/local/nginx/logs/access.log  view log

1.2 create systemctl file

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
[Install]
WantedBy=mulit-user.target

1.3 modify nginx.conf

The default configuration of nginix is unable to process php, so you need to modify the configuration file (vim /usr/local/nginx/conf/nginx.conf)

Before modification        location / {
            root   html;
            index  index.html index.htm;

//location after modification / {
            root   html;
            index  index.html index.htm index.php; (Add pair php Support)


//Remove comments        #location ~ \.php$ {
      
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script
_name;
            include        fastcgi_params;
        }


1.4 check configuration file

[root@localhost ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

2. install php

yum -y install epel-release ##epel source with more software
yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel   ##Dependent environment
cd /usr/local/src/
wget http://www.php.net/distributions/php-7.4.1.tar.gz
tar  -zxf php-5.6.40.tar.gz 
cd php-5.6.40
 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
make && make install ##Compilation and installation 
cp php.ini-production /usr/local/php/php.ini ##Copy an initial file

2.1 add php environment variable check configuration file

vim /etc/profile
export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin   ##Add to environment variable
php-fpm -t start-up
cp /usr/local/php/etc  php-fpm.conf.default php-fpm.conf  ##Copy profile
cat php-fpm.conf ##To view the profile, listen on the 9000 port:
; Note: This value is mandatory.
listen = 127.0.0.1:9000

2.2 create systemctl file

vim /usr/lib/systemd/system/php-fpm.service  ##Create start service start

[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
[Install]
WantedBy=mulit-user.target

//Check whether the service is normal 
[root@localhost ~]# netstat -tulnp | grep php
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      1309/php-fpm: maste 

[root@localhost ~]# ps auxf | grep php-fpm
root      1324  0.0  0.0 112712   964 pts/0    S+   03:22   0:00          \_ grep --color=auto php-fpm
root      1309  0.0  0.4 218888  4992 ?        Ss   03:21   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody    1310  0.0  0.4 218888  4532 ?        S    03:21   0:00  \_ php-fpm: pool www
nobody    1311  0.0  0.4 218888  4532 ?        S    03:21   0:00  \_ php-fpm: pool www
[root@localhost ~]#

3. Install mysql

/usr/local/src Installation package storage path 
yum install -y gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DWITH_SSL=yes -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1
useradd -s /sbin/nologin mysql #Add mysql user

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
export PATH=$PATH:/usr/local/mysql/bin/ ##Add environment variable

3.1mqsql configuration file

vim /etc/my.cnf ##Update configuration
[mysqld]
bind-address=0.0.0.0
port=3306
datadir=/data/mysql
user=mysql
skip-name-resolve
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow.log
expire_logs_days=2
innodb-file-per-table=1
innodb_flush_log_at_trx_commit = 2
log_warnings = 1
max_allowed_packet = 512M
connect_timeout = 60
net_read_timeout = 120
[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid

3.2 initialize mysql

mkdir  -pv /data/mysql
chown  -R mysql:mysql /usr/local/mysql/ /data/mysql/
yum install -y perl-Module-Install
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql/

3.3 create systemctl file

vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start 
[Install]
WantedBy=mulit-user.target```

## 3.4 mysql security configuration
mysql -uroot -h 127.0.0.1 -A
mysqladmin -h 127.0.0.1 -u root password 'test123'
mysql -uroot -h 127.0.0.1 -p -A
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%' IDENTIFIED BY 'test123' WITH GRANT OPTION; 
 flush privileges; 

## 3.5 start validation mysql service
systemctl start mysqld.service
ps auxf | grep mysql
netstat -tulnp | grep mysql
cat /data/mysql/mysqld.log 
```powershell

4. Verify LNMP environment

vim /usr/local/nginx/html/test_mysql.php
<?php
$link=mysql_connect("127.0.0.1","root","test123");
if(!$link){
 echo "mysql_connect fail";
}else{
echo "mysql_connect success";
}
?>
http://serverip/test_mysql.php web Visit

5.zabbix construction

yum install -y libevent-devel weget tar gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel  #Environmental dependence:
cd /usr/local/src/
tar -zxvf zabbix-4.0.16.tar.gz 
cd zabbix-4.0.16
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
make && make install 
export PATH=$PATH:/usr/local/zabbix/sbin/:/usr/local/zabbix/bin  #Add environment variable
zabbix_server --version

5.1 ZABBIX server database initialization

Use root Sign in mysql
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbix123';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

set names utf8;
use zabbix;
source /usr/local/src/zabbix-4.0.16/database/mysql/schema.sql
source /usr/local/src/zabbix-4.0.16/database/mysql/data.sql
source /usr/local/src/zabbix-4.0.16/database/mysql/images.sql

5.2 ZABBIX server configuration

vim /usr/local/zabbix/etc/zabbix_server.conf

LogFile=/usr/local/zabbix/zabbix_server.log
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix123
DBPort=3306
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/externalscrips
LogSlowQueries=3000


useradd -s /sbin/nologin zabbix
chown  zabbix:zabbix -R /usr/local/zabbix/

zabbix_server #Start zabbix
ps auxf| grep zabbix_server
netstat -tulnp| grep zabbix
tail-f /usr/local/zabbix/zabbix_server.log

5.3 zabbix web installation

mkdir /usr/local/nginx/html/zabbix
cp -a /usr/local/src/zabbix-4.0.16/frontends/php/* /usr/local/nginx/html/zabbix/

http://ip/zabbix/setup.php ##Visit zabbix for configuration
vim /usr/local/php/etc/php.ini ##zabbix web will prompt that some parameters fail. Modify the following php configuration parameters
post_max_size = 32M
max_execution_time = 350
max_input_time = 350
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1

systemctl restart php-fpm  ##Restart service

//Finally, zabbix will try to copy the configuration file directly to configure zabbix.conf.php

vim /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;

$DB['TYPE']     = 'MYSQL';
$DB['SERVER']   = '127.0.0.1';
$DB['PORT']     = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER']     = 'zabbix';
$DB['PASSWORD'] = 'zabbix123';

// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';

$ZBX_SERVER      = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

//The default zabbix password is Admin zabbix

6.Grafana installation

yum -y localinstall grafana-6.0.2-1.x86_64.rpm
systemctl enable grafana-server
systemctl start grafana-server
Published 1 original article, praised 0 and visited 12
Private letter follow

Tags: PHP Zabbix MySQL Nginx

Posted on Mon, 03 Feb 2020 10:23:07 -0500 by thebopps