服务端:192.168.200.40
客户端:192.168.200.60
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
root@localhost ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
--2021-04-01 11:13:37-- http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:4680 (4.6K) [application/x-redhat-package-manager]
正在保存至: “nginx-release-centos-7-0.el7.ngx.noarch.rpm”
100%[======================>] 4,680 --.-K/s 用时 0s
2021-04-01 11:13:38 (400 MB/s) - 已保存 “nginx-release-centos-7-0.el7.ngx.noarch.rpm” [4680/4680])
[root@localhost ~]# 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 list
如果出现以下问题:
[root@localhost ~]# yum list
已加载插件:fastestmirror, langpacks
/var/run/yum.pid 已被锁定,PID 为 17043 的另一个程序正在运行。
Another app is currently holding the yum lock; waiting for it to exit...
另一个应用程序是:PackageKit
内存:162 M RSS (649 MB VSZ)
已启动: Thu Apr 1 11:10:49 2021 - 03:31之前
状态 :睡眠中,进程ID:17043
将进程杀掉即可:
[root@localhost ~]# kill -5 17043
[root@localhost ~]# yum install nginx -y
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 108485/nginx: maste
[root@localhost ~]# systemctl enable nginx #设为开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# yum install -y mariadb-server mariadb
[root@localhost ~]# systemctl start mariadb.service
[root@localhost ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[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
[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
获取https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
警告:/var/tmp/rpm-tmp.uNc4OO: 头V3 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:epel-release-7-12 ################################# [100%]
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
获取https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
警告:/var/tmp/rpm-tmp.O9dfAV: 头V4 RSA/SHA1 Signature, 密钥 ID 62e74ca5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:webtatic-release-7-3 ################################# [100%]
[root@localhost ~]# yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
[root@localhost ~]# php -v
PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
#第8行 user = nginx
#第10行 group = nginx
[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_script_name;
include fastcgi_params;
}
[root@localhost ~]# 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 //时区
[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# netstat -ntap | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 86082/php-fpm: mast
[root@localhost html]# systemctl restart nginx
[root@localhost ~]# vim /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
[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
[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如何对该列进行排序和比较。
[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数据库连接失败!";
?>
[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 官网 https://www.zabbix.com/download
[root@localhost ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
警告:/var/tmp/rpm-tmp.ReqDjI: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
38:LogFile=/var/log/zabbix/zabbix_server.log
49:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
82:SocketDir=/var/run/zabbix
91:DBHost=localhost //注释去掉
100:DBName=zabbix
116:DBUser=zabbix
124:DBPassword=admin123 //修改本行
356:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473:Timeout=4
516:AlertScriptsPath=/usr/lib/zabbix/alertscripts
527:ExternalScripts=/usr/lib/zabbix/externalscripts
563:LogSlowQueries=3000
[root@localhost ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf
#检查修改的配置文件是否正确
[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php
:%s /graphfont/kaiti/g #同时按住shift与:键
cp STKAITI.TTF /usr/share/zabbix/fonts/
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/
'//递归修改文件权限'
[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;
[root@localhost zabbix]# vim /etc/httpd/conf.d/zabbix.conf
#第20行 php_value date.timezone Asia/Shanghai
systemctl start zabbix-server.service && systemctl enable zabbix-server.service
systemctl start zabbix-agent.service && systemctl enable zabbix-agent.service
systemctl restart php-fpm.service && systemctl restart nginx
[root@localhost zabbix]# netstat -anpl | grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 121393/zabbix_serve
tcp 0 0 127.0.0.1:10051 127.0.0.1:58008 TIME_WAIT -
tcp6 0 0 :::10051 :::* LISTEN 121393/zabbix_serve
浏览器输入:输入:http://192.168.200.40/zabbix/
[root@localhost web]# chmod -R +x /etc/zabbix/ #赋权
[root@localhost web]# ls
maintenance.inc.php zabbix.conf.php
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存储库与agent代理服务'
--
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'
可以将界面转换成中文界面