设为首页 收藏本站
查看: 991|回复: 0

[经验分享] Zabbix二:在nginx上搭建

[复制链接]

尚未签到

发表于 2019-1-21 11:32:30 | 显示全部楼层 |阅读模式
  介绍就不再次介绍了。目前很多公司都在nginx上搭建服务了,所以我又搭建了一个LNMP+Zabbix,具体步骤如下
  -----------LNMP+Zabbix----------------------------
##两台服务器防火墙关闭
[root@cacti ~]# systemctl stop firewalld.service
[root@cacti ~]# 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@cacti ~]# setenforce 0
  ===========LNMP安装环境(安装nginx1.14)========
##手动配置yum仓库
[root@cacti ~]# vim /etc/yum.repos.d/nginx.repo
  [nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
  -------------------安装nginx------------------
[root@cacti ~]# yum list
[root@cacti ~]# yum install nginx -y
[root@cacti ~]# systemctl start nginx
[root@cacti ~]# netstat -ntap | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      45100/nginx: master
[root@cacti ~]# systemctl enable nginx
  ------------------安装mariadb-----------------
[root@cacti ~]# yum install mariadb-server mariadb -y
[root@cacti ~]# systemctl start mariadb.service
[root@cacti ~]# systemctl enable mariadb.service
##设置数据库
[root@cacti ~]# mysql_secure_installation
回车
y
abc123          ##密码自己定义
abc123
n
n
n
y
  ##登录数据库
[root@cacti ~]# mysql -uroot -p
Enter password:             ##输入密码
MariaDB [(none)]>
  -----------------安装php7.2------------------------
#安装epel源
[root@cacti ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
##或者
[root@cacti ~]# yum install epel-release -y
[root@cacti ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  [root@cacti ~]# yum install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql -y
[root@cacti ~]# php -v
PHP 7.2.10 (cli) (built: Sep 15 2018 07:10:58) ( NTS )
  [root@cacti ~]# vim /etc/php-fpm.d/www.conf
user = nginx            ##8行
group = nginx           ##10行
  [root@cacti ~]# vim /etc/php.ini
expose_php = Off            ##359行(隐藏php版本)
short_open_tag = On     ##202行(支持php短标签)
  ##以下为Zabbix配置要求
max_execution_time = 300            ##368行(执行时间)
max_input_time = 300            ##378行(接收数据等待时间)
memory_limit = 128M         ##389行(每个脚本占用内存)
post_max_size = 16M         ##656行(POST数据大小)
upload_max_filesize = 2M            ##799行(下载文件大小)
always_populate_raw_post_data = -1      ##800行
date.timezone = Asia/Shanghai       ##877行(时区)
  [root@cacti ~]# vim /etc/nginx/conf.d/default.conf
index  index.php index.html index.htm;      ##10行
location ~ .php$ {             ##30-36行(去掉注释)
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; #修改用户root
include        fastcgi_params;
}
  ##启动服务
[root@cacti ~]# systemctl start php-fpm.service
[root@cacti ~]# 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@cacti ~]# netstat -ntap | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      3250/php-fpm: maste
[root@cacti ~]# systemctl restart nginx

##测试
[root@cacti ~]# cd /usr/share/nginx/html/
[root@cacti html]# ls
50x.html  index.html
[root@cacti html]# vim info.php
  
  http://192.168.120.183/info.php
##测试连接数据库



[root@cacti html]# mysql -uroot -p
Enter password:
MariaDB [(none)]> CREATE DATABASE zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.02 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)
  [root@cacti html]# mysql -uzabbix -p
Enter password:
MariaDB [(none)]>
  ##如果zabbix用户登录失败,参考以下方法
-------------解决本地无法登录问题(可忽略)---------------------------
[root@cacti html]# mysql -uzabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
##出错##
##解决方案:
##进入root用户数据库
[root@cacti html]# mysql -uroot -p
  MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | cacti     |
| root   | cacti     |
|        | localhost |
| root   | localhost |
+--------+-----------+
##出现空用户,删除空用户
MariaDB [(none)]> drop user ''@localhost;
Query OK, 0 rows affected (0.02 sec)
  MariaDB [(none)]> drop user ''@cacti;
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   | cacti     |
| root   | localhost |
+--------+-----------+
##空用户已删除
  [root@cacti html]# mysql -uzabbix -p
Enter password:
MariaDB [(none)]>
##登录成功
  ----------------以下开始部署zabbix Server-------
[root@cacti ~]# 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.hVq9av: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
[root@cacti ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
[root@cacti ~]#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         ##去掉注释
101:DBName=zabbix
117:DBUser=zabbix
125:DBPassword=admin123         ##修改
357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
475:Timeout=4
518:AlertScriptsPath=/usr/lib/zabbix/alertscripts
529:ExternalScripts=/usr/lib/zabbix/externalscripts
565:LogSlowQueries=3000
  [root@cacti ~]# mkdir /abc
[root@cacti ~]# mount.cifs //192.168.100.10/rhel7 /abc
Password for root@//192.168.100.10/rhel7:  
[root@cacti ~]# cd /abc/zabbix/
[root@cacti zabbix]# ls
php-bcmath-5.4.16-42.el7.x86_64.rpm  php-mbstring-5.4.16-42.el7.x86_64.rpm  STKAITI.TTF
  [root@cacti zabbix]# vim /usr/share/zabbix/include/defines.inc.php
##shift:输入
:%s /graphfont/kaiti/g
[root@cacti zabbix]# cp STKAITI.TTF /usr/share/zabbix/fonts/
[root@cacti ~]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/
[root@cacti html]# chown -R zabbix:zabbix /etc/zabbix/
[root@cacti html]# chown -R zabbix:zabbix /usr/share/nginx/
[root@cacti html]# chown -R zabbix:zabbix /usr/lib/zabbix/
[root@cacti html]# chmod -R 755 /etc/zabbix/web/
[root@cacti html]# chmod -R 777 /var/lib/php/session/
[root@cacti html]# zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix
Enter password:                     ##密码为之前设置的admin123(zabbix登录密码)
##启动服务
[root@cacti ~]# systemctl start zabbix-server.service
[root@cacti ~]# systemctl start zabbix-agent.service
[root@cacti ~]# netstat -anpt | grep zabbix
tcp        0      0 0.0.0.0:10050           0.0.0.0:
               LISTEN      2789/zabbix_agentd  
tcp6       0      0 :::10050                :::*                    LISTEN      2789/zabbix_agentd
[root@cacti ~]# systemctl stop php-fpm.service
[root@cacti ~]# systemctl stop nginx
[root@cacti ~]# systemctl start php-fpm.service
[root@cacti ~]# systemctl start nginx
[root@cacti ~]# systemctl restart zabbix-server.service
##访问
http://192.168.120.183/zabbix/setup.php
网页访问步骤和之前在LAMP上一样




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-665965-1-1.html 上篇帖子: zabbix2.4.6 源码包安装 下篇帖子: 【Zabbix】通过iLO进行Zabbix监控——针对HP服务器集成
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表