zabbix安装(Ubuntu)
Posted 好好学习啊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix安装(Ubuntu)相关的知识,希望对你有一定的参考价值。
zabbix的安装
- Zabbix监控架构至少需要server,agent,web模块。mysql、web部分和server安装在同一台机器上。
- Zabbix安装前服务器要做时间同步(ntp)
1.创建用户和用户组(Zabbix默认使用Zabbix用户)
groupadd zabbix
adduser zabbix
adduser zabbix zabbix
1. 安装依赖
- 在安装过程中可能会缺少依赖,慢慢安装吧!有点keng。
sudo apt-get install libxml2-dev sudo apt-get install libxml2 sudo apt-get install make sudo apt-get install zlib1g.dev sudo apt-get install zlib1g sudo apt-get install libcurl4-openssl-dev sudo apt-get install libjpeg-dev sudo apt-get install libpng-dev
- 发生这个错误,缺少BZip2
解决办法:下载 bzip2-1.0.6.tar.gz
make && sudo make install
2. 安装php
#安装编译套件 sudo apt-get install build-essential #安装php前端需要的包 sudo apt-get install libmysqlclient15-dev php5-gd php5-mysql libfreetype6-dev #安装zabbix需要的包,snmp\curl\ssl\fping sudo apt-get install snmp libsnmp-dev snmpd libcurl4-openssl-dev fping sudo apt-get install php5-fpm
- 下载PHP
wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror
- 安装编译
mv mirror php-5.5.35.tar.gz && tar xvf php-5.5.35.tar.gz && cd php-5.5.35 ./configure --prefix=/usr/local/product/php-5.5.35 --with-config-file-path=/usr/local/product/php-5.5.35/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath make && make install ln -s /usr/local/product/php-5.5.35 /usr/local/php cp php.ini-production /usr/local/php/etc/php.ini cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf
- 修改PHP参数,可以使用find命令查看
find / -name php.ini -print
sudo vim /etc/php5/cgi/php.ini
- 做以下修改
sudo vim /etc/php5/apache2/php.ini修改项: post_max_size = 16M max_execution_time = 300 max_input_time = 300 date.timezone = "Asia/Shanghai"
3.MySQL部分
mysql> use mysql; mysql>create database zabbix character set utf8; mysql>grant all privileges on zabbix.* to [email protected]‘%‘ identified by ‘zabbix‘; mysql>flush privileges;
- 导入数据库表
cd zabbix-3.2.6/database/mysql mysql -uroot -proot zabbix < schema.sql mysql -uroot -proot zabbix < images.sql mysql -uroot -proot zabbix < data.sql
4.编译安装zabbix
4.1下载安装Zabbix
网址:
tar -xvzf zabbix-3.2.6.tar.gz cd zabbix-3.2.6/ sudo ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-proxy --with-mysql --with-net-snmp --with-libcurl --enable-java make -j4 make install
执行完上述命令,zabbix就安装成功了,位置在/usr/local/zabbix,并且–enable-server和–enable-agent是同时开启server和agent,并且后面的参数对于server来说都要加上
- 修改配置server文件
mkdir -p /etc/zabbix cp -r zabbix-3.2.6/conf/* /etc/zabbix/ chown -R zabbix:zabbix /etc/zabbix vim /etc/zabbix/zabbix_server.conf
- 做以下修改
LogFile=/tmp/zabbix_server.log PidFile=/tmp/zabbix_server.pid DBName=zabbix DBUser=zabbix DBPassword=zabbix DBPort=3306
进入zabbix的安装目录下,sbin/zabbix_server启功server,关闭用kill
vim /etc/zabbix/zabbix_agentd.conf
- 设置zabbix开机启动
sudo cp misc/init.d/debian/zabbix-server /etc/init.d sudo cp misc/init.d/debian/zabbix-agent /etc/init.d cd !$ sudo chmod 755 zabbix-* sudo update-rc.d zabbix-server defaults sudo update-rc.d zabbix-agent defaults
- 做以下修改
Server=127.0.0.1 #允许server获取数据(改成serverIP) ServerActive=127.0.0.1 #主动给server推送数据(改成serverIP) Hostname=Zabbix server
4.2 agent安装
- 只安装agent
tar -xvzf zabbix-3.2.6.tar.gz cd zabbix-3.2.6/ ./configure --prefix=/opt/zabbix --enable-agent make make install groupadd zabbix # sudo adduser zabbix useradd -g zabbix zabbix #sudo gpasswd -a zabbix zabbix mkdir -p /etc/zabbix cp -r zabbix-3.2.6/conf/* /etc/zabbix/ chown -R zabbix:zabbix /etc/zabbix vim /etc/zabbix/zabbix_agent.conf Server=192.168.0.157 ServerActive=192.168.0.157 Hostname=bigdata2(起一个唯一的名字)
5.nginx(web配置)
- 归置一下zabbix的web服务,以便nginx访问
sudo mkdir /usr/share/nginx/html/zabbix/ cd zabbix-3.2.6/frontends/ sudo cp -r php/* /usr/share/nginx/html/zabbix # /usr/share/nginx/html/zabbix/conf/zabbix.conf.php 保存zabbix连接信息
- 修改nginx配置文件
sudo vim /etc/nginx/nginx.conf user www-data; worker_processes 4; pid /run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; server { listen 8088; server_name localhost; # access_log /var/log/nginx/zabbix.log main; root /usr/share/nginx/html/zabbix/; index index.php; location /{ try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; } } }
6. Ubuntu下安装
1.安装server
wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.0-1+trusty_all.deb dpkg -i zabbix-release_3.0-1+trusty_all.deb apt-get update apt-get install php5 zabbix-frontend-php php5-mysql sudo apt-get install zabbix-server-mysql #会安装MySQL sudo vim /etc/zabbix/zabbix_server.conf DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix
# 配置PHP sudo vim /etc/php5/apache2/php.ini修改项: post_max_size = 16M max_execution_time = 300 max_input_time = 300 date.timezone = "Asia/Shanghai" 修改完成后重启apache2 /etc/init.d/apache2 restart 配置数据库 首先mysql配置 cd /etc/mysql sudo vim my.cnf 注释掉下面这行 #bind-address = 127.0.0.1 mysql>create database zabbix character set utf8 collate utf8_bin; mysql>grant all privileges on zabbix.* to [email protected] identified by ‘zabbix‘; mysql> flush privileges; sudo apt-get install zabbix-frontend-php(数据库root,root,root) sudo cp -r /usr/share/zabbix /var/www/html/zabbix
- 初始化数据库
cd /usr/share/doc/zabbix-server-mysql
ls
gunzip create.sql.gz
mysql -uzabbix -pzabbix zabbix <create.sql
- 重启
sudo /etc/init.d/zabbix-server stop
sudo /etc/init.d/zabbix-server start
- 安装agent(不用重复做)
wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.0-1+trusty_all.deb dpkg -i zabbix-release_3.0-1+trusty_all.deb apt-get install zabbix-agent
sudo vim /etc/zabbix/zabbix_agentd.conf 做以下修改 Server=192.168.0.157 ServerActive=192.168.0.157 Hostname=bigdata2
- 因为安装agent时会启动agent进程,在修改配置文件后要重启agent服务。
sudo service zabbix-agent restart
7. 配置中文环境
首先启用中文 sudo vim /usr/share/zabbix/include/locales.inc.php 把zh_CN后面参数写true,然后安装中文包 sudo apt-get install language-pack-zh-hant language-pack-zh-hans 接着,配置相关环境变量: vi /etc/environment 在文件中增加语言和编码的设置: LANG="zh_CN.UTF-8" LANGUAGE="zh_CN:zh:en_US:en" 接着,重新设置本地配置: dpkg-reconfigure locales 最后重启apache,server服务
7.解决中文乱码
- 在zabbix的frontend页面所在目录中,可以这样查找目录
sudo find / -name defines.inc.php -print
1. 到网上下载simkai.ttf文件,上传到/usr/share/zabbix/fonts目录下
2. 修改配置sudo vim /usr/share/zabbix/include/defines.inc.php
重启web服务。
sudo service php5-fpm restart
以上是关于zabbix安装(Ubuntu)的主要内容,如果未能解决你的问题,请参考以下文章