一、安装环境 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功能也不能正常使用
临时关闭: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
关闭防火墙
临时关闭: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。