zabbix环境搭建

zabbix介绍
zabbix是一个开源的监控软件集成了nagos和cat的优势
而且有很多自带的插件可以使用,而且还有api接口供我们使用
zabbix还支持自定义监控项

初始环境
- centos 6.5

zabbix环境搭建:
- 环境初始化
- mysql
- php
- nginx
- zabbix

搭建步骤
1. 环境初始化

 #!/bin/bash
## filename:init.sh
## .安装常用工具
yum install -y nano vim lrzsz wget ntpdate
## 更改时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
## 或者
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
## 同步服务器
ntpdate -u ntp.api.bz
# NTP服务器(上海) :ntp.api.bz
##
## .安装开发软件包
## 如果没有修改成163的源可以直接安装 如果已经改成了163的源需要执行下面的代码
wget http://www.atomicorp.com/installers/atomic
sh ./atomic
yum -y install libmcrypt libmcrypt-devel
rm -rf atomic RPM-GPG-KEY.art.txt RPM-GPG-KEY.atomicorp.txt
##
## 安装开发软件包
yum -y groupinstall "Development Tools"
yum -y install libxml2* curl curl-devel libjpeg* libpng* freetype-devel ## 安装zabbix依赖包yum源
wget http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
rpm -ivh zabbix-release-3.2-.el6.noarch.rpm
yum -y install libxml2* snmp* net-snmp* curl* php-mysql
rm -rf zabbix-release-3.2-.el6.noarch.rpm

2. 安装mysql

 #!/bin/bash
## filename:mysql.sh
## 安装mysql服务
yum -y install mysql mysql-server mysql-devel ## 启动mysql服务
service mysqld restart ## 重置mysql密码
mysqladmin -u root password ## lnmp创建wiki数据库
#mysql -uroot -p123456 <<EOF
#create database wiki charset utf8;
#grant all on wiki.* to wiki@'localhost' identified by 'wiki';
#flush privileges;
#EOF ## zabbix创建数据库
mysql -uroot -p123456 <<EOF
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
flush privileges;
EOF

3. 安装php

 #!/bin/bash
## filename:php.sh
## 安装php
wget http://cn2.php.net/distributions/php-5.6.2.tar.gz
tar -xvf php-5.6..tar.gz
cd php-5.6. ## lnmp执行脚本
#./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 ## zabbix执行脚本
./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 ## 安装
make && make install ## 复制文件
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm ## 修改配置文件
## 修改/usr/local/php/etc/php-fpm.conf
## user = php-fpm
## group = php-fpm
## 修改为
## user = nginx
## group = nginx sed -i 's/user =.*/user = nginx/g' /usr/local/php/etc/php-fpm.conf
sed -i 's/group =.*/group = nginx/g' /usr/local/php/etc/php-fpm.conf ## 删除文件
cd -
rm -rf php-5.6. php-5.6..tar.gz ## 启动php(需先更改nginx配置文件才可以启动)
#/etc/init.d/php-fpm start

4. 安装nginx

 #!/bin/bash
## filename:nginx.sh
## 安装nginx
yum install -y nginx ## 修改配置文件
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak echo "user nginx nginx;
worker_processes ;
error_log /var/log/nginx_error.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile ;
events
{
use epoll;
worker_connections ;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size ;
client_header_buffer_size 32k;
large_client_header_buffers 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout ;
tcp_nodelay on;
fastcgi_connect_timeout ;
fastcgi_send_timeout ;
fastcgi_read_timeout ;
fastcgi_buffer_size 64k;
fastcgi_buffers 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_http_version 1.0;
gzip_comp_level ;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
log_format www '$"remote_addr" - $"remote_user" [$"time_local"] \"\$request\" '
'$"status" $"body_bytes_sent" \"\$http_referer\" '
'\"\$http_user_agent\" $"http_x_forwarded_for"';
server
{
listen ;
server_name vagrant-centos65.vagrantup.com;
index start.php index.htm index.html index.php pengyou.php weibo.php qzone.php;
root /usr/share/nginx/html;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:;
fastcgi_index start.php;
include fastcgi.conf;
}
location ~ .*.(svn|git|cvs)
{
deny all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
}
}" > /etc/nginx/nginx.conf ## 启动nginx
/etc/init.d/nginx start ## 测试
echo "<?php
phpinfo();
?>
" > /usr/share/nginx/html/cc.php

5. 安装zabbix

 #!/bin/bash
## filename:zabbix.sh
## 下载并解压进入
wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.2.6/zabbix-3.2.6.tar.gz
tar -zxvf zabbix-3.2..tar.gz
cd zabbix-3.2. ## 执行脚本(开始配置zabbix(我在这里安装了server和agent))
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 ## 安装
make install ## 添加组账户、用户账户 -g指定新用户的主组
groupadd zabbix
useradd -g zabbix zabbix ## 拷贝导入数据库
cd database/mysql/
mysql -uzabbix -p'zabbix' zabbix < schema.sql
mysql -uzabbix -p'zabbix' zabbix < images.sql
mysql -uzabbix -p'zabbix' zabbix < data.sql
cd - ## 修改zabbix服务器的mysql配置
## 修改/usr/local/etc/zabbix_server.conf
## DBHost=localhost
## DBName=zabbix
## DBUser=zabbix
## DBPassword=zabbix
cp -a /usr/local/etc/zabbix_server.conf /usr/local/etc/zabbix_server.conf.bak
sed -i '/# DBHost=.*/a\DBHost=localhost' /usr/local/etc/zabbix_server.conf
# sed -i '/# DBName=.*/a\DBName=zabbix' /usr/local/etc/zabbix_server.conf
# sed -i '/# DBUser=.*/a\DBName=zabbix' /usr/local/etc/zabbix_server.conf
sed -i '/# DBPassword=.*/a\DBPassword=zabbix' /usr/local/etc/zabbix_server.conf ## 安装完成 启动后端
/usr/local/sbin/zabbix_server ## 拷贝文件到前端页面
cp -rf frontends/php/* /usr/share/nginx/html/ ## 修改php配置文件
## 修改
## /usr/local/php/etc/php.ini
## php_value max_execution_time 300
## php_value memory_limit 128M
## php_value post_max_size 16M
## php_value upload_max_filesize 2M
## php_value max_input_time 300
## php_value always_populate_raw_post_data -1
## date.timezone = "Asia/Shanghai"
## 修改脚本:
sed -i 's/max_execution_time =.*/max_execution_time = /g' /usr/local/php/etc/php.ini
## sed -i 's/memory_limit =.*/memory_limit = 128M/g' /usr/local/php/etc/php.ini
sed -i 's/post_max_size =.*/post_max_size = 16M/g' /usr/local/php/etc/php.ini
## sed -i 's/upload_max_filesize =.*/upload_max_filesize = 2M/g' /usr/local/php/etc/php.ini
sed -i 's/max_input_time =.*/max_input_time = 300/g' /usr/local/php/etc/php.ini
sed -i '/;always_populate_raw_post_data =.*/a\always_populate_raw_post_data = -1' /usr/local/php/etc/php.ini
sed -i '/;date.timezone =/a\date.timezone = "Asia/Shanghai"' /usr/local/php/etc/php.ini ## 更改配置文件后重启php服务
/etc/init.d/php-fpm restart ## 删除index.html文件
rm -rf /usr/share/nginx/html/index.html ## 删除zabbix安装包
rm -rf zabbix-3.2..tar.gz zabbix-3.2. ## 然后从本地浏览器进入虚拟机所在的ip地址进行zabbix的安装 # Configure DB connection
# Database host:127.0.0.1
# Database port:
## 安装完成后
### Username:Admin
### Password:zabbix

6. 进程启动脚本

 #!/bin/bash
## filename:init-run.sh
## 启动mysql
/etc/init.d/mysqld start
# service mysqld start ## 启动php
/etc/init.d/php-fpm start
# service php-fpm start ## 启动nginx
/etc/init.d/nginx start
# service nginx start ## 启动zabbix
/usr/local/sbin/zabbix_server
/usr/local/sbin/zabbix_agentd
上一篇:Ant学习总结5(配合Ant视频8,9)


下一篇:C#三大支柱之继承