zabbix介绍
zabbix是一个开源的监控软件集成了nagos和cat的优势
而且有很多自带的插件可以使用,而且还有api接口供我们使用
zabbix还支持自定义监控项
初始环境
- centos 6.5
zabbix环境搭建:
- 环境初始化
- mysql
- php
- nginx
- zabbix
搭建步骤
1. 环境初始化
1 #!/bin/bash 2 ## filename:init.sh 3 ## 1.安装常用工具 4 yum install -y nano vim lrzsz wget ntpdate 5 ## 更改时区 6 ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 7 ## 或者 8 # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 9 ## 同步服务器 10 ntpdate -u ntp.api.bz 11 # NTP服务器(上海) :ntp.api.bz 12 ## 13 ## 2.安装开发软件包 14 ## 如果没有修改成163的源可以直接安装 如果已经改成了163的源需要执行下面的代码 15 wget http://www.atomicorp.com/installers/atomic 16 sh ./atomic 17 yum -y install libmcrypt libmcrypt-devel 18 rm -rf atomic RPM-GPG-KEY.art.txt RPM-GPG-KEY.atomicorp.txt 19 ## 20 ## 安装开发软件包 21 yum -y groupinstall "Development Tools" 22 yum -y install libxml2* curl curl-devel libjpeg* libpng* freetype-devel 23 24 ## 安装zabbix依赖包yum源 25 wget http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm 26 rpm -ivh zabbix-release-3.2-1.el6.noarch.rpm 27 yum -y install libxml2* snmp* net-snmp* curl* php-mysql 28 rm -rf zabbix-release-3.2-1.el6.noarch.rpm
2. 安装mysql
1 #!/bin/bash 2 ## filename:mysql.sh 3 ## 安装mysql服务 4 yum -y install mysql mysql-server mysql-devel 5 6 ## 启动mysql服务 7 service mysqld restart 8 9 ## 重置mysql密码 10 mysqladmin -u root password 123456 11 12 ## lnmp创建wiki数据库 13 #mysql -uroot -p123456 <<EOF 14 #create database wiki charset utf8; 15 #grant all on wiki.* to wiki@'localhost' identified by 'wiki'; 16 #flush privileges; 17 #EOF 18 19 ## zabbix创建数据库 20 mysql -uroot -p123456 <<EOF 21 create database zabbix character set utf8 collate utf8_bin; 22 grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; 23 flush privileges; 24 EOF
3. 安装php
1 #!/bin/bash 2 ## filename:php.sh 3 ## 安装php 4 wget http://cn2.php.net/distributions/php-5.6.2.tar.gz 5 tar -xvf php-5.6.2.tar.gz 6 cd php-5.6.2 7 8 ## lnmp执行脚本 9 #./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --with-openssl --enable-bcmath --enable-sockets 10 11 ## zabbix执行脚本 12 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --with-openssl --enable-bcmath --enable-sockets --with-mysqli --with-gettext 13 14 ## 安装 15 make && make install 16 17 ## 复制文件 18 cp php.ini-production /usr/local/php/etc/php.ini 19 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 20 cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 21 chmod +x /etc/init.d/php-fpm 22 23 ## 修改配置文件 24 ## 修改/usr/local/php/etc/php-fpm.conf 25 ## user = php-fpm 26 ## group = php-fpm 27 ## 修改为 28 ## user = nginx 29 ## group = nginx 30 31 sed -i 's/user =.*/user = nginx/g' /usr/local/php/etc/php-fpm.conf 32 sed -i 's/group =.*/group = nginx/g' /usr/local/php/etc/php-fpm.conf 33 34 ## 删除文件 35 cd - 36 rm -rf php-5.6.2 php-5.6.2.tar.gz 37 38 ## 启动php(需先更改nginx配置文件才可以启动) 39 #/etc/init.d/php-fpm start
4. 安装nginx
1 #!/bin/bash 2 ## filename:nginx.sh 3 ## 安装nginx 4 yum install -y nginx 5 6 ## 修改配置文件 7 cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak 8 9 echo "user nginx nginx; 10 worker_processes 16; 11 error_log /var/log/nginx_error.log crit; 12 pid /var/run/nginx.pid; 13 worker_rlimit_nofile 65535; 14 events 15 { 16 use epoll; 17 worker_connections 65535; 18 } 19 http 20 { 21 include mime.types; 22 default_type application/octet-stream; 23 server_names_hash_bucket_size 128; 24 client_header_buffer_size 32k; 25 large_client_header_buffers 4 32k; 26 client_max_body_size 8m; 27 sendfile on; 28 tcp_nopush on; 29 keepalive_timeout 60; 30 tcp_nodelay on; 31 fastcgi_connect_timeout 300; 32 fastcgi_send_timeout 300; 33 fastcgi_read_timeout 300; 34 fastcgi_buffer_size 64k; 35 fastcgi_buffers 4 64k; 36 fastcgi_busy_buffers_size 128k; 37 fastcgi_temp_file_write_size 128k; 38 gzip on; 39 gzip_min_length 1k; 40 gzip_buffers 4 16k; 41 gzip_http_version 1.0; 42 gzip_comp_level 2; 43 gzip_types text/plain application/x-javascript text/css application/xml; 44 gzip_vary on; 45 log_format www '$"remote_addr" - $"remote_user" [$"time_local"] "$request" ' 46 '$"status" $"body_bytes_sent" "$http_referer" ' 47 '"$http_user_agent" $"http_x_forwarded_for"'; 48 server 49 { 50 listen 80; 51 server_name vagrant-centos65.vagrantup.com; 52 index start.php index.htm index.html index.php pengyou.php weibo.php qzone.php; 53 root /usr/share/nginx/html; 54 location ~ .*.(php|php5)?$ 55 { 56 fastcgi_pass 127.0.0.1:9000; 57 fastcgi_index start.php; 58 include fastcgi.conf; 59 } 60 location ~ .*.(svn|git|cvs) 61 { 62 deny all; 63 } 64 location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ 65 { 66 expires 30d; 67 } 68 location ~ .*.(js|css)?$ 69 { 70 expires 1h; 71 } 72 } 73 }" > /etc/nginx/nginx.conf 74 75 ## 启动nginx 76 /etc/init.d/nginx start 77 78 ## 测试 79 echo "<?php 80 phpinfo(); 81 ?> 82 " > /usr/share/nginx/html/cc.php
5. 安装zabbix
1 #!/bin/bash 2 ## filename:zabbix.sh 3 ## 下载并解压进入 4 wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.2.6/zabbix-3.2.6.tar.gz 5 tar -zxvf zabbix-3.2.6.tar.gz 6 cd zabbix-3.2.6 7 8 ## 执行脚本(开始配置zabbix(我在这里安装了server和agent)) 9 ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 10 11 ## 安装 12 make install 13 14 ## 添加组账户、用户账户 -g指定新用户的主组 15 groupadd zabbix 16 useradd -g zabbix zabbix 17 18 ## 拷贝导入数据库 19 cd database/mysql/ 20 mysql -uzabbix -p'zabbix' zabbix < schema.sql 21 mysql -uzabbix -p'zabbix' zabbix < images.sql 22 mysql -uzabbix -p'zabbix' zabbix < data.sql 23 cd - 24 25 ## 修改zabbix服务器的mysql配置 26 ## 修改/usr/local/etc/zabbix_server.conf 27 ## DBHost=localhost 28 ## DBName=zabbix 29 ## DBUser=zabbix 30 ## DBPassword=zabbix 31 cp -a /usr/local/etc/zabbix_server.conf /usr/local/etc/zabbix_server.conf.bak 32 sed -i '/# DBHost=.*/aDBHost=localhost' /usr/local/etc/zabbix_server.conf 33 # sed -i '/# DBName=.*/aDBName=zabbix' /usr/local/etc/zabbix_server.conf 34 # sed -i '/# DBUser=.*/aDBName=zabbix' /usr/local/etc/zabbix_server.conf 35 sed -i '/# DBPassword=.*/aDBPassword=zabbix' /usr/local/etc/zabbix_server.conf 36 37 ## 安装完成 启动后端 38 /usr/local/sbin/zabbix_server 39 40 ## 拷贝文件到前端页面 41 cp -rf frontends/php/* /usr/share/nginx/html/ 42 43 ## 修改php配置文件 44 ## 修改 45 ## /usr/local/php/etc/php.ini 46 ## php_value max_execution_time 300 47 ## php_value memory_limit 128M 48 ## php_value post_max_size 16M 49 ## php_value upload_max_filesize 2M 50 ## php_value max_input_time 300 51 ## php_value always_populate_raw_post_data -1 52 ## date.timezone = "Asia/Shanghai" 53 ## 修改脚本: 54 sed -i 's/max_execution_time =.*/max_execution_time = 300/g' /usr/local/php/etc/php.ini 55 ## sed -i 's/memory_limit =.*/memory_limit = 128M/g' /usr/local/php/etc/php.ini 56 sed -i 's/post_max_size =.*/post_max_size = 16M/g' /usr/local/php/etc/php.ini 57 ## sed -i 's/upload_max_filesize =.*/upload_max_filesize = 2M/g' /usr/local/php/etc/php.ini 58 sed -i 's/max_input_time =.*/max_input_time = 300/g' /usr/local/php/etc/php.ini 59 sed -i '/;always_populate_raw_post_data =.*/aalways_populate_raw_post_data = -1' /usr/local/php/etc/php.ini 60 sed -i '/;date.timezone =/adate.timezone = "Asia/Shanghai"' /usr/local/php/etc/php.ini 61 62 ## 更改配置文件后重启php服务 63 /etc/init.d/php-fpm restart 64 65 ## 删除index.html文件 66 rm -rf /usr/share/nginx/html/index.html 67 68 ## 删除zabbix安装包 69 rm -rf zabbix-3.2.6.tar.gz zabbix-3.2.6 70 71 ## 然后从本地浏览器进入虚拟机所在的ip地址进行zabbix的安装 72 73 # Configure DB connection 74 # Database host:127.0.0.1 75 # Database port:3306 76 ## 安装完成后 77 ### Username:Admin 78 ### Password:zabbix
6. 进程启动脚本
1 #!/bin/bash 2 ## filename:init-run.sh 3 ## 启动mysql 4 /etc/init.d/mysqld start 5 # service mysqld start 6 7 ## 启动php 8 /etc/init.d/php-fpm start 9 # service php-fpm start 10 11 ## 启动nginx 12 /etc/init.d/nginx start 13 # service nginx start 14 15 ## 启动zabbix 16 /usr/local/sbin/zabbix_server 17 /usr/local/sbin/zabbix_agentd