Centos 7.6搭建LAMP,部署zabbix監控環境


一、安裝環境 LAMP 

整套一起安裝

一套:yum install httpd httpd-devel mysql-server mysql-devel php php-devel php-mysql -y

分開安裝

1、安裝apache

yum install -y httpd

httpd服務開機進行自啟:systemctl enable httpd

啟動httpd服務:systemctl start httpd

開啟80端口:iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT 臨時,關機重啟,不生效

    firewall-cmd --zone=public --add-port=5672/tcp --permanent   # 開放5672端口

    firewall-cmd --zone=public --remove-port=5672/tcp --permanent  #關閉5672端口

    firewall-cmd --reload   # 配置立即生效

   查看防火牆所有開放的端口

  firewall-cmd --zone=public --list-ports

  查看防火牆狀態

  firewall-cmd --state

  查看監聽的端口

  netstat -lnpt


查看端口號:iptables -L -n

有些Centos 7.6里面沒有安裝wget命令,所以要自己安裝:

yum -y install wget

1.1.MYSQL安裝

下載mysql的repo源:

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

安裝mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

安裝MYSQL

sudo yum install -y  mysql-server

重啟服務:

systemctl restart mysql 或
systemctl restart mysql.service

登錄,並修改密碼:

mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > flush privileges;
mysql > exit;

安裝php環境

yum -y install php
rpm -ql php

 將php與mysql關聯起來

yum install -y php php-mysql
rpm -ql php-mysql

 安裝常用PHP模塊

yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
放入測試文件:
cd  /var/www/html
echo '<?php phpinfo();?>' >index.php

重啟apache服務器

 systemctl restart httpd

下載zabbix

wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.6/zabbix-3.2.6.tar.gz
在zabbix_server和zabbix_agent端執行
yum -y install curl curl-devel net-snmp net-snmp-devel perl-DBI
groupadd zabbix;
useradd -g zabbix zabbix;
usermod -s /sbin/nologin zabbix
創建初始數據庫:
# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by '123456';
mysql
> quit;
mysql -uzabbix -p123456 zabbix<database/mysql/schema.sql
mysql -uzabbix -p123456 zabbix<database/mysql/images.sql
mysql -uzabbix -p123456 zabbix<database/mysql/data.sql
安裝
yum -y install gcc

yum -y install gcc

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

make && make install
ln -s /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/

安裝完畢后,進入/usr/local/zabbix/etc/目錄,

 cp zabbix_server.conf zabbix_server.conf.bak
為Zabbix服務器配置數據庫
vim zabbix_server.conf

 正常安裝完zabbix后,登錄后zabbix監控報錯zabbix server is not running: the information displayed may not be current

下面的幾種情況都有可能引起這個錯誤,

1. selinux是否關閉。一定要關閉這個,開啟selinux會引起一連串問題,甚至zabbix的discovery功能也不能正常使用

關閉SELinux的方法:
臨時關閉:setenforce 0

永久關閉:vi /etc/selinux/config

同時cp zabbix_server 啟動腳本至/etc/init.d目錄,啟動zabbix_server,zabbix_server默認監聽端口為10051

cp misc/init.d/tru64/zabbix_server  /etc/init.d/zabbix_server
chmod o+x /etc/init.d/zabbix_server
/etc/init.d/zabbix_server start

 

 

 用下面代碼解決:

sed -i '/post_max_size/s/8/16/g;/max_execution_time/s/30/300/g;/max_input_time/s/60/300/g;s/\;date.timezone. * /date.timezone \=PRC/g;s/\;always_populate_raw_post_data/always_populate_raw_post_data/g' /etc/php.ini
注:
setenforce 1 設置SELinux 成為enforcing模式
setenforce 0 設置SELinux 成為permissive模式 
在lilo或者grub的啟動參數中增加:selinux=0,也可以關閉selinux

關閉防火牆

臨時關閉:systemctl stop firewalld.service

永久關閉:systemctl disable firewalld.service

1.安裝agent(在監控的目標主機上配置)

創建用戶

groupadd zabbix;

useradd -g zabbix zabbix;
usermod -s /sbin/nologin zabbix

 

安裝方法和安裝zabbix一樣

wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.2.6/zabbix-3.2.6.tar.gz
tar zxvf zabbix-3.2.6.tar.gz 
./configure --prefix=/usr/local/zabbix --enable-agent
make
make install
ln -s /usr/local/zabbix/sbin/zabbix_* /usr/local/sbin/
cp misc/init.d/tru64/zabbix_agentd /etc/init.d/zabbix_agentd
chmod o+x /etc/init.d/zabbix_agentd
/etc/init.d/zabbix_agentd start

主機檢測鏈接

/usr/local/zabbix/bin/zabbix_get -s 192.168.72.130 -k system.uname

 

 表示鏈接上

修改agent配置文件

vim /etc/zabbix/zabbix_agentd.conf
vim /etc/zabbix/zabbix_agentd.conf

Server=192.168.2.76 監控服務器是哪台主機

ServerActive=127.0.0.1 被監控的服務器是哪台主機

Hostname=node1 被監控主機名

啟動agent服務

/etc/init.d/zabbix_agentd restart

接着在zabbix web界面手動將該主機納入監控的主機上

記得被監控的主機關閉:selinux。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM