lnmp部署zabbix
阿新 • • 發佈:2018-11-03
需求說明
在三臺不同的主機上搭建lnmp環境並安裝配置zabbix
環境說明
在三臺主機上搭建好lnmp並可以正常執行,如何搭建戳這裡----->三臺主機搭建lnmp
系統平臺 | ip | 需要安裝的服務 |
---|---|---|
centos7,redhat7 | 172.16.11.13 | nginx |
centos7,redhat7 | 172.16.11.14 | mysql |
centos7,redhat7 | 172.16.11.15 | php |
①.關閉防火牆
[[email protected] ~]# systemctl stop firewalld.service
②.關閉selinux
[[email protected] ~]# setenforce 0
[[email protected] ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
③.需要在安裝nginx的伺服器上下載zabbix原始碼包
[[email protected] ~]# ls
[[email protected] ~]# ls
anaconda-ks.cfg nginx-1.14.0 nginx-1.14.0.tar.gz zabbix-4.0.0 zabbix-4.0.0.tar.gz
zabbix下載
操作步驟
- 172.16.11.14
配置zabbix資料庫
[[email protected] ~]# mysql -uroot -p
Enter password:
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.07 sec)
mysql> grant all privileges on zabbix.* to [email protected] identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.13 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)
- 172.16.11.13
①.安裝依賴包和mariadb包
[[email protected] ~]# yum -y install net-snmp-devel libevent-devel mariadb mysql-devel libcurl-devel libxml2-devel
②.下載zabbix 的原始碼包並解壓,建立zabbix使用者
[[email protected] ~]# tar -xf zabbix-3.4.12.tar.gz
[[email protected] ~]# groupadd -r zabbix
[[email protected] ~]# useradd -r -M -s /sbin/nologin -g zabbix zabbix
③.往zabbix資料庫匯入檔案
[[email protected] ~]# cd zabbix-3.4.12/database/mysql/
[[email protected] mysql]# ls
data.sql images.sql schema.sql
[[email protected] mysql]# mysql -h 172.16.11.14 -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure
[[email protected] mysql]# mysql -h 172.16.11.14 -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[[email protected] mysql]# mysql -h 172.16.11.14 -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure
④.編譯安裝zabbix
[[email protected] zabbix-3.4.12]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
[[email protected] zabbix-3.4.12]# make install
⑤.修改服務端配置檔案,新增如下內容,並啟動服務
[[email protected] ~]# vim /usr/local/etc/zabbix_server.conf
DBPassword=zabbix123!
[[email protected] ~]# zabbix_server
[[email protected] ~]# zabbix_agentd
⑥.修改配置檔案建立網頁
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
error_log logs/error.log;
#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;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8000;
server_name www.haha.com;
location / {
root /www/aaa;
index index.php index.html;
}
location ~ \.php$ {
root /www/aaa;
fastcgi_pass 172.16.11.15:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/abc$fastcgi_script_name;
include fastcgi_params;
}
}
}
- 172.16.11.15
①.配置php
[[email protected] ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[[email protected] ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[[email protected] ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[[email protected] ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
②.建立存放網頁檔案的目錄
[[email protected] ~]# mkdir /www/abc/ -p
[[email protected] ~]# groupadd -r nginx //這裡nginx使用者的uid和pid要和nginx客戶端裡面的nginx的相同
[[email protected] ~]# useradd -r -s /sbin/nologin -M -g nginx nginx
[[email protected] ~]# chown -R nginx.nginx /www/
③.使用phpize命令生成configura然後新增模組,最後修改配置檔案加入如下內容
[[email protected] mysqli]# yum -y install php-mysqlnd
[[email protected] ~]# cd /root/php-7.2.8/ext/mysqli/
[[email protected] mysqli]# phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
[[email protected] mysqli]# ./configure --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
[[email protected] mysqli]# make && make install
[[email protected] mysqli]# vim /etc/php.ini
extension=mysqli.so //新增這一行
④.安裝nfs並配置
[[email protected] mysqli]# yum -y install nfs-utils
[[email protected] mysqli]# vim /etc/exports
/www/abc 172.16.11.13(rw,no_root_squash) //新增共享的目錄
[[email protected] mysqli]# systemctl start nfs-server
- 172.16.11.13
①.掛載nfs伺服器
[[email protected] nginx]# mount -t nfs 172.16.11.15:/www/abc /www/aaa/
[[email protected] nginx]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 17G 1.9G 16G 11% /
devtmpfs 478M 0 478M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 6.7M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 125M 890M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 3.8G 3.8G 0 100% /mnt
172.16.11.15:/www/abc 17G 2.2G 15G 13% /www/aaa
②.將zabbix的php網頁拷貝到掛載的目錄裡面去
[[email protected] nginx]# cp -r /root/zabbix-4.0.0/frontends/php/* /www/aaa/
③.修改目錄許可權來使其有許可權生成配置檔案
[[email protected] nginx]# chmod 777 /www/aaa/conf/
安裝配置zabbix
到這裡就配置完成可以測試了,我就放測試圖了,想看如何配置請看上篇文件
報錯解決
①.使用phpize的時候報錯
[[email protected] mysqli]# phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
解決辦法:安裝autoconf,直接使用 yum -y install autoconf
②.配置zabbix的時候發現 PHP databases support off
解決辦法:檢視上面172.16.11.15配置裡面的第三步即可