码迷,mamicode.com
首页 > 其他好文 > 详细

Zabbix实战-1

时间:2020-08-13 11:54:27      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:time   private   zlib   data   NPU   creat   ini   目录   lan   

作者:Vaedit

官网文档地址:https://www.zabbix.com/cn/download?zabbix=4.0&os_distribution=centos&os_version=7&db=mysql&ws=apache

实验环境

ip地址 组件 配置
192.168.0.160 zabbix-server,php,mysql,zabbix-agent,zabbix-web,nginx等 2核2G
192.168.0.161 zabbix-agent,nginx 2核2G

安装zabbix-server环境

1 初始化环境
#192.168.0.160
setenforce 0
systemctl stop firewalld
systemctl enable firewalld
2 安装Mysql

部署Mysql 5.7版本:

yum -y install yum-utils 
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
yum install mysql-community-server mysql-community-devel
systemctl start mysqld
systemctl status mysqld
systemctl enable mysqld

设置root密码:

grep ‘temporary password‘ /var/log/mysqld.log
mysql -uroot -p
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Zabbix@2019‘;

修改配置文件:

# vi /etc/my.cnf
[mysql]
socket = /tmp/mysql.sock
[mysqld]
user = mysql
port = 3306
datadir = /var/lib/mysql
socket = /tmp/mysql.sock
bind-address = 0.0.0.0
pid-file = /var/run/mysqld/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci
log-error = /var/log/mysqld.log

max_connections = 10240
open_files_limit = 65535
innodb_buffer_pool_size = 3G
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 256M
# 修改完成后重启
# systemctl restart mysqld
3 安装Nginx

源码编译安装:

wget http://nginx.org/download/nginx-1.15.3.tar.gz
yum install gcc pcre-devel openssl-devel –y
useradd -M -s /sbin/nologin nginx
tar zxvf nginx-1.15.3.tar.gz
cd nginx-1.15.3
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
make && make install

修改配置文件,修改pid位置:

# vi /usr/local/nginx/conf/nginx.conf
pid        /var/run/nginx.pid;

配置systemd管理服务:

# vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

启动并开启自启:

systemctl daemon-reload
systemctl start nginx
systemctl enable nginx
4 PHP部署

安装依赖:

yum install epel-release -y
yum install -y gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel libxslt-devel

源码编译安装PHP

wget http://docs.php.net/distributions/php-5.6.36.tar.gz
tar zxf php-5.6.36.tar.gz
cd php-5.6.36
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-opcache --with-mysql --with-mysqli  --enable-session --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --enable-xmlwriter --enable-xmlreader --enable-xml --enable-sockets --enable-bcmath --with-gettext
make -j 8 && make install

拷贝配置文件:

cp php.ini-production /usr/local/php/etc/php.ini
cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/

配置systemd管理服务:

# vi /usr/lib/systemd/system/php-fpm.service 
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

启动并开机自启:

systemctl daemon-reload
systemctl start php-fpm
systemctl enable php-fpm
5 部署Zabbix-server

安装依赖包:

yum install libxml2-devel libcurl-devel libevent-devel net-snmp-devel mysql-community-devel -y

源码编译安装zabbix:

tar -zxf zabbix-4.0.0.tar.gz
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
cd zabbix-4.0.0
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
make install

修改配置文件:

# vi /usr/local/zabbix/etc/zabbix_server.conf
# egrep -v "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=root
DBPassword=Zabbix@2019
DBSocket= /tmp/mysql.sock
Timeout=4
AlertScriptsPath=/usr/local/zabbix/alertscripts
LogSlowQueries=3000

配置systemd管理服务:

# vi /usr/lib/systemd/system/zabbix_server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0

[Install]
WantedBy=multi-user.target

导入表结构:

cd zabbix-4.0.0/database/mysql
mysql -uroot –pZabbix@2019
create database zabbix default charset utf-8;
mysql> use zabbix;
mysql> source schema.sql;
mysql> source images.sql;
mysql> source data.sql;

####单独设置zabbix用户
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by ‘password‘;
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit; 

#yum安装可以通过如下导入初始架构和数据,系统将提示您输入新创建的密码。
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix 

启动并加入开机启动:

systemctl daemon-reload
systemctl start zabbix-server
systemctl enable zabbix-server

启动Agent,也监控本机:

/usr/local/zabbix/sbin/zabbix_agentd
6 部署Zabbix WEB

Zabbix前端使用PHP写的,所以必须运行在PHP支持的Web服务器上。只需要简单的从frontends/php路径下复制PHP文件到Web服务器的网站根目录,就可以访问页面了。

拷贝Zabbix前端程序到网站根目录:

cp zabbix-4.0.0/frontends/php/* /usr/local/nginx/html/ -rf

修改配置参数:

# vi /usr/local/php/etc/php.ini
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
always_populate_raw_post_data = -1
date.timezone = Asia/Shanghai

重启php-fpm生效:

systemctl restart php-fpm

修改Nginx配置文件:

# vi /usr/local/nginx/conf/nginx.conf  
  server {
        listen       80;
        server_name  localhost;

        access_log  logs/zabbix.access.log  main;

        location / {
            root   html;
            index  index.php index.html index.htm;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

# 重启Nginx
systemctl restat nginx

然后就可以通过访问网页开始初始化配置Zabbix,初始化默认账号密码:Admin,zabbix

Zabbix实战-1

标签:time   private   zlib   data   NPU   creat   ini   目录   lan   

原文地址:https://blog.51cto.com/vaedit/2519342

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!