一.准备工作
yum -y install net-snmp-devel php-bcmath php-ctype php-xml php-xmlreader php-xmlwriter php-session php-net-socket php-mbsting php-gettext php-ldap #依赖关系
1.创建zabbix用户
groupadd zabbix useradd -g zabbix -M -s /sbin/nologin zabbix
2.调整服务器时间
监控端和被监控端的时间应同步
yum install -y rdate rdate -s time-b.nist.gov
yum install ntp.x86_64 -y ntpdate cn.pool.ntp.org clock -w
以上时间同步方法二选一
二.zabbix server安装
1.安装
wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.2.7/zabbix-3.2.7.tar.gz/download -P /download wget https://www.zabbix.com/downloads/3.2.0/zabbix_agents_3.2.0.linux2_6.amd64.tar.gz -P /download cd /download tar -zxvf zabbix-3.2.7.tar.gz cd zabbix-3.2.7 ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java make && make install
2.创建zabbix数据库
mysql -uroot -p123456 -hlocalhost create user 'zabbix'@'localhost' identified by 'aixocm'; create database zabbix character set utf8; grant all on zabbix.* to zabbix@'%' identified by 'aixocm'; flush privileges;
3.顺序导入zabbix数据
cd /download/zabbix-3.2.7 mysql -uroot -paixocm -h localhost zabbix <database/mysql/schema.sql mysql -uroot -paixocm -h localhost zabbix <database/mysql/images.sql mysql -uroot -paixocm -h localhost zabbix <database/mysql/data.sql
4.修改php.ini
vi /usr/local/php/etc/php.ini
zabbix要求php下列参数为以下值
post_max_size 16M max_execution_time 300 max_input_time = 300 date.timezone = Asia/Shanghai always_populate_raw_post_data = -1
5.拷贝zabbix前端文件至nginx站点目录
cp -rf /download/zabbix-3.2.7/frontends/php/ /www/ mv /www/php /www/zabbix
6.修改nginx配置nginx.conf
vi /usr/local/nginx/conf/nginx.conf
user deamon; worker_processes 8; #指定了要开启的进程数,每进程占用10M~12M的内存,建议和CPU的核心数量一样多的进程就行了。 error_log /var/log/nginx/error.log warn; pid /var/run/nginx/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. #events 用来指定Nginx工作模式以及连接数上限 events { use epoll; #使用epoll高效模式,适用于Linux,Unix使用kqueue worker_connections 100000; #定义Ningx没个进程最大的连接数。默认为1024,受到文件句柄的约束。 } worker_rlimit_nofile 100000; #打开的文件句柄数量最高为10万 http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; server_names_hash_bucket_size 128; client_header_buffer_size 32k; #客户端请求头部的缓冲区大小,一般一个请求头的大小不会超过1k large_client_header_buffers 4 32k; #客户请求头缓冲大小 nginx默认会用client_header_buffer_size这个buffer来读取header值 client_max_body_size 8m; #设定通过nginx上传文件的大小 gzip on; #该指令用于开启或关闭gzip模块(on/off) gzip_min_length 1k; #设置允许压缩的页面最小字节数,页面字节数从header头得content-length中进行获取 gzip_buffers 4 16k; #设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流 gzip_http_version 1.0; #识别http的协议版本 gzip_comp_level 2; #gzip压缩比,1压缩比最小处理速度最快 #匹配mime类型进行压缩,无论是否指定,”text/html”类型总是会被压缩的 gzip_types text/plain application/x-javascript text/css application/xml text/javascript; gzip_vary on; #和http头有关系,加个vary头,给代理服务器用的 charset utf-8; #字符集为utf-8 access_log off; # 日常日志关闭 log_not_found off; # 日常日志关闭 #fastcgi_temp_path /etc/nginx/tmp; #fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m; #fastcgi_cache_key " request_method request_uri"; fastcgi_connect_timeout 300; #指定连接到后端FastCGI的超时时间。 fastcgi_send_timeout 300; #向FastCGI传送请求的超时时间,这个值是指已经完成两次握手后向FastCGI传送请求的超时时间。 fastcgi_read_timeout 300; #接收FastCGI应答的超时时间,这个值是指已经完成两次握手后接收FastCGI应答的超时时间。 fastcgi_buffer_size 254k; #指定读取FastCGI应答第一部分需要用多大的缓冲区 fastcgi_buffers 16 256k; #指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答。 fastcgi_busy_buffers_size 512k; #这个指令我也不知道是做什么用,只知道默认值是fastcgi_buffers的两倍。 fastcgi_temp_file_write_size 512k; #在写入fastcgi_temp_path时将用多大的数据块,默认值是fastcgi_buffers的两倍。 server { listen 80 ; #监听端口号 #域名为 server_name localhost; # 指定网站的目录 root /www/; # localtion模块指定网站首页名称 location / { index index.php index.html index.htm; if (!-e $request_filename) { return 444; } } location ~ \.php$ { root /www; #fastcgi_cache MYAPP; #fastcgi_cache_valid 200 60m; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; fastcgi_cache_valid 200 60m; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /zabbix{ alias /www/zabbix; } #指定对网页图片格式进行缓存max表示10年,也可以是30d(天) location ~ \.(swf|js|css|xml|gif|jpg|jpeg|png|bmp)$ { error_log off; access_log off; #expires 30d; expires max; } } }