一个系统运维的打怪升级之路

LNMP 环境下部署 zabbix 4.0.7

2013-04-11
21,511次查阅
2019/6/13

zabbix服务端

为了方便后续 MySQL 的命令续操作,先配置 mysql 配置文件,编辑/etc/my.cnf添加如下:

[client]
password   = mysql_root_passowrd

安装依赖包

yum groupinstall "Development tools" -y
yum install -y net-snmp-devel unixODBC-devel mysql-devel net-snmp-devel libxml2-devel libcurl-devel libevent-devel gcc-c++ gcc perl-DBI

Ubuntu:

apt install libsnmp-dev libxml2-dev libevent-dev libpcre3-dev

配置zabbix用户和组

groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin

下载源码包并解压

wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.7/zabbix-4.0.7.tar.gz
tar zxvf zabbix-4.0.7.tar.gz && cd zabbix-4.0.7

./configure --prefix=/usr/local/zabbix \
--enable-server \
--enable-agent \
--enable-proxy \
--with-mysql=/usr/local/mysql/bin/mysql_config \
--with-net-snmp \
--with-libcurl \
--with-libxml2

make install

chown zabbix:zabbix /usr/local/zabbix/ -R
cp misc/init.d/tru64/zabbix_* /etc/init.d/
chmod +x /etc/init.d/zabbix_*

ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
ln -s /usr/local/zabbix/bin/* /usr/local/bin/

# 创建自定义脚本存放目录
mkdir -p /data/zabbix/alertscripts
chown zabbix:zabbix /data/zabbix -R

修改配置文件:

egrep -Ev "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf
ListenPort=10051
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=root
DBPassword=mysql_root_password
DBSocket=/tmp/mysql.sock
Timeout=4
AlertScriptsPath=/data/zabbix/alertscripts
LogSlowQueries=3000

创建数据库,初始化数据:

mysql -e "create database zabbix default charset utf8;"
mysql zabbix < database/mysql/schema.sql
mysql zabbix < database/mysql/images.sql
mysql zabbix < database/mysql/data.sql

启动zabbix服务:

/etc/init.d/zabbix_server start

配置zabbix网页控制台:

mkdir -p /data/wwwroot/zabbix
\cp -a frontends/php/* /data/wwwroot/zabbix
chown -R www:www /data/wwwroot/zabbix

Nginx 配置:

server
{
    listen 80;
    server_name zabbix.1987.name;
    index index.html index.htm index.php;
    root /home/wwwroot/zabbix;
    access_log /home/nginxlogs/zabbix.1987.name.log jsonlog;

    error_page 404 403 500 502 503 504 /error.html;
    location = /error.html {
        root /home/wwwroot/error_page;
    }

    #Enable PHP
    include enable-php.conf;

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|ico)$ {
        access_log off;
        expires 7d;
    }
}

完成之后即可登录,zabbix默认登录账号密码:Admin/zabbix

默认zabbix图形上的中文无法显示,这里需要更换字体,上传字体文件到/data/wwwroot/zabbix/fonts目录下,修改文件/data/wwwroot/zabbix/include/defines.inc.php,下面两处:

define(‘ZBX_GRAPH_FONT_NAME’,        ‘DejaVuSans’);
define(‘ZBX_FONT_NAME’, ‘DejaVuSans’);

修改里面的字体名字,字体文件后缀为ttf。

安装agentd

依赖包:

yum groupinstall "Development tools" -y
yum install -y net-snmp-devel unixODBC-devel mysql-devel net-snmp-devel libxml2-devel libcurl-devel libevent-devel gcc-c++ gcc perl-DBI

建立用户组:

groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin

编译安装:

./configure --prefix=/usr/local/zabbix --enable-agent

make install

chown zabbix:zabbix /usr/local/zabbix/ -R
cp misc/init.d/tru64/zabbix_* /etc/init.d/
chmod +x /etc/init.d/zabbix_*

ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
ln -s /usr/local/zabbix/bin/* /usr/local/bin/

配置文件:

egrep -Ev "^#|^$" /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

启动:

/etc/init.d/zabbix_agentd start

评论

想说点什么?