Zabbix 能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。是一个基于 Web 界面的提供分布式系统监视以及网络监视功能的企业级开源解决方案。
准备工作:
主机名 | 操作系统 | IP地址 |
zabbix | CentOS7 | 192.168.1.1 |
nginx_php | 192.168.1.2 | |
mysql | 192.168.1.3 | |
192.168.1.3上操作
[root@mysql ~]# yum -y install mariadb mariadb-server mariadb-libs mariadb-devel
[root@mysql ~]# systemctl start mariadb #开启mariadb数据库
[root@mysql ~]# mysql_secure_installation #数据库初始化设置
Enter current password for root (enter for none): #直接回车
Set root password? [Y/n] y #是否设置root密码
Remove anonymous users? [Y/n] n #是否移除匿名用户
Disallow root login remotely? [Y/n] n #是否不允许root远程登录
Remove test database and access to it? [Y/n] n #是否移除测试数据库
Reload privilege tables now? [Y/n] y #是否重载数据库表
[root@mysql ~]# mysql -uroot -p123
MariaDB [(none)]> grant all on *.* to root@'%' identified by '123456';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
192.168.1.2上操作
挂光盘,并配置yum源
[root@nginx_php ~]# yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
[root@nginx_php ~]# ls
anaconda-ks.cfg libmcrypt-2.5.7.tar.gz nginx-1.10.3.tar.gz php-5.6.36.tar.gz
[root@nginx_php ~]# tar zxf nginx-1.10.3.tar.gz -C /usr/src/
[root@nginx_php ~]# cd /usr/src/nginx-1.10.3/
[root@nginx_php nginx-1.10.3]# useradd nginx -s /sbin/nologin
[root@nginx_php nginx-1.10.3]# ./configure \
--prefix=/usr/local/nginx \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-pcre \
--with-http_ssl_module \
--with-http_gzip_static_module \
--user=nginx --group=nginx && make && make install
[root@nginx_php nginx-1.10.3]# cd
[root@nginx_php ~]# ln -s /usr/local/nginx/sbin/* /usr/local/bin/
[root@nginx_php ~]# yum -y install make apr* autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel
[root@nginx_php ~]# tar zxf libmcrypt-2.5.7.tar.gz -C /usr/src/
[root@nginx_php ~]# cd /usr/src/libmcrypt-2.5.7/
[root@nginx_php libmcrypt-2.5.7]# ./configure \
--prefix=/usr/local/libmcrypt && make && make install
[root@nginx_php libmcrypt-2.5.7]# cd
[root@nginx_php ~]# tar zxf php-5.6.36.tar.gz -C /usr/src/
[root@nginx_php ~]# cd /usr/src/php-5.6.36/
[root@nginx_php php-5.6.36]# ./configure \
--prefix=/usr/local/php5.6 \
--with-config-file-path=/etc \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-gd \
--with-iconv \
--with-libxml-dir=/usr \
--with-mhash \
--with-mcrypt \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--with-zlib \
--with-freetype-dir \
--with-png-dir \
--with-jpeg-dir \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-mcrypt=/usr/local/libmcrypt \
--with-curl
[root@nginx_php php-5.6.36]# make && make install
[root@nginx_php php-5.6.36]# cp php.ini-production /etc/php.ini
[root@nginx_php php-5.6.36]# vim /etc/php.ini
修改:
202 short_open_tag = 0n #支持短标签
363 expose_php = 0ff #禁止显示php版本
372 max_execution_time = 300 #php脚本最大执行时间
382 max_input_time = 300 #以秒为单位对通过POST、GET以及PUT方式接收数据进行限制
660 post_max_size = 16M #上传文件大小限制
702 always_populate_raw_post_data = -1
936 date.timezone = Asia/Shanghai #时区设置为上海
删除:
1811 ;mbstring.func_overload = 0
[root@nginx_php php-5.6.36]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@nginx_php php-5.6.36]# chmod +x /etc/init.d/php-fpm
[root@nginx_php php-5.6.36]# chkconfig --add php-fpm
[root@nginx_php php-5.6.36]# cd
[root@nginx_php ~]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@nginx_php ~]# vim /usr/local/php5.6/etc/php-fpm.conf
25 pid = run/php-fpm.pid
149 user = nginx
150 group = nginx
164 listen = 127.0.0.1:9000
241 pm.max_children = 300
246 pm.start_servers = 10
251 pm.min_spare_servers = 10
256 pm.max_spare_servers = 50
[root@nginx_php ~]# /etc/init.d/php-fpm start
[root@nginx_php ~]# netstat -anpt | grep php-fpm
[root@nginx_php ~]# cd /usr/local/nginx/conf/
[root@nginx_php conf]# rm -rf nginx.conf
[root@nginx_php conf]# vim nginx.conf
user nginx;
worker_processes 4;
error_log logs/error.log;
pid logs/nginx.pid;
events {
use epoll;
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;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@nginx_php conf]# nginx -t
[root@nginx_php conf]# nginx
[root@nginx_php conf]# netstat -anpt | grep 80
[root@nginx_php ~]# vim /usr/local/nginx/html/test1.php
<?php
phpinfo()
?>
[root@nginx_php ~]# vim /usr/local/nginx/html/test2.php
<?php
$link=mysqli_connect('192.168.1.3','root','123456');
if($link) echo "恭喜你,数据库连接成功了!!";
mysqli_close($link);
?>
[root@mysql ~]# mysql -u root -p123
MariaDB [(none)]> create database zabbix character set utf8;
MariaDB [(none)]> grant all on zabbix.* to zabbix@'192.168.1.%' identified by 'zabbix';
MariaDB [(none)]> grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
[root@mysql ~]# ls
anaconda-ks.cfg zabbix-4.2.6.tar.gz
[root@mysql ~]# tar zxf zabbix-4.2.6.tar.gz -C /usr/src/
[root@mysql ~]# cd /usr/src/zabbix-4.2.6/
[root@mysql zabbix-4.2.6]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
[root@mysql zabbix-4.2.6]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
[root@mysql zabbix-4.2.6]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
挂光盘,并配置yum源
[root@zabbix ~]# yum -y install createrepo
[root@zabbix ~]# ls
anaconda-ks.cfg zabbix-4.2.6.tar.gz zabbix_rpm.tar.gz
[root@zabbix ~]# tar zxf zabbix_rpm.tar.gz -C /mnt
[root@zabbix ~]# createrepo /mnt/zabbix_rpm
[root@zabbix ~]# cat <<END > /etc/yum.repos.d/zabbix.repo
[zabbix]
name=zabbix
baseurl=file:///mnt/zabbix_rpm
enabled=1
gpgcheck=0
END
[root@zabbix ~]# yum -y install net-snmp net-snmp-devel curl-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel OpenIPMI-devel libssh2-devel libevent libevent-devel gcc* libxml2-devel mysql-devel
[root@zabbix ~]# groupadd zabbix
[root@zabbix ~]# useradd -s /sbin/nologin -g zabbix zabbix
[root@zabbix ~]# tar zxf zabbix-4.2.6.tar.gz -C /usr/src
[root@zabbix ~]# cd /usr/src/zabbix-4.2.6
[root@zabbix zabbix-4.2.6]# ./configure \
--prefix=/usr/local/zabbix \
--enable-server \
--enable-agent \
--enable-java \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-openipmi \
--with-mysql && make && make install
[root@zabbix zabbix-4.2.6]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/
[root@zabbix zabbix-4.2.6]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
[root@zabbix ~]# vim /usr/local/zabbix/etc/zabbix_server.conf
38 LogFile=/usr/local/zabbix/zabbix_server.log
68 PidFile=/usr/local/zabbix/logs/zabbix_server.pid
85 DBHost=192.168.1.3
94 DBName=zabbix
110 DBUser=zabbix
118 DBPassword=zabbix
133 DBPort=3306
创建进程号存放路径,并赋权
[root@zabbix ~]# mkdir -p /usr/local/zabbix/logs
[root@zabbix ~]# chown -R zabbix:zabbix /usr/local/zabbix/
[root@zabbix ~]# cd /usr/src/zabbix-4.2.6/misc/init.d/
[root@zabbix init.d]# cp fedora/core/* /etc/init.d/
[root@zabbix init.d]# vim /etc/init.d/zabbix_server
22 BASEDIR=/usr/local/zabbix
31 PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid
[root@zabbix init.d]# chkconfig --add zabbix_server
[root@zabbix init.d]# chkconfig zabbix_server on
[root@zabbix init.d]# systemctl start zabbix_server
[root@zabbix init.d]# netstat -anpt | grep 10051
[root@nginx_php ~]# ls
anaconda-ks.cfg nginx-1.10.3.tar.gz zabbix-4.2.6.tar.gz
libmcrypt-2.5.7.tar.gz php-5.6.36.tar.gz
[root@nginx_php ~]# tar zxf zabbix-4.2.6.tar.gz -C /usr/src/
[root@nginx_php ~]# cd /usr/src/zabbix-4.2.6/
[root@nginx_php zabbix-4.2.6]# cp -r frontends/php/* /usr/local/nginx/html/
[root@nginx_php zabbix-4.2.6]# chown -R nginx:nginx /usr/local/nginx/html/
[root@nginx_php zabbix-4.2.6]# nginx -s reload
[root@nginx_php zabbix-4.2.6]# /etc/init.d/php-fpm restart