欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

IBM Cloud上基于Grafana和Zabbix的监控环境安装

程序员文章站 2022-03-06 18:27:45
1:安装准备Zabbix需要的LNMP环境可以使用脚本或source code安装,前者较快, 在CentOS 7.x上大约1小时,源码安装比较慢。系统和软件版本:CentOS 7.x 在IBM Cloud上创建的虚机,测试中使用瞬态配置,上线时用Public型。mysql-5.7.29.tar.gznginx-1.16.1.tar.gzphp-7.2.27.tar.gzzabbix-4.4.5.tar.gzgrafana-7.1.5-1.x86_64.rpmalexanderzob...

1:安装准备
Zabbix需要的LNMP环境可以使用脚本或source code安装,前者较快, 在CentOS 7.x上大约1小时,源码安装比较慢。

系统和软件版本:

  • CentOS 7.x 在IBM Cloud上创建的虚机,测试中使用瞬态配置,上线时用Public型。
    IBM Cloud上基于Grafana和Zabbix的监控环境安装
  • mysql-5.7.29.tar.gz
  • nginx-1.16.1.tar.gz
  • php-7.2.27.tar.gz
  • zabbix-4.4.5.tar.gz
  • grafana-7.1.5-1.x86_64.rpm
  • alexanderzobnin-zabbix-app version: 4.0.1

(1) 关闭防火墙和selinux
(2)创建安装目录和用户

mkdir -pv /tools/{mysql-5.7,nginx-1.16,php-7.2,zabbix-4.4}
mkdir -pv /tools/mysql-5.7/data

ln -s /tools/mysql-5.7 /tools/mysql
ln -s /tools/nginx-1.16 /tools/nginx
ln -s /tools/php-7.2 /tools/php
ln -s /tools/zabbix-4.4 /tools/zabbix

useradd -s /sbin/nologin mysql
useradd -s /sbin/nologin nginx
useradd -s /sbin/nologin zabbix

2:安装mysql

cd tools
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.29.tar.gz
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.29.tar.gz

yum install -y cmake gcc gcc-c++ openssl-devel ncurses-devel

tar xvf mysql-5.7.29.tar.gz
tar xvf mysql-boost-5.7.29.tar.gz -C /tools/

cd mysql-5.7.29

cmake \
-DCMAKE_INSTALL_PREFIX=/tools/mysql-5.7 \
-DMYSQL_DATADIR=/tools/mysql-5.7/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_unicode_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_BOOST=/tools/mysql-5.7.29/boost/boost_1_59_0

make & make install

创建需要的文件及更改属主和属组

mkdir -pv /tools/mysql/log
touch /tools/mysql/log/mariadb.log
touch /tools/mysql/log/mariadb.pid
chown -R mysql /tools/{mysql-5.7,mysql-5.7.29,mysql}

(5) 初始化数据,修改配置文件

vim /etc/my.cnf
[mysqld]
datadir=/tools/mysql/data #数据目录位置
socket=/tools/mysql/mysql.sock #sock文件的路径
skip-grant-tables #跳过登录认证
user=mysql
explicit_defaults_for_timestamp=true
[mysqld_safe]
log-error=/tools/mysql/log/mariadb.log #错误日志位置
pid-file=/tools/mysql/log/mariadb.pid

(6) 添加环境变量

vim /etc/profile //末尾添加两行

export PATH=$PATH:/tools/mysql/support-files
export PATH=$PATH:/tools/mysql/bin

保存退出刷新环境变量 
source /etc/profile/

(7) 初始化启动mysql

mysqld --initialize --user=mysql --basedir=/tools/mysql --datadir=/tools/mysql/data
mysql.server start
//记住此处系统自动生成的临时密码
ln -s /tools/mysql/mysql.sock /tmp/

(8) 下载zabbix源码包并解压

wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.4.5/zabbix-4.4.5.tar.gz
tar xvf zabbix-4.4.5.tar.gz
cd zabbix-4.4.5/database/mysql

登录mysql:

mysql -u root -p

输入刚才记录的密码,登录后执行以下命令:

use mysql;
create database zabbix default character set utf8;
update mysql.user set authentication_string=password('修改的密码') where user='root';
use zabbix;
source schema.sql;
source images.sql;
source data.sql;
exit;

最后恢复密码登录mysql 修改文件,重启mysql服务

vim /etc/my.cnf
//去掉 skip-grant-tables

mysql.server restart

//下次登录mysql需要修改密码

mysql> SET PASSWORD = PASSWORD('new-password');

添加lib文件

echo “/tools/mysql/lib” > /etc/ld.so.conf.d/mysql.conf

ldconfig -v

3:安装nginx
(1) 下载 nginx 并解压

cd tools
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar xvf nginx-1.16.1.tar.gz

(2) 编译安装并添加环境变量

cd nginx-1.16.1

./configure --prefix=/tools/nginx-1.16 --user=nginx --group=nginx --without-select_module --without-poll_module --with-http_ssl_module --with-pcre --with-debug

make 
make install 

添加变量

vim /etc/profile //追加一行
export PATH=$PATH:/tools/nginx/sbin

source /etc/profile

(3)更改 nginx 的属主和属组以及修改配置文件

chown nginx:nginx -R /tools/nginx-1.16

修改配置文件

vim /tools/nginx/conf/nginx.conf

修改启动用户 user nginx;
启动nginx:

nginx

4:安装php
(1) 下载php源码并井进行解压

cd /tools
wget https://www.php.net/distributions/php-7.2.27.tar.gz
tar xvf php-7.2.27.tar.gz

(2) 安装及解决依赖

yum install -y libxml2-devel openssl-devel net-snmp net-snmp-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel bzip2 bzip2-devel freetype-devel gmp-devel readline-devel libxslt-devel fontconfig

cd php-7.2.27

./configure --prefix=/tools/php-7.2 --with-mysqli=/tools/mysql/bin/mysql_config --enable-inline-optimization --enable-fpm --enable-soap --enable-pcntl --enable-xml --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --without-pear


 make
 make install

(3) 拷贝服务和配置文件,设置属主和属组

cp /tools/php-7.2.27/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
cp /tools/php-7.2/etc/{php-fpm.conf.default,php-fpm.conf}
cp /tools/php-7.2/etc/php-fpm.d/www.conf{.default,}
cp php.ini-production /tools/php-7.2/lib/php.ini

chown nginx:nginx -R /tools/php-7.2

(4) 修改配置文件并启动

修改php.ini配置文件

vim /tools/php/lib/php.ini //修改如下4行

post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = PRC

启动php服务

systemctl start php-fpm.service && systemctl enable php-fpm.service

修改nginx.conf文件使nginx支持php

vim /tools/nginx/conf/nginx.conf 

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

编写测试php文件

vim /tools/nginx/html/index.php

          <?php phpinfo(); ?>

重启nginx服务

nginx -s reload

5:安装Zabbix Server
(1) 安装依赖,编译安装

yum localinstall -y libevent-devel-2.0.21-4.el7.x86_64.rpm
yum install unixODBC-devel mysql-devel net-snmp-devel libxml2-devel libcurl-devel libevent-devel -y
cd zabbix-4.4.5
./configure --prefix=/tools/zabbix-4.4 --enable-server --enable-agent --with-mysql=/tools/mysql/bin/mysql_config --enable-ipv6 --with-netsnmp --with-libcurl --with-libxml2
make 
make install

(2) 配置环境变量

vim /etc/profile	//追加如下行
export PATH=$PATH:/tools/zabbix/sbin

source /etc/profile

(3) 修改配置文件

vim /tools/zabbix/etc/zabbix_server.conf 
DBUser=root
DBPassword=theDBpassword

拷贝zabbix至nginx的目录下,重启nginx服务;
cd /tools/zabbix-4.4.5
cp -R frontends/php/* /tools/nginx/html/
nginx -s reload

访问页面ok即可。

(4)登录
账户为 admin 密码zabbix
登录后界面为http://your-domain.com/setup.php
注意:

  1. 连接数据库的步骤需要将服务器ip改为127.0.0.1 不能使用localhost,否则会报错。
  2. 在Install步骤,配置文件无法安装,按照页面提示手动下载传到nginx目录下即可。
# mysql -uroot -p -e "grant all on zabbix.* to 'zabbix'@localhost identified by 'zabbix'"
Enter password:

IBM Cloud上基于Grafana和Zabbix的监控环境安装

IBM Cloud上基于Grafana和Zabbix的监控环境安装

  1. 安装Zabbix agent
cd /tools
wget https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.5-1.el7.x86_64.rpm
systemctl stop firewalld
systemctl disable firewalld.service
grep SELINUX /etc/selinux/config
SELINUX=disabled
rpm -Uvh https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-agent-4.4.5-1.el7.x86_64.rpm

vi /etc/zabbix/zabbix_agentd.conf
# Server=
StartAgents=0
ServerActive=<server's-IP-addr>
Hostname=dallas

service zabbix-agent start
chkconfig zabbix-agent on
  1. 安装Grafana
wget https://dl.grafana.com/oss/release/grafana-7.1.5-1.x86_64.rpm
yum install grafana-7.1.5-1.x86_64.rpm
systemctl start grafana-server
systemctl status grafana-server
systemctl enable grafana-server

登录UI,默认用户名/口令为admin/admin

  1. 安装Grafana-Zabbix plugin
grafana-cli plugins list-remote|grep zabbix
grafana-cli plugins install alexanderzobnin-zabbix-app
grafana-cli plugins install grafana-clock-panel
systemctl restart grafana-server

配置Zabbix数据源,开启监控。
IBM Cloud上基于Grafana和Zabbix的监控环境安装IBM Cloud上基于Grafana和Zabbix的监控环境安装

本文地址:https://blog.csdn.net/weixin_46707197/article/details/111996548