文章目录
一、部署环境
服务端:192.168.182.11
客户端:192.168.182.22
二、服务端配置
(1)、关闭防火墙
systemctl stop firewalld
systemctl enable firewalld
setenforce 0
LNMP安装环境
(2)、安装nginx
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
1、手动创建nginx yum安装源
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@localhost ~]# yum clean all 清空缓存
[root@localhost ~]# yum list 加载列表
2、安装nginx,默认为nginx-1.12.2
yum install -y nginx
systemctl start nginx
systemctl enable nginx
netstat -natp | grep 80
(3)、安装mysql 5.7
yum install -y mariadb-server mariadb
systemctl enable mariadb.service
systemctl start mariadb
mysql_secure_installation
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #回车
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] Y #设置密码
New password: #abc123
Re-enter new password: #abc123
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] n #不删除匿名用户
... skipping.
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n #允许远程登录
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n #不删除测试数据库
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y #重新加载
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
//验证密码已经设置好无误
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> \q
Bye
(4)、安装PHP 7. 2
1、安装PHP源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
或者
yum install epel-release-y
2、yum仓库建立,安装软件包
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm ## yum源
//等待时间取决于网络
yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
php -v 查看php版本
(5)、配置nginx支持php
1、修改php-fpm配置文件,把apache改为nginx
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
#第8行 user = nginx
#第10行 group = nginx
2、配置location,在index中添加index.php。以支持index.php的首页
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf
#第10行 index index.php index.html index.htm;
#第30~36行
#配置php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去掉注释并修改
#把fastcgi_param中的/scripts改为$document_root。root是配置php程序放置的根目录。
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scri pt_name;
include fastcgi_params;
}
// 把fastcgi_param中的/scripts改为$document_root。 root是配置php程序放置的根目录
(6)、配置PHP
1、修改PHP配置文件
vim /etc/php.ini
#第359行 expose_php = Off //隐藏php版本
#第202行 short_open_tag = On //支持php短标签
//以下为zabbix配置要求
#第368行 max_execution_time = 300 //执行时间
#第378行 max_input_time = 300 //接收数据等待时间
#第389行 memory_limit = 128M //每个脚本占用内存
#第656行 post_max_size = 16M //POST数据大小
#第799行 upload_max_filesize = 2M //下载文件大小
#第800行 always_populate_raw_post_data = -1 //可以用 $HTTP_RAW_POST_DATA 接收post raw data
#第877行 date.timezone = Asia/Shanghai //时区
2、开启PHP服务并重启nginx服务
systemctl start php-fpm.service
systemctl enable php-fpm.service
netstat -ntap | grep 9000
systemctl restart nginx
(7)、测试首页
(1)写一个简单的测试首页
[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
(2)浏览器访问192.168.182.11/info.php
(8)、测试连接数据库
[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','root','abc123');
if ($link) echo "连接成功!!";
else echo "连接失败!!";
?>
注:mysql_connect扩展自 PHP 5.5.0 起已废弃,改用mysqli或pdo_mysql
(9)、安装zabbix前提
1、准备zabbix数据库
[root@localhost html]# mysql -uroot -p
ariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
MariaDB [(none)]> flush privileges; ##刷新权限
#collate的作用
对于mysql中那些字符类型的列,如VARCHAR,CHAR,TEXT类型的列,都需要有一个COLLATE类型来告知mysql如何对该列进行排序和比较。
2、检查用户能否登录数据库
[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','zabbix','admin123');
if ($link) echo "Zabbix数据库连接成功!";
else echo "Zabbix数据库连接失败!";
?>
浏览器验证之后,会发现连接失败。
3、解决本地登录无法登录的问题(连接成功,可忽略)
[root@localhost html]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select user,host from mysql.user; #有空用户名称占用导致本地无法登录远程可登录
+--------+-----------------------+
| user | host |
+--------+-----------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+--------+-----------------------+
7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@localhost; #删除空用户
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@localhost.localdomain; #删除空用户
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------------------+
| user | host |
+--------+-----------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | localhost.localdomain |
+--------+-----------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> \q
Bye
再刷新一下网页,连接成功。这里原因就是有空用户导致连接失败
三、部署zabbix Server
zabbix 官网 https://www.zabbix.com/download
1、安装yum源
rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
2、安装相关环境包
yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent
3、导入数据库脚本
生成数据库文件,注意密码不要输成root的
[root@localhost zabbix]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: #密码admin23
//查看文件是否存在
[root@localhost zabbix]# mysql -uzabbix -p
MariaDB [(none)]> use zabbix;
MariaDB [zabbix]> show tables;
4、修改zabbix配置文件
vim /etc/zabbix/zabbix_server.conf
//91行;去掉注释;连接本地的数据库
DBHost=localhost
//124行;修改本行;数据库密码
DBPassword=admin123
#----------------其他相关配置(比较重要的配置,看情况修改)------------------------
//38行;日志文件位置
LogFile=/var/log/zabbix/zabbix_server.log
//49行;日志文件大小;设置为0,不限制日志文件大小
LogFileSize=0
//72行;pid文件位置
PidFile=/var/run/zabbix/zabbix_server.pid
//82行;套接字文件位置;套接字是计算机之间进行通信的一种约定或一种方式
SocketDir=/var/run/zabbix
//100行;数据库名
DBName=zabbix
//116行;数据库用户名
DBUser=zabbix
//356行;采用的网络管理协议SNMP
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
//473行;超时时间
Timeout=4
//516行;脚本文件
AlertScriptsPath=/usr/lib/zabbix/alertscripts
//527行;扩展脚本文件
ExternalScripts=/usr/lib/zabbix/externalscripts
//563行;慢日志时间,超过3000秒记录
LogSlowQueries=3000
5、启动zabbix及相关服务
注意:setenforce 0 系统安全机制一定要关闭
修改属主、属组、赋权
cp -r /usr/share/zabbix/ /usr/share/nginx/html/
chown -R zabbix:zabbix /etc/zabbix/
chown -R zabbix:zabbix /usr/share/nginx/
chown -R zabbix:zabbix /usr/lib/zabbix/
chmod -R 755 /etc/zabbix/web/
chmod -R 777 /var/lib/php/session/
重启服务
systemctl start zabbix-server.service
systemctl enable zabbix-server.service
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service
netstat -anpl | grep 10051
netstat -anpl | grep 10050
systemctl restart php-fpm.service
systemctl restart nginx
安装后登录 用户名Admin 密码:zabbix
http://192.168.162.11/zabbix/
//安装后登录用户名:Admin 密码: zabbix
6、配置客户端(被监控端)
安装zabbix存储库与agent代理服务
rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
yum -y install zabbix-agent
修改zabbix代理配置文件
--
vim /etc/zabbix/zabbix_agentd.conf '//修改zabbix代理配置文件'
Server=192.168.200.40 '//98行,指向监控服务器地址'
ServerActive=192.168.200.40 '//139行,指向监控服务器地址'
Hostname=Zabbix-test '//150行,修改名称'
--
systemctl start zabbix-agent.service && systemctl enable zabbix-agent.service
netstat -ntap |grep 'zabbix'
转载:https://blog.csdn.net/panrenjun/article/details/115375833
查看评论