zabbix部署安装
zabbix server端配置与部署
- 安装rpm包,生成.repo文件
rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
- 安装依赖包
wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64//iksemel-1.4-6.sdl7.x86_64.rpm
yum install iksemel-1.4-6.sdl7.x86_64.rpm
- 安装zabbix-server-mysql zabbix-web-mysql
#避免下载速度过慢可以重新配置zabbix下载源
[root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo
# 输入 -> :%s#repo.zabbix.com#mirror.tuna.tsinghua.edu.cn/zabbix#g
yum install zabbix-server-mysql zabbix-web-mysql httpd mysql -y
- 修改zabbix-server配置信息`
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
如果mysql也是在本机上面,但是不是通过yum安装的,而是通过二进制或者编译安装可能需要配置socket路径,否则可能连接不上mysql
# 过滤需要修改的配置文件,进行检查
[root@localhost ~]# grep -Ev '^$|#' /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<your password>
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
- 授权zabbix数据库用户,并导入zabbix表
create database zabbix character set utf8 collate utf8_bin;//创建zabbix数据库
grant all on zabbix.* to zabbix@'localhost' identified by '<your password>';//创建用户
zcat /usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz |mysql -u zabbix -p<your password> zabbix//导入zabbix的表数据
- 配置zabbix的httpd子配置文件
vim /etc/httpd/conf.d/zabbix.conf --打开时区注释,并修改成你的时区
#php_value date.timezone Asia/Shanghai
- 启动zabbix,httpd,mysql服务
systemctl restart zabbix-server.service
systemctl enable zabbix-server #开机自启动
systemctl restart httpd.service
systemctl enable httpd.service #开机自启动
systemctl restart mysqld.service #启动mysql数据库
systemctl enable mysqld.service
- 关闭防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config #永久关闭
systemctl stop firewalld
- 如果连接到本地数据库的socket文件,是因为数据库默认socket默认路径为/tmp/mysql.sock
#通过设置软链接可以解决
ln -s /home/mysql/mysql.sock /var/lib/mysql/mysql.sock
- 打开浏览器访问zabbix页面
访问localhost/zabbix
zabbix的默认账户:Admin,默认密码:zabbix,点击登录。
参考链接:https://github.com/ThanlonSmith/Zabbix-Tutorial
yum install zabbix-agent -y
systemctl start zabbix-agent.service
systemctl enable zabbix-agent.service
zabbix agent端的部署
另起一台centos7 主机
- 下载zabbix-agent的rpm包,并在本地安装
wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.16-1.el7.x86_64.rpm
rpm -ivh zabbix-agent-4.0.16-1.el7.x86_64.rpm
- 修改agent端的配置文件
vim /etc/zabbix/zabbix_agentd.conf
- 配置zabbix-agent开机启动
systemctl enable zabbix-agent
systemctl restart zabbix-agent
zabbix agent添加后web的设置
创建主机
最后记得点击添加模板
使用nginx提供zabbix前端页面,在nginx.conf文件添加
server {
listen 80; #监听的端口号
server_name www.sc.com; #虚拟主机(网站服务的域名)
root /usr/share/zabbix; #网页存放的路径
index index.php; #网站的首页
location = /favicon.ico {
log_not_found off;
}
location / {
try_files $uri $uri/ =404;
}
location /assets {
access_log off;
expires 10d;
}
location ~ /\.ht {
deny all;
}
location ~ /(api\/|conf[^\.]|include|locale) {
deny all;
return 404;
}
location ~ [^/]\.php(/|$) {
# 如果没有此sock文件,则修改为127.0.0.1:9000
fastcgi_pass unix:/run/php-fpm/zabbix.sock; #php结尾的文件路由到这个socket文件
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT /usr/share/zabbix;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}
重启nginx
nginx -s reload
发现
检查发现忘记安装php-fpm,无法解析php页面
[root@nginx_LB conf]# netstat -anpo | grep "php-fpm" | wc -l
>>0
下载php-fpm,并启动php-fpm
yum install php-fpm -y
systemctl start php-fpm
systemctl enable php-fpm
访问成功,登录
修改/etc/php.ini文件中的date.timezone = “Asia/Shanghai”
重启php-fpm,刷新网页,发现访问成功