CentOS7 npm+zabbix 安装配置

mini安装centos7

更新yum源

yum -y install net-tools wget lrzsz lsof
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all
yum makecache

 

安装依赖库

yum -y remove selinux*
yum -y update
yum -y install pcre pcre-devel openssl openssl-devel gcc-c++
systemctl stop firewalld.service
systemctl disable firewalld.service

 

 安装nginx

cd /home/
useradd -s /sbin/nologin -M nginx
wget http://nginx.org/download/nginx-1.13.8.tar.gz
tar -zxvf nginx-1.13.8.tar.gz
cd nginx-1.13.8
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.13.8 --with-http_stub_status_module --with-http_ssl_module
make && make install
ln -s /application/nginx-1.13.8/ /application/nginx
cd /application/nginx/conf
egrep -v "#|^$" nginx.conf.default > nginx.conf

 

 配置nginx

vi /application/nginx/conf/nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    client_max_body_size 8M;
    client_body_buffer_size 128k;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~\.(php|php5)?$ {
                root /application/nginx/html;
                fastcgi_read_timeout 150;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /application/nginx/html$fastcgi_script_name;
                include    fastcgi_params;
        }
    }
}

 /application/nginx/sbin/nginx -t

CentOS7 npm+zabbix 安装配置


 nginx自启设置

vi /lib/systemd/system/nginx.service

Description=nginx  
After=network.target  
   
[Service]  
Type=forking  
ExecStart=/application/nginx/sbin/nginx  
ExecReload=/application/nginx/sbin/nginx -s reload
ExecStop=/application/nginx/sbin/nginx -s stop
PrivateTmp=true  
   
[Install]  
WantedBy=multi-user.target

systemctl enable nginx.service

systemctl start nginx.service

CentOS7 npm+zabbix 安装配置

安装PHP环境

cd /home/
wget http://cn2.php.net/distributions/php-5.6.32.tar.gz
cd php-5.6.32
yum install -y epel-release
yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

./configure --prefix=/application/php-5.6.32 --with-mysql --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-gettext --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --enable-opcache=no
make && make install

ln -s /application/php-5.6.32/ /application/php
cp php.ini-production /application/php/lib/php.ini
cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf

php-fpm自动启动

vi /lib/systemd/system/php-fpm.service

[Unit]
Description=php
After=network.target

[Service]
Type=forking
ExecStart=/application/php/sbin/php-fpm
ExecStop=pkill -9 php-fpm
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl enable php-fpm.service

systemctl start php-fpm.service
CentOS7 npm+zabbix 安装配置

安装mysql

cd /home/
 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm 
yum repolist enabled | grep "mysql.*-community.*"
yum install mysql-community-server mysql-devel -y
systemctl start mysqld.service
systemctl enable mysqld.service

初始化mysql密码:

more /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: aYXccWSPA7<-

mysql -uroot -p
Enter password:aYXccWSPA7<-

5.7.6以及之后的版本修改密码的命令为:
ALTER USER 'root'@'localhost' IDENTIFIED BY '!@QWASZX1q2w3e4r';
mysql>

安装zabbix 

yum -y install mysql-devel net-snmp-devel  libevent  libevent-devel

cd /home/
wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.5/zabbix-3.4.5.tar.gz
cd zabbix-3.4.5

groupadd zabbix
useradd -g zabbix zabbix

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
make && make install

mkdir -p /usr/local/zabbix/logs
chown -R zabbix.zabbix /usr/local/zabbix/logs

mv /usr/local/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf.bak
mv /usr/local/zabbix/etc/zabbix_agentd.conf /usr/local/zabbix/etc/zabbix_agentd.conf.bak

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

LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/logs/zabbix_server.pid
DBHost=172.29.10.21
DBName=zabbix
DBUser=zabbix
DBPassword=!@QWASZX1q2w3e4r
ListenIP=0.0.0.0
Timeout=4
FpingLocation=/usr/sbin/fping
AlertScriptsPath=/usr/local/zabbix/shell
LogSlowQueries=3000

vi /usr/local/zabbix/etc/zabbix_agentd.conf

LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
PidFile=/usr/local/zabbix/logs/zabbix_agentd.pid
Server=172.16.33.20,172.16.33.22,172.16.33.23,172.29.10.20,172.29.10.1
ServerActive=127.0.0.1
Hostname=WebSvn
UserParameter=Rec_Count[*],/script/test $1
UserParameter=Rec_Dva[*],/script/test $1
UserParameter=Avaya_Count[*],/script/avaya/avaya $1
UserParameter=count[*],python /script/py/count.py $1
UserParameter=avaya_trunk[*],python /script/py/avaya_trunk.py $1 $2 $3 $4
UserParameter=area_call_count[*],python /script/py/area_call_count.py $1 $2
UserParameter=business[*],python /script/py/business_number_count.py $1 $2

设置zabbix自动启动

cd /home/zabbix-3.4.5/misc/init.d/tru64
cp zabbix_* /etc/init.d/
chmod +x /etc/init.d/zabbix_*

vi /etc/init.d/zabbix_server
SERVICE="Zabbix server"
DAEMON=/usr/local/zabbix/sbin/zabbix_server
PIDFILE=/usr/local/zabbix/logs/zabbix_server.pid

vi /etc/init.d/zabbix_agentd 
SERVICE="Zabbix agent"
DAEMON=/usr/local/zabbix/sbin/zabbix_agentd
PIDFILE=/usr/local/zabbix/logs/zabbix_agentd.pid

ln -s /usr/local/zabbix/etc/* /usr/local/etc

vi /lib/systemd/system/zabbix_server.service 

[Unit]  
Description=zabbix_server
After=network.target  
   
[Service]  
Type=forking  
ExecStart=/etc/init.d/zabbix_server start
ExecReload=/etc/init.d/zabbix_server restart
ExecStop=/etc/init.d/zabbix_server stop
PrivateTmp=true  
   
[Install]  
WantedBy=multi-user.target

vi /lib/systemd/system/zabbix_agentd.service 

[Unit]
Description=zabbix_agentd
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/zabbix_agentd start
ExecReload=/etc/init.d/zabbix_agentd restart
ExecStop=/etc/init.d/zabbix_agentd stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

创建数据库

create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by '!@QWASZX1q2w3e4r';
grant all privileges on zabbix.* to zabbix@'%'  identified by '!@QWASZX1q2w3e4r';
flush privileges;
exit

cd /home/zabbix-3.4.5
mysql -uzabbix -p!@QWASZX1q2w3e4r zabbix < /home/zabbix-3.4.5/database/mysql/schema.sql
mysql -uzabbix --p!@QWASZX1q2w3e4r zabbix < /home/zabbix-3.4.5/database/mysql/images.sql
mysql -uzabbix --p!@QWASZX1q2w3e4r zabbix < /home/zabbix-3.4.5/database/mysql/data.sql

systemctl start zabbix_server.service

systemctl start zabbix_agentd.service

systemctl enable zabbix_agentd.service

systemctl enable zabbix_server.service

访问:http://172.29.10.21/zabbix/setup.php

依次填写信息,至完成

zabbix图像文字乱码处理

某台机器,非本机
cd /application/nginx/html/zabbix/fonts/
scp simhei.ttf [email protected]:$(pwd)
回到本机
chown -R nginx.nginx /application/nginx/html/zabbix/fonts/simhei.ttf 
sed -i 's/DejaVuSans/simhei/g' /application/nginx/html/zabbix/include/defines.inc.php

 

安装fping

yum -y install fping