文章目录
- @[toc]
- 一、环境准备
- 1)部署lnmp
- 2)修改配置文件
- 3)安装数据库
- 二、部署zabbix
- 1)下载zabbix
- 2)安装zabbix服务端
- 3)修改配置
- 4)开机启动
- 5)安装客户端
- 三、登录配置
- 1)访问
- 2)修改一下php的配置
- 3)连接数据库
- 4)修改时区,填入主机名称
- 5)安装成功界面
- 6)登录zabbix
- 四、添加监控
文章目录
- @[toc]
- 一、环境准备
- 1)部署lnmp
- 2)修改配置文件
- 3)安装数据库
- 二、部署zabbix
- 1)下载zabbix
- 2)安装zabbix服务端
- 3)修改配置
- 4)开机启动
- 5)安装客户端
- 三、登录配置
- 1)访问
- 2)修改一下php的配置
- 3)连接数据库
- 4)修改时区,填入主机名称
- 5)安装成功界面
- 6)登录zabbix
- 四、添加监控
一、环境准备
1)部署lnmp
#先安装nginx和php待用
yum -y install yum-utils#修改nginx的源
$ vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true#安装nginx
yum install -y nginx#安装php源和php7.4
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php74
yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json -y
php -v#启动
systemctl start nginx php-fpm
systemctl enable nginx
systemctl enable php-fpm
2)修改配置文件
- 把php的默认用户修改为跟nginx一样的,并增加一个nginx的配置文件
sed -i "s#apache#nginx#g" /etc/php-fpm.d/www.conf
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.`date +%F`
$ vim /etc/nginx/conf.d/zabbix.conf
server {listen 80;server_name localhost;root /app/code/zbx;location / {index index.php;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
mkdir -p /app/code/zbx
systemctl restart nginx php-fpm
3)安装数据库
#卸载mariadb
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# yum remove -y mariadb-libs-5.5.68-1.el7.x86_64
#安装mysql数据库
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
tar -xf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.28-linux-glibc2.12-x86_64 /usr/local/mysql
useradd mysql
mkdir -p /data/3306/mysql
mkdir -p /data/mysql/3306/data
chown -R mysql:mysql /data/mysql/3306/data$ vim /etc/my.cnf
[mysqld]
port=3306
user=mysql
datadir=/data/3306/mysql
pid-file=/data/3306/mysql/mysql.pid
socket=/data/3306/mysql/mysql.sock
[client]
socket=/data/3306/mysql/mysql.sock/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
source /etc/profilemysql -uroot
mysql> create database if not exists `zabbix` default character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@'%' identified by 'Zabbix886!';
mysql> grant all privileges on *.* to zabbix@'%';
mysql> exit
- 增加安全性,MySQL设置密码。
-- 使用mysql客户端登录到MySQL服务
mysql -u root -p -- 在mysql提示符下,运行以下命令来更新密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '1q2w3e4r';-- 刷新权限使更改生效
FLUSH PRIVILEGES;#测试登录
mysql -u root -p1q2w3e4r
二、部署zabbix
1)下载zabbix
wget -c https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.9.tar.gz
tar -xf zabbix-6.4.9.tar.gz -C /data/
cd /data/zabbix-6.4.9/database/mysql/
mysql -uroot zabbix < schema.sql
mysql -uroot zabbix < images.sql
mysql -uroot zabbix < data.sql
2)安装zabbix服务端
#安装依赖
yum install -y mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent-devel openldap-devel libcurl-devel
cd /data/zabbix-6.4.9#连接依赖
ln -s /usr/local/mysql/lib/private/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
ln -s /usr/local/mysql/lib/private/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/mysql/lib/libmysqlclient.so.21 /usr/lib64/libmysqlclient.so.21#编译
./configure --sysconfdir=/etc/zabbix/ --enable-server --with-mysql --with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib --with-libpthread --with-libevent --with-openssl --with-ldap --with-libcurl --with-libpcre
make install#删除编译的数据目录
rm -rf /data/zabbix-6.4.9
我这里报错了,原因是缺少了两个依赖库
/usr/bin/ld: warning: libcrypto.so.1.1, needed by /usr/local/mysql/lib/libmysqlclient.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libssl.so.1.1, needed by /usr/local/mysql/lib/libmysqlclient.so, not found (try using -rpath or -rpath-link)
我从刚刚下载的数据库里面拉一个出来就可以了
ln -s /usr/local/mysql/lib/private/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
ln -s /usr/local/mysql/lib/private/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/mysql/lib/libmysqlclient.so.21 /usr/lib64/libmysqlclient.so.21
3)修改配置
cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.`date +%F`
cat >/etc/zabbix/zabbix_server.conf<<EOF
ListenPort=10051
LogFile=/var/log/zabbix_server.log
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=Zabbix886!
AllowUnsupportedDBVersions=1
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
EOF
4)开机启动
#创建用户
useradd -s /sbin/nologin -M zabbix#修改systemctl开机管理
cat > /usr/lib/systemd/system/zabbix-server.service<<EOF
[Unit]
Description=Zabbix Server with MySQL DB
After=syslog.target network.target mysqld.service[Service]
Type=simple
ExecStart=/usr/local/sbin/zabbix_server -f
User=zabbix[Install]
WantedBy=multi-user.target
EOF#重新加载配置
systemctl daemon-reload
touch /var/log/zabbix_server.log
chown -R zabbix:zabbix /var/log/zabbix_server.log
systemctl start zabbix-server
systemctl enable zabbix-server
cp -r ui/* /app/code/zbx/
chown -R nginx:nginx /app/code/zbx/
5)安装客户端
rpm -ivh https://mirrors.aliyun.com/zabbix/zabbix/6.4/rhel/7/x86_64/zabbix-agent2-6.4.9-release1.el7.x86_64.rpm
sed -i 's#gpgcheck=1#gpgcheck=0#g' /etc/yum.repos.d/zabbix.repo
yum install -y zabbix-agent2
cp /etc/zabbix/zabbix_agent2.conf /etc/zabbix/zabbix_agent2.conf.`date +%F`
cat >/etc/zabbix/zabbix_agent2.conf<<EOF
PidFile=/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agent2.d/*.conf
PluginSocket=/run/zabbix/agent.plugin.sock
ControlSocket=/run/zabbix/agent.sock
Include=./zabbix_agent2.d/plugins.d/*.conf
EOF
systemctl start zabbix-agent2.service
systemctl enable zabbix-agent2.service
三、登录配置
1)访问
- 访问自己IP地址:http://192.168.6.65/setup.php
- 选择默认语言:中文(zh_CN)
2)修改一下php的配置
#快速修改
cp /etc/php.ini /etc/php.ini.`date +%F`
sed -i "s/post_max_size = 8M/post_max_size = 18M/g" /etc/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php.ini
sed -i "s/max_input_time = 60/max_input_time = 300/g" /etc/php.ini
systemctl restart php-fpm
3)连接数据库
- 填入数据库名、密码、主机
- 主机:192.168.6.65(本机IP地址)
- 数据库名称:zabbix
- 密码:Zabbix886!
4)修改时区,填入主机名称
- 主机名称:信息中心监控
- 时区Asia/Shanghai
5)安装成功界面
6)登录zabbix
- http://192.168.6.65/index.php
- 默认账号密码Admin/zabbix
四、添加监控
【参考】https://zhuanlan.zhihu.com/p/678250839