作者:邓聪聪
为了工作之需要,在系统服务方面不断的摸爬打滚,有了这样点点滴滴的经验,留后在使用! 插件网盘取。
链接: https://pan.baidu.com/s/1i5u0ed3 密码: rx52
1:安装依赖包--(安装LNMP环境)
1 yum -y install lrzsz ntp gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel cmake gcc* ncurses-devel
2: 上传源码安装包nginx、mysql(我这里用yum源的安装方式来安装这两个软件)
zabbix的各版本下载:https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/
1 yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm 2 yum -y install mysql-server mysql-devel net-snmp-devel nginx
3:源码编译安装PHP
1 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local/php --with-png-dir=/usr/local/php --with-freetype-dir=/usr/local/php --enable-gd-native-ttf --with-iconv-dir=/usr/local/php --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local/php --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath 2 make -j4 && make install
#在php的安装包文件内拷贝-到安装的php的etc目录中
1 cp php.ini-production /usr/local/php/etc/php.ini
#需要修改的参数
1 /usr/local/php/etc/php.ini 2 max_execution_time = 300 3 post_max_size = 16M 4 max_input_time = 300 5 date.timezone = PRC
#/usr/local/php/etc的路径下(原有的是纯默认文件,创建一个修改配置文件)
1 cp php-fpm.conf.default php-fpm.conf
4:安装zabbix
1 tar -zxvf zabbix-3.0.4.tar.gz 2 cd zabbix-3.0.4 3 ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 4 make -j4 && make install
#创建zabbix用户
1 useradd zabbix -s /sbin/nologin
5:#导入sql文件,在/usr/local/src/zabbix-3.2.4下。#zabbix安装包下data的将数据重定向给数据库中的zabbix
1 mysql -u<mysql用户> -p<mysql密码> zabbix < database/mysql/schema.sql 2 mysql -u<mysql用户> -p<mysql密码> zabbix < database/mysql/images.sql 3 mysql -u<mysql用户> -p<mysql密码> zabbix < database/mysql/data.sql
6: #进入数据库查看表项
1 mysql 2 mysql> create database zabbix default charset utf8; #创建zabbix 的库 3 mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix'; #给zabbix库赋权限 4 mysql> flush privileges; #刷新表权限 5 mysql> show databases; #查看表结构
7:#创建WEB管理目录
1 mkdir -p /data/zabbix/web #为了方便管理创建管理库 2 mkdir -p /data/zabbix/log #为了方便管理创建管理库 3 mkdir -pv /usr/local/nginx/conf/zabbix #为了方便管理创建管理库
8:#把目录的文件取出
1 cp -rp /usr/local/src/zabbix/zabbix-3.2.4/frontends/php/* /data/zabbix/web/ 2 cp /usr/local/src/zabbix/zabbix-3.2.4/misc/init.d/tru64/zabbix_* /etc/init.d/
9:#编辑WEB访问的nginx下的配置文件
1 cd /usr/local/nginx/conf/zabbix/ 2 vim zabbix.conf 3 server { 4 listen 80; 5 server_name web; 6 access_log /data/zabbix/log/zabbix.access.log main; 7 index index.html index.php index.html; 8 root /data/zabbix/web; 9 location /{ 10 try_files $uri $uri/ /index.php?$args; 11 } 12 location ~ ^(.+.php)(.*)$ { 13 fastcgi_split_path_info ^(.+.php)(.*)$; 14 include fastcgi.conf; 15 fastcgi_pass 127.0.0.1:9000; 16 fastcgi_index index.php; 17 fastcgi_param PATH_INFO $fastcgi_path_info; 18 } 19 }
10:#编辑nginx的配置文件
1 user nginx; 2 worker_processes 1; 3 #error_log logs/error.log warning; 4 #error_log logs/error.log notice; 5 #error_log logs/error.log info; 6 pid logs/nginx.pid; 7 events { 8 worker_connections 1024; 9 } 10 http { 11 include mime.types; 12 default_type application/octet-stream; 13 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 14 '$status $body_bytes_sent "$http_referer" ' 15 '"$http_user_agent" "$http_x_forwarded_for"'; 16 access_log logs/access.log main; 17 sendfile on; 18 #tcp_nopush on; 19 20 #keepalive_timeout 0; 21 keepalive_timeout 65; 22 23 #gzip on; 24 include zabbix/*.conf; 25 }
11:#启动服务项的进程,检查端口,检查防火墙策略等
1 /usr/local/src/zabbix/sbin/zabbix_agentd 2 /usr/local/src/zabbix/sbin/zabbix_server 3 /etc/init.d/nginx start 4 /usr/local/php/sbin 5 ./php-fpm 6 /etc/init.d/mysqld start 7 netstat -tunlp 8 iptables -vnL --line
12:#设置企业微信告警在/usr/local/zabbix/share/zabbix/alertscripts下创建一个shell脚本的配置文
find / -name alertscripts ==> /usr/lib/zabbix/alertscripts #脚本所在路径
1 [root@bogon alertscripts]# cat weixin 2 #!/bin/bash 3 PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin 4 ###SCRIPT_NAME:weixin.sh### 5 ###send message from weixin for zabbix monitor### 6 7 CropID='wwf15e7a8a0c2ee0e7' 8 Secret='hoZb2VoBXEmAnLL1_ZAXmTRfVrDaOpiIEpQN6BP1KIM' 9 GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret" 10 Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F'access_token\":\"' '{print $2}' | awk -F'"' '{print $1}') 11 12 PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken" 13 14 function body() { 15 local int AppID=1000002 16 local UserID=$1 17 local PartyID=1 18 local Msg=$(echo "$@" | cut -d" " -f3-) 19 printf '{\n' 20 printf '\t"touser": "'"$UserID"\"",\n" 21 printf '\t"toparty": "'"$PartyID"\"",\n" 22 printf '\t"msgtype": "text",\n' 23 printf '\t"agentid": "'" $AppID "\"",\n" 24 printf '\t"text": {\n' 25 printf '\t\t"content": "'"$Msg"\""\n" 26 printf '\t},\n' 27 printf '\t"safe":"0"\n' 28 printf '}\n' 29 } 30 /usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL
#测试脚本的可用性
1 bash -x ./weixin test4
web端微信告警设置:
13:如果配置了公网地址就建议打开防火墙 iptables
1 iptables -I INPUT s 192.168.2.3 -J ACCEPT 2 iptables -A INPUT -s (IP地址/掩码) -p tcp -m tcp --dport 80 -j ACCEPT 3 iptables -A INPUT -p tcp -m tcp -j DROP
=====后面的都是zabbix的web端口设置的问题了=====
*************** <当你发现自己的才华撑不起自己的野心时,请静下心来学习吧!!!> ***************