CentOS7.2下部署zabbix4.0
程序员文章站
2022-06-02 18:56:56
...
镜像下载、域名解析、时间同步请点击 阿里云开源镜像站
1. 基础环境配置优化
1.1 关闭防火墙
[root@monitor_53 ~]$ systemctl stop firewalld
[root@monitor_53 ~]$ systemctl disable firewalld
1.2 关闭selinux
[root@monitor_53 ~]$ setenforce 0
[root@monitor_53 ~]$ sed -i "s#enforcing#disabled#g" /etc/sysconfig/selinux
1.3 下载官方源
[root@monitor_53 ~]$ wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@monitor_53 ~]$ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@monitor_53 ~]$ yum clean all
[root@monitor_53 ~]$ yum makecache
[root@monitor_53 ~]$ yum update -y
1.4 安装扩展和依赖
[root@monitor_53 ~]$ yum install -y php-mysql php-gd php-bcmath php-common php-xml php-mbstring php-cli pcre glibc gcc livevent zlib libcurl-devel curl-devel OpenIPMI-devel libssh2 fping net-snmp-devel perl-DBI openssl-devel iksemel libxml2
2. 安装lnmp架构
2.1 安装LNMP环境
[root@monitor_53 ~]$ yum install -y httpd php mariadb mariadb-server ntp
2.2 配置时间同步
[root@monitor_53 ~]$ ntpdate -u asia.pool.ntp.org
[root@monitor_53 ~]$ systemctl enable ntpd
[root@monitor_53 ~]$ echo '* /30 * * * * /usr/sbin/ntpdate -u asia.pool.ntp.org > /dev/null 2>&1' >>/var/spool/cron/root
2.3 配置数据库
[root@monitor_53 ~]$ mkdir -p /home/mysql/{data,logs}
[root@monitor_53 ~]$ touch /home/mysql/logs/slow_query_log.log
[root@monitor_53 ~]$ touch /home/mysql/logs/error.log
[root@monitor_53 ~]$ chown -R mysql:mysql /home/mysql
[root@monitor_53 ~]$ cp /etc/my.cnf /etc/my.cnf.bak
[root@monitor_53 ~]$ cat /etc/my.cnf
[mysqld]
user = mysql
port = 3306
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
pid-file = /var/run/mariadb/mariadb.pid
log-error = /home/mysql/logs/error.log
slow_query_log = on
slow_query_log_file = /home/mysql/logs/slow_query_log.log
long_query_time = 0.1
log_queries_not_using_indexes =1
long_query_time=2
character_set_server=utf8
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqldump]
quick
max_allowed_packet = 32M
2.4 初始化数据库
[root@monitor_53 ~]$ systemctl enable mariadb
[root@monitor_53 ~]$ systemctl start mariadb
[root@monitor_53 ~]$ mysql_secure_installation #初始化,配置完成root密码后,一路按Y即可
[root@monitor_53 ~]$ mysql_secure_installation
Enter current password for root (enter for none): 回车
Set root password? [Y/n] 回车
New password: 123456
Re-enter new password: 123456
Remove anonymous users? [Y/n] 回车
Disallow root login remotely? [Y/n] 回车
Remove test database and access to it? [Y/n] 回车
Reload privilege tables now? [Y/n] 回车
Thanks for using MariaDB!
2.5 启动http
[root@monitor_53 ~]$ systemctl start httpd
[root@monitor_53 ~]$ systemctl enable httpd
[root@monitor_53 ~]$ netstat -ntap | egrep '(80|3306)'
3. 安装zabbix
3.1 安装Server、Web、Agent
[root@monitor_53 ~]$ rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@monitor_53 ~]$ yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent
3.2 创建zabbix数据库
[root@monitor_53 ~]$ mysql -uroot -p123456
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to 'zabbix'@'10.0.0.53' identified by 'zabbix';
mysql> flush privileges;
mysql> quit;
3.3 导入初始架构和数据
[root@monitor_53 ~]$ zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -h 10.0.0.53 -uzabbix -p zabbix
3.4 为Zabbix-server配置数据库
[root@monitor_53 ~]$ cp /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.bak
[root@monitor_53 ~]$ cat /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
DebugLevel=3
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=10.0.0.53
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/lib/mysql/mysql.sock
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
3.5 为Zabbix-server配置PHP
[root@monitor_53 ~]$ cp /etc/httpd/conf.d/zabbix.conf /etc/httpd/conf.d/zabbix.conf.bak
[root@monitor_53 ~]$ vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Europe/Riga
3.6 修改zabbix-agent配置文件
[root@monitor_53 ~]$ cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
[root@monitor_53 ~]$ cat /etc/zabbix/zabbix_agentd.conf
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
ListenPort=10050
Server=10.0.0.53
ServerActive=10.0.0.53
Hostname=10.0.0.53
Include=/etc/zabbix/zabbix_agentd.d/*.conf
HostMetadataItem=system.uname
StartAgents=1
RefreshActiveChecks=120
BufferSize=200
Timeout=10
3.7 启动server和agent
[root@monitor_53 ~]$ systemctl restart zabbix-server zabbix-agent httpd
[root@monitor_53 ~]$ systemctl enable zabbix-server zabbix-agent httpd
3.8 查看所有服务端口
[root@monitor_53 ~]$ netstat -tnlp | egrep '(80|3306|10050|10051)'
3.9 配置Zabbix前端
浏览器连接到新安装的Zabbix前端: http://10.0.0.53/zabbix
Database type MySQL
Database server 10.0.0.53
Database port 3306
Database name zabbix
Database user zabbix
Database password zabbix
Zabbix server 10.0.0.53
Zabbix server port 10051
Zabbix server name 运维监控
推荐阅读
-
在centos7下安装和部署java8和mysql
-
Linux Centos7.2下安装nodejs&npm配置全局路径的教程
-
阿里云服务器CentOS 6.3下快速安装部署 LAMP 、vsftpd 环境的方法
-
CentOS 6.3下安装部署Oracle服务器图文教程
-
WIN10下WNMP开发环境部署
-
vue-router启用history模式下的开发及非根目录部署方法
-
windows7下mysql8.0.18部署安装教程图解
-
Ubuntu 14.04下Django和MySQL环境部署全过程
-
Linux下GitLab如何安装部署
-
Linux CentOS下安装Tomcat9及web项目的部署