两台主机搭建zabbix监控(lnmp)
2019-03-02 17:36
423 查看
文章目录
nginx端:192.168.56.129
其他端:192.168.56.128
1.安装mysql
[root@localhost ~]# yum -y install gcc [root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel [root@localhost ~]# groupadd -r -g 306 mysql [root@localhost ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql [root@localhost ~]# cd /usr/src/ [root@localhost src]# tar xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@localhost src]# cd /usr/local/ [root@localhost local]# ls bin etc games include lib lib64 libexec mysql-5.7.23-linux-glibc2.12-x86_64 sbin share src [root@localhost local]# ll 总用量 0 drwxr-xr-x. 2 root root 6 3月 10 2016 bin drwxr-xr-x. 2 root root 6 3月 10 2016 etc drwxr-xr-x. 2 root root 6 3月 10 2016 games drwxr-xr-x. 2 root root 6 3月 10 2016 include drwxr-xr-x. 2 root root 6 3月 10 2016 lib drwxr-xr-x. 2 root root 6 3月 10 2016 lib64 drwxr-xr-x. 2 root root 6 3月 10 2016 libexec lrwxrwxrwx. 1 root root 36 3月 2 13:48 mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/ drwxr-xr-x. 9 root root 129 3月 2 13:42 mysql-5.7.23-linux-glibc2.12-x86_64 drwxr-xr-x. 2 root root 6 3月 10 2016 sbin drwxr-xr-x. 5 root root 49 1月 8 19:10 share drwxr-xr-x. 2 root root 6 3月 10 2016 src [root@localhost local]# chown -R mysql.mysql /usr/local/mysql [root@localhost local]# ll /usr/local/mysql -d lrwxrwxrwx. 1 mysql mysql 36 3月 2 13:48 /usr/local/mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/ [root@localhost local]# ls /usr/local/mysql bin COPYING docs include lib man README share support-files [root@localhost local]# cd [root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@localhost ~]# . /etc/profile.d/mysql.sh [root@localhost ~]# echo $PATH /usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost ~]# mkdir /opt/data [root@localhost ~]# chown -R mysql.mysql /opt/data/ [root@localhost ~]# ll /opt/ 总用量 0 drwxr-xr-x. 2 mysql mysql 6 3月 2 14:00 data [root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/ 2019-03-02T06:01:22.880828Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2019-03-02T06:01:23.154766Z 0 [Warning] InnoDB: New log files created, LSN=45790 2019-03-02T06:01:23.184014Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2019-03-02T06:01:23.267837Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9b86197a-3cb0-11e9-b11b-000c29ece1b2. 2019-03-02T06:01:23.268460Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2019-03-02T06:01:23.269050Z 1 [Note] A temporary password is generated for root@localhost: sn>#26&G7e69 [root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql "/usr/local/include/mysql" -> "/usr/local/mysql/include/" [root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf [root@localhost ~]# ldconfig -v [root@localhost ~]# cat > /etc/my.cnf <<EOF > [mysqld] > basedir = /usr/local/mysql > datadir = /opt/data > socket = /tmp/mysql.sock > port = 3306 > pid-file = /opt/data/mysql.pid > user = mysql > skip-name-resolve > EOF [root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld [root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld [root@localhost ~]# service mysqld start Starting MySQL.Logging to '/opt/data/localhost.err'. SUCCESS! [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 128 *:20048 *:* LISTEN 0 128 *:22 *:* LISTEN 0 64 *:43704 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:40666 *:* LISTEN 0 64 *:2049 *:* LISTEN 0 128 :::111 :::* LISTEN 0 128 :::20048 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 :::39610 :::* LISTEN 0 64 :::40125 :::* LISTEN 0 64 :::2049 :::* LISTEN 0 80 :::3306 :::* [root@localhost ~]# mysql -uroot -p mysql> set password = password('pengsuran123!'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> quit Bye
2.安装PHP
[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel libpcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php72w-mysqlnd [root@localhost local]# cd /usr/src/ [root@localhost src]# ls debug kernels mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz php-7.2.8.tar.xz zabbix-4.0.4.tar.gz [root@localhost src]# tar xf php-7.2.8.tar.xz [root@localhost src]# cd php-7.2.8/ [root@localhost php-7.2.8]# ./configure --prefix=/usr/local/php7 \ --with-config-file-path=/etc \ --enable-fpm \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-openssl \ --enable-bcmath \ --with-iconv \ --with-bz2 \ --enable-calendar \ --with-curl \ --enable-exif \ --enable-ftp \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --with-gettext \ --enable-json \ --enable-mbstring \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-readline \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-pcntl \ --enable-posix [root@localhost php-7.2.8]# make -j $(cat /proc/cpuinfo |grep processor|wc -l) [root@localhost php-7.2.8]# make install [root@localhost php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh [root@localhost php-7.2.8]# source /etc/profile.d/php7.sh [root@localhost php-7.2.8]# php -v PHP 7.2.8 (cli) (built: Mar 2 2019 15:20:58) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies [root@localhost php-7.2.8]# cp php.ini-production /etc/php.ini [root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm [root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf [root@localhos 20000 t php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf [root@localhost php-7.2.8]# vim /usr/local/php7/etc/php-fpm.conf [root@localhost php-7.2.8]# service php-fpm start Starting php-fpm done [root@localhost php-7.2.8]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 128 *:20048 *:* LISTEN 0 128 *:22 *:* LISTEN 0 64 *:43704 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:40666 *:* LISTEN 0 64 *:2049 *:* LISTEN 0 128 127.0.0.1:9000 *:* LISTEN 0 128 :::111 :::* LISTEN 0 128 :::20048 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 :::39610 :::* LISTEN 0 64 :::40125 :::* LISTEN 0 64 :::2049 :::* LISTEN 0 80 :::3306 :::*
3.安装zabbix
[root@psr1 ~]# yum -y install net-snmp-devel libevent-devel [root@psr1 ~]# mv zabbix-4.0.4.tar.gz /usr/src/ [root@psr1 ~]# cd /usr/src/ [root@psr1 src]# tar xf zabbix-4.0.4.tar.gz [root@psr1 src]# groupadd -r zabbix [root@psr1 src]# useradd -r -g zabbix -M -s /sbin/nologin zabbix [root@psr1 src]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.23 MySQL Community Server (GPL) mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.06 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!'; Query OK, 0 rows affected, 2 warnings (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@psr1 ~]# cd /usr/src/zabbix-4.0.4/database/mysql/ [root@psr1 mysql]# ls data.sql images.sql Makefile.am Makefile.in schema.sql [root@psr1 mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@psr1 mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@psr1 mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@psr1 mysql]# cd /usr/src/zabbix-4.0.4/ [root@psr1 zabbix-4.0.4]# ./configure --enable-server \ > --enable-agent \ > --with-mysql \ > --with-net-snmp \ > --with-libcurl \ > --with-libxml2 [root@psr1 zabbix-4.0.4]# make install [root@psr1 ~]# ls /usr/local/etc/ zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d [root@psr1 ~]# vim /usr/local/etc/zabbix_server.conf [root@psr1 ~]# zabbix_server [root@psr1 ~]# zabbix_agentd [root@psr1 ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 *:20048 *:* LISTEN 0 128 *:22 *:* LISTEN 0 64 *:43704 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:40666 *:* LISTEN 0 64 *:2049 *:* LISTEN 0 128 *:10050 *:* LISTEN 0 128 *:10051 *:* LISTEN 0 128 127.0.0.1:9000 *:* LISTEN 0 128 :::111 :::* LISTEN 0 128 :::20048 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 :::39610 :::* LISTEN 0 64 :::40125 :::* LISTEN 0 64 :::2049 :::* LISTEN 0 80 :::3306 :::*
4.php端配置
[root@localhost ~]# mkdir -p /var/www/zabbix [root@localhost ~]# cd /usr/src/zabbix-4.0.4/ [root@localhost zabbix-4.0.4]# ls aclocal.m4 ChangeLog config.log configure.ac frontends m4 man README AUTHORS compile config.status COPYING include Makefile misc sass bin conf config.sub database INSTALL Makefile.am missing src build config.guess configure depcomp install-sh Makefile.in NEWS [root@localhost zabbix-4.0.4]# cd frontends/ [root@localhost frontends]# ls php [root@localhost frontends]# cd php/ [root@localhost php]# ls actionconf.php chart6.php images screenedit.php adm.gui.php chart7.php img screen.import.php adm.housekeeper.php chart.php imgstore.php screens.php adm.iconmapping.php charts.php include search.php adm.images.php conf index_http.php services.php adm.macros.php conf.import.php index.php setup.php adm.other.php correlation.php items.php slideconf.php adm.regexps.php discoveryconf.php js slides.php adm.triggerdisplayoptions.php disc_prototypes.php jsLoader.php srv_status.php adm.triggerseverities.php favicon.ico jsrpc.php styles adm.valuemapping.php fonts latest.php sysmap.php adm.workingtime.php graphs.php local sysmaps.php api_jsonrpc.php history.php locale templates.php app host_discovery.php maintenance.php toptriggers.php applications.php hostgroups.php map.import.php tr_events.php audio hostinventoriesoverview.php map.php trigger_prototypes.php auditacts.php hostinventories.php overview.php triggers.php auditlogs.php host_prototypes.php profile.php usergrps.php browserwarning.php host_screen.php queue.php users.php chart2.php hosts.php report2.php zabbix.php chart3.php httpconf.php report4.php chart4.php httpdetails.php robots.txt chart5.php image.php screenconf.php [root@localhost zabbix-4.0.4]# cp -a frontends/php/* /var/www/zabbix/ [root@localhost zabbix-4.0.4]# cd [root@localhost ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf [root@localhost ~]# service php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done 然后安装NFS [root@localhost ~]# yum -y install nfs-utils [root@localhost ~]# systemctl start rpcbind nfs-server [root@localhost ~]# vim /etc/exports /var/www/zabbix *(ro) [root@localhost ~]# chmod 777 /var/www/zabbix/ [root@localhost ~]# systemctl restart nfs-server [root@localhost zabbix]# vim /usr/local/php7/etc/php-fpm.d/www.conf 将listen = 127.0.0.1:9000 改为listen = 192.168.56.128:9000 [root@localhost zabbix]# service php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done
5.nginx端配置
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf error_log logs/error.log; //将此行取消注释 location / { root html; index index.php index.html index.htm ; //在这添加index.php } location ~ \.php$ { //这边是去消注释,并改为以下内容 root /var/www/zabbix; //这里必须指向php端的zabbix文件 fastcgi_pass 192.168.56.128:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //$document_root 指代前面的内容-/var/www/zabbix include fastcgi_params; } [root@localhost ~]# nginx -s reload //nginx端也要安装nfs [root@localhost ~]# yum -y install nfs-utils [root@localhost ~]# mount -t nfs 192.168.56.128:/var/www/zabbix /usr/local/nginx/html [root@localhost ~]# df -Th 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root xfs 18G 1.5G 17G 9% / devtmpfs devtmpfs 899M 0 899M 0% /dev tmpfs tmpfs 911M 0 911M 0% /dev/shm tmpfs tmpfs 911M 9.5M 902M 2% /run tmpfs tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda1 xfs 497M 135M 362M 28% /boot tmpfs tmpfs 183M 0 183M 0% /run/user/0 192.168.56.128:/var/www/zabbix nfs4 18G 5.9G 12G 34% /usr/local/nginx/html
验证:
相关文章推荐
- 两台虚拟机搭建zabbix监控(lnmp)
- CentOS 6.5 LNMP架构Zabbix 3.2.4监控端搭建
- 企业级监控软件zabbix搭建部署之zabbix Services添加主机
- 在CentOS 7 64位操作系统环境下搭建LNMP(Linux+Nginx+MySQL+PHP)来运行Zabbix监控程序
- LNMP安装配置Zabbix搭建企业级监控平台
- centos 快速搭建lnmp、lamp+zabbix3.2监控系统
- Linux监控平台——搭建zabbix监控平台,zabbix监控主动模式、被动模式、添加监控主机、添加自定义模板、处理图形乱码、自动发现
- LNMP环境搭建(基于zabbix监控软件)
- 两台虚拟机搭建zabbix监控
- 企业级监控软件zabbix搭建部署之Zabbix自定义端口阈值配置以及应用 推荐
- zabbix监控主动模式、被动模式、添加监控主机、添加自定义模板、处理图形乱码、自动发现
- zabbix 3.4.6 监控windows 主机(安装windows agent)
- Linux系统搭建zabbix监控系统实例讲解
- zabbix3.0.4监控linux主机cpu使用率超过90%的时候报警
- CentOS 7.3下Zabbix 4.0监控搭建过程超详细教程
- Zabbix监控Windows主机
- zabbix监控之Centos基于LNMP环境安装
- 分布式监控系统Zabbix-3.0.3-lnmp安装记录
- zabbix监控两台文件的md5值是否一致
- 排错 zabbix-agent 主机重启无法被监控