LNMP+zabbix服务搭建
环境部署
服务端:192.168.35.100
客户端:192.168.35.101
服务端安装配置
关闭防火墙
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# 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.
[[email protected] ~]# setenforce 0
一、LNMP安装环境
1、安装nginx1.16
(1)从官网上下载
[[email protected] ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
--2020-01-31 13:19:13-- http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
正在解析主机 nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
正在连接 nginx.org (nginx.org)|62.210.92.35|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:4680 (4.6K) [application/x-redhat-package-manager]
正在保存至: “nginx-release-centos-7-0.el7.ngx.noarch.rpm”100%[====================================>] 4,680 1.29KB/s 用时 3.5s
2020-01-31 13:19:17 (1.29 KB/s) - 已保存 “nginx-release-centos-7-0.el7.ngx.noarch.rpm” [4680/4680])
(2)手动创建nginx yum安装源
[[email protected] ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
(3)重新加载
[[email protected] ~]# yum list
(4)安装nginx
[[email protected] ~]# yum install nginx -y
(5)开启服务
[[email protected] ~]# systemctl start nginx
[[email protected] ~]# netstat -ntap | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 108485/nginx: maste
[[email protected] ~]# systemctl enable nginx #设为开机自启动
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
(6)打开网页访问下
2、安装mysql 5.7
(1)安装服务
[[email protected] ~]# yum install -y mariadb-server mariadb
(2)开启服务
[[email protected] ~]# systemctl start mariadb.service
[[email protected] ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
(3)进行设置
[[email protected] ~]# 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!
//验证密码已经设置好无误
[[email protected] ~]# 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 ServerCopyright (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
3、安装PHP
(1)安装PHP源
[[email protected] ~]# 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%]
(2)yum仓库的生成
[[email protected] ~]# 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%]
(3)安装软件包
[[email protected] ~]# yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql
(4)查看PHP版本
[[email protected] ~]# php -v
PHP 7.2.27 (cli) (built: Jan 26 2020 15:49:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
4、配置nginx支持php
(1)修改php-fpm配置文件,把apache改为nginx
[[email protected] ~]# vim /etc/php-fpm.d/www.conf
//8 user = nginx
//10 group = nginx
(2)配置location,在index中添加index.php。以支持index.php的首页
[[email protected] ~]# 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;
}
5、配置php
(1)修改PHP配置文件
[[email protected] ~]# 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服务
[[email protected] ~]# systemctl start php-fpm.service
[[email protected] ~]# 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.
[[email protected] ~]# netstat -ntap | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 86082/php-fpm: mast[[email protected] html]# systemctl restart nginx
6、测试首页
(1)写一个简单的测试首页
[[email protected] ~]# vim /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
(2)打开浏览器访问:http://192.168.35.100/info.php
7、测试连接数据库
(1)测试页
[[email protected] ~]# vim /usr/share/nginx/html/info.php
<?php
$link=mysqli_connect('127.0.0.1','root','abc123');
if ($link) echo "true !!!";
else echo "false !!!";
?>注:mysql_connect扩展自 PHP 5.5.0 起已废弃,改用mysqli或pdo_mysql
(2)在浏览器刷新:
8、安装zabbix前提
(1)准备zabbix数据库
[[email protected] html]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.64-MariaDB MariaDB ServerCopyright (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)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> GRANT all privileges ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> \q
Bye
(2)检查用户能否登录数据库
[[email protected] html]# mysql -u zabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES) #显示不能
(3)解决办法
[[email protected] 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 ServerCopyright (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
(4)在进行登录就可以了
[[email protected] html]# mysql -u zabbix -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.64-MariaDB MariaDB ServerCopyright (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
二、部署zabbix Server
zabbix 官网 https://www.zabbix.com/download
1、安装yum源
[[email protected] ~]# 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.g3WDdJ: 头V4 RSA/SHA512 Signature, ** ID a14fe591: NOKEY
2、安装相关环境包
[[email protected] ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
3、修改配置文件
[[email protected] ~]# grep -n '^'[a-Z] /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
4、修正图表中文乱码
[[email protected] ~]# vim /usr/share/zabbix/include/defines.inc.php
:%s /graphfont/kaiti/g
5、从微软系统下复制相应的字体文件到 /usr/share/zabbix/fonts 目录中注意字体名称要对应配置文件,且注意大小写
[[email protected] zabbix]# cp STKAITI.TTF /usr/share/zabbix/fonts
6、赋予权限
[[email protected] zabbix]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/
[[email protected] zabbix]# chown -R zabbix:zabbix /etc/zabbix/
[[email protected] zabbix]# chown -R zabbix:zabbix /usr/share/nginx/
[[email protected] zabbix]# chown -R zabbix:zabbix /usr/lib/zabbix/
[[email protected] zabbix]# chmod -R 755 /etc/zabbix/web/
[[email protected] zabbix]# chmod -R 777 /var/lib/php/session/
7、生成数据库文件,注意密码不要输成root的
[[email protected] zabbix]# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
Enter password: #密码admin23//查看文件是否存在
[[email protected] zabbix]# mysql -uzabbix -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 5.5.64-MariaDB MariaDB ServerCopyright (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)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_suppress |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| item_preproc |
| items |
| items_applications |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_remote_command |
| task_remote_command_result |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
144 rows in set (0.00 sec)MariaDB [zabbix]> \q
Bye
8、修改时区
[[email protected] zabbix]# vim /etc/httpd/conf.d/zabbix.conf
//20 php_value date.timezone Asia/Shanghai
9、启动服务
[[email protected] zabbix]# systemctl start zabbix-server.service
[[email protected] zabbix]# systemctl enable zabbix-server.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
[[email protected] zabbix]# systemctl start zabbix-agent.service
[[email protected] zabbix]# systemctl enable zabbix-agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
[[email protected] 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
10、安装后登录 用户名Admin 密码:zabbix
输入:http://192.168.35.100/zabbix/
此步骤会报错,显示无法创建文件的问题:
解决办法:在页面安装过程中遇到无法创建的问题根据提示的连接地址下载配置文件zabbix.conf.php
拷贝并赋予权限:
[[email protected] zabbix]# ls
php-bcmath-5.4.16-42.el7.x86_64.rpm STKAITI.TTF
php-mbstring-5.4.16-42.el7.x86_64.rpm zabbix.conf.php
[[email protected] zabbix]# cp zabbix.conf.php /etc/zabbix/web/
[[email protected] zabbix]# chown zabbix.zabbix /etc/zabbix/web/zabbix.conf.php
然后再点击就安装好了,输入用户名及密码就可以进行登录