Ubuntu16.04搭建zabbix服务端

这次的实验环境是在docker容器中进行的,为此我们需要docker pull ubuntu:16.04的镜像,以及映射zabbix的80端口。

创建实验容器

docker pull ubuntu:16.04
docker run -it --name zabbix_server -p 8080:80 ubuntu:16.04 /bin/bahs

1. 更新apt源

这里用的源为阿里云的公共源

cp /etc/apt/sources.list /etc/apt/sources.list.bak
echo > /etc/apt/sources.list
cat >> /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
 deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
EOF
apt-get update

2. 安装apache2及PHP7.0

更新完之后安装apache2

apt-get install -y apache2

安装PHP7.0及其依赖

apt-get install -y php7.0 php7.0-xml php7.0-curl php7.0-mbstring libapache2-mod-php7.0

3. 安装及配置mysql

apt-get install -y mysql-server mysql-client

配置mysql,创建zabbix用户及数据库

mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'you password';
mysql> flush privileges;
mysql> exit

4. 安装zabbix

添加zabbix仓库

wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+xenial_all.deb
dpkg -i zabbix-release_4.0-2+xenial_all.deb
apt-get updat

安装zabbix

apt-get install -y zabbix-server-mysql zabbix-frontend-php zabbix-agent zabbix-proxy-mysql

5. 配置zabbix及apache2

修改/etc/zabbix/zabbix_server.conf文件中关于数据库的配置

DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=数据库密码

修改apache2配置文件
/etc/zabbix/apache.conf文件中的内容复制到/etc/apache2/apache2.conf中,并修改其中的时区配置项。
/etc/apache2/apache2.conf将文件中的注释去掉之后的内容

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
	Options FollowSymLinks
	AllowOverride None
	Require all denied
</Directory>

<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
	Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

我们将apache2/apache2.conf文件中的<Directory>项全部删掉,并将zabbix/apache.conf文件中的内容粘贴在<Directory>的位置上,效果如下

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<IfModule mod_alias.c>
    Alias /zabbix /usr/share/zabbix
</IfModule>

<Directory "/usr/share/zabbix">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

    <IfModule mod_php5.c>
        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 max_input_vars 10000
        php_value always_populate_raw_post_data -1
        php_value date.timezone Asia/Shanghai 此处修改为自身的时区,并取消注释
    </IfModule>
    <IfModule mod_php7.c>
        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 max_input_vars 10000
        php_value always_populate_raw_post_data -1
        php_value date.timezone Asia/Shanghai 此处修改为自身的时区,并取消注释
    </IfModule>
</Directory>

<Directory "/usr/share/zabbix/conf">
    Order deny,allow
    Deny from all
    <files *.php>
        Order deny,allow
        Deny from all
    </files>
</Directory>

<Directory "/usr/share/zabbix/app">
    Order deny,allow
    Deny from all
    <files *.php>
        Order deny,allow
        Deny from all
    </files>
</Directory>

<Directory "/usr/share/zabbix/include">
    Order deny,allow
    Deny from all
    <files *.php>
        Order deny,allow
        Deny from all
    </files>
</Directory>

<Directory "/usr/share/zabbix/local">
    Order deny,allow
    Deny from all
    <files *.php>
        Order deny,allow
        Deny from all
    </files>
</Directory>

AccessFileName .htaccess
<FilesMatch "^\.ht">
	Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

6. 导入zabbix数据库数据

/usr/share/doc/zabbix-server-mysql/目录下,有一个create.sql.gz文件,解压文件并导入数据库
注意:如果不存在该文件则转到第9步

zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix

7. 设置zabbix自启

systemctl enable zabbix-server zabbix-agent apache2
service zabbix-server restart
service zabbix-agent restart
service apache2 restart

8. 测试

在浏览器中输入zabbix服务器的ip地址访问zabbix
如:127.0.0.1/zabbix

看到这个界面之后就是正式开始配置zabbix了,zabbix的默认登陆密码为Admin:zabbix

9. 如果安装了zabbix-server-mysql后找不到create.sql.gz怎么办?

  • 首页先找到需要安装的版本的对应源码包,在官网可以找到,如我这里使用的zabbix4.0的版本
    https://www.zabbix.com/download_sources#tab:40LTS
    访问上面的链接找到源码包并下载下来
  • 下载完之后解压,在database文件夹中找到mysql文件夹,将其中的data.sql, images.sql, schema.sql导入到数据库中即可。
    mysql导入方式
mysql -uroot -p -D zabbix < schema.sql

导入顺序为schema.sql->images.sql->data.sql

zabbix设置中文的方法
安装language-pack-zh-hant language-pack-zh-hans
重启zabbix-server及apache2

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页