Zabbix 是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix 能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
Zabbix官网
- 临时关闭
systemctl stop firewalld
- 永久关闭
systemctl disable firewalld2、关闭selinux
- 临时关闭
setenforce 0
- 永久关闭
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config3、初始化
mkdir -p /data/{software,logs,temp} chmod 777 /data/logs2、N(Nginx) 1、生成安装脚本
cat > install_nginx.sh << EOF #!/bin/bash ###By Luis yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl yum -y install openssl-devel ng_tgz=`find / -name "nginx-1.18.0.tar.gz"` install_dir=`basename ${ng_tgz} .tar.gz` if [ ! -d /data/software ];then mkdir -p /data/software fi if [ ! -d /data/temp ];then mkdir -p /data/temp fi tar -xf ${ng_tgz} -C /data/temp/ cd /data/temp/${install_dir} ./configure --prefix=/data/software/nginx --with-http_stub_status_module make && make install ln -sv /data/software/nginx/sbin/nginx /usr/bin/nginx EOF2、执行安装
- 将源码包上传至服务器,并执行以上脚本进行安装
sh install_nginx.sh3、使用systemd管理服务
cat > /lib/systemd/system/nginx.service << EOF [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/data/software/nginx/sbin/nginx [Install] WantedBy=multi-user.target EOF systemctl daemon-reload #重载使其生效4、启停方式
- 启动
systemctl start nginx
- 停止
systemctl stop nginx
- 重启
systemctl restart nginx3、M(Mysql) 1、安装脚本
#!/bin/bash yum -y install libaio cd /data/software/ tar xvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ cd /usr/local ln -s mysql-5.7.30-linux-glibc2.12-x86_64 mysql DB_base_DIR='/data/software/mysql_3306' DB_LOG_DIR='/data/logs/mysql_3306' mkdir -p ${DB_base_DIR}/{data,etc,tmp} mkdir -pv ${DB_LOG_DIR}/{innodb_logs,bin,relaylog,undo} useradd mysql chown -R mysql.mysql ${DB_base_DIR} chown -R mysql.mysql ${DB_LOG_DIR} cd /usr/local/mysql cat > /etc/my.cnf <2、执行脚本安装default-character-set=utf8 no-auto-rehash socket=/data/software/mysql_3306/tmp/mysql.sock [mysqld] port=3306 sql_mode='NO_ENGINE_SUBSTITUTION' character-set-server=utf8mb4 default-storage-engine=INNODB default-time-zone="+08:00" log_timestamps=SYSTEM explicit_defaults_for_timestamp=1 transaction-isolation = READ-COMMITTED # directionary innodb_log_group_home_dir=/data/logs/mysql_3306/innodb_logs/ innodb_data_home_dir=/data/software/mysql_3306/data/ innodb_data_file_path=ibdata1:10M:autoextend:max:10G datadir=/data/software/mysql_3306/data/ tmpdir=/data/software/mysql_3306/tmp/ slave_load_tmpdir=/data/software/mysql_3306/tmp/ log_error=/data/logs/mysql_3306/error.log slow_query_log_file=/data/logs/mysql_3306/slow.log socket=/data/software/mysql_3306/tmp/mysql.sock log_bin=/data/logs/mysql_3306/bin/mysql_bin relay_log=/data/logs/mysql_3306/relaylog/relaylog # undo settings innodb_undo_tablespaces=3 innodb_undo_logs=128 innodb_undo_directory=/data/logs/mysql_3306/undo innodb_undo_log_truncate = 1 innodb_max_undo_log_size = 2G innodb_purge_rseg_truncate_frequency = 128 # innodb settings innodb_log_files_in_group=2 innodb_log_file_size=1G innodb_flush_log_at_trx_commit=1 innodb_max_dirty_pages_pct=50 innodb_read_io_threads=8 innodb_write_io_threads=16 innodb_file_per_table=1 innodb_thread_concurrency=16 innodb_change_buffering=inserts innodb_checksum_algorithm=crc32 innodb_adaptive_flushing=1 innodb_stats_on_metadata=0 innodb_flush_method=O_DIRECT innodb_log_buffer_size=10M innodb_flush_neighbors=0 innodb_lock_wait_timeout=50 innodb_sync_array_size=16 transaction-isolation = READ-COMMITTED innodb_open_files=65535 open_files_limit=65535 innodb_autoinc_lock_mode = 2 # table table_definition_cache=8192 table_open_cache=8192 table_open_cache_instances=16 # thread and thread pool thread_stack=262144 thread_cache_size=256 # binlog and replication binlog_cache_size=5M binlog-format=ROW sync_binlog=1 expire_logs_days=7 log_slave_updates = 1 relay_log_info_repository=TABLE master_info_repository=TABLE relay_log_recovery=1 max_binlog_size=512M binlog-format=ROW slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN' # semi sync replication settings # new replication setting slave-parallel-type = LOGICAL_CLOCK slave-parallel-workers = 16 slave_preserve_commit_order=1 slave_transaction_retries=128 # gtid gtid_mode=ON enforce_gtid_consistency=ON binlog_gtid_simple_recovery = 1 binlog_checksum=NONE # slow log long_query_time=1 slow_query_log=1 skip-slave-start=1 #coms query_cache_type=0 query_cache_size=0 local-infile=1 max_allowed_packet=64M read_rnd_buffer_size=16M join_buffer_size=8M sort_buffer_size=2M read_buffer_size=4M open_files_limit=65535 lower_case_table_names=1 skip-name-resolve=1 skip-external-locking=1 safe-user-create #timeout connect_timeout=30 delayed_insert_timeout =300 innodb_rollback_on_timeout=OFF net_read_timeout=30 net_write_timeout=60 slave_net_timeout=30 #myisam concurrent_insert=2 key_buffer_size=8M myisam_sort_buffer_size=20M # START ConFIGURE server_id=3306106 max_connections=12000 max_user_connections=10000 max_connect_errors=35000 innodb_buffer_pool_size=2G innodb_io_capacity=200 innodb_io_capacity_max=400 # END ConFIGURE #skip-grant-tables [mysqld_safe] pid_file=/data/software/mysql_3306/tmp/mysql.pid #malloc-lib=/usr/lib/libjemalloc.so numa-interleave=1 EOF #初始化 ./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=${DB_base_DIR}/data cp /usr/local/mysql/support-files/mysql.server /data/software/mysql_3306/mysqld #将启动脚本复制到/data/software/mysql_3306/目录下 sed -i 's%^basedir=%basedir=/usr/local/mysql%' /data/software/mysql_3306/mysqld #修改启动脚本相关的basedir变量 sed -i 's%^datadir=%datadir=/data/software/mysql_3306/data%' /data/software/mysql_3306/mysqld #修改启动脚本相关的datadir变量 echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
- 将源码包上传至服务器,并执行以上脚本进行安装
source /etc/profile su - mysql -c "/data/software/mysql_3306/mysqld start" #这里使用mysql用户启动,切勿使用root4、使用systemd管理服务
cat > /lib/systemd/system/mysql.service << EOF [Unit] Description=mysql After=network.target [Service] Type=forking ExecStart=/data/software/mysql_3306/mysqld start ExecStop=/data/software/mysql_3306/mysqld stop [Install] WantedBy=multi-user.target EOF systemctl daemon-reload #重载使其生效5、启停
- 启动
systemctl start mysql
- 停止
systemctl stop mysql
- 重启
systemctl restart mysql6、为Zabbix授权数据库用户
# source /etc/profile # mysqladmin -uroot password 123 # mysql -u root -p123 mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; mysql> flush privileges; mysql> q4、P(PHP) 1、安装
- 上传源码包至/data/temp/目录下并解压
cd /data/temp/ tar -xf php-7.3.27.tar.gz
- 进入编译目录
cd php-7.3.27
- 安装依赖
yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel bzip2-devel
- 编译
./configure --prefix=/data/software/php7 --with-config-file-path=/data/software/php7/etc --with-openssl --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-bz2 --with-mysqli=mysqlnd --enable-fpm --with-pdo-mysql=mysqlnd --with-gd --enable-bcmath --with-gettext
- 安装
make && make install
- 生成配置文件
cp php.ini-production /data/software/php7/etc/php.ini cd /data/software/php7/etc/ cp php-fpm.conf.default php-fpm.conf cd php-fpm.d/ cp www.conf.default www.conf2、使用systemd管理服务
cat > /lib/systemd/system/php-fpm.service << EOF [Unit] Description=php-fpm After=network.target [Service] Type=forking ExecStart=/data/software/php7/sbin/php-fpm [Install] WantedBy=multi-user.target EOF systemctl daemon-reload #重载使其生效3、启停
- 启动
systemctl start php-fpm
- 停止
systemctl stop php-fpm
- 重启
systemctl restart php-fpm四、Zabbix-server部署 1、安装
- 上传源码包至/data/temp/目录下并解压
cd /data/temp/ tar -xf zabbix-5.2.6.tar.gz cd zabbix-5.2.6
- 创建Zabbix用户
groupadd zabbix useradd -g zabbix zabbix usermod -s /sbin/nologin zabbix
- 安装依赖
yum install -y libevent-devel wget tar gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel mysql-devel unixODBC-devel fping net-snmp-devel unixODBC-devel openssl-devel OpenIPMI-devel java-devel
- 编译
./configure --prefix=/data/software/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java
- 安装
make && make install2、使用systemd管理服务
cat > /lib/systemd/system/zabbix.service << EOF [Unit] Description=zabbix After=network.target [Service] Type=forking ExecStart=/data/software/zabbix/sbin/zabbix_server [Install] WantedBy=multi-user.target EOF systemctl daemon-reload #重载使其生效3、启停
- 启动
systemctl start zabbix.service
- 停止
systemctl stop zabbix.service
- 重启
systemctl restart zabbix.service五、配置修改及启动 1、数据库初始化Zabbix表
- 进入Zabbix解压目录中存放初始化SQL的目录
cd /data/temp/zabbix-5.2.6/database/mysql
- 使用前面创建的数据库用户zabbix导入初始化数据
mysql -u zabbix -pzabbix -D zabbix < schema.sql mysql -u zabbix -pzabbix -D zabbix < images.sql mysql -u zabbix -pzabbix -D zabbix < data.sql2、修改Nginx配置
- 进入配置文件所在目录并编辑配置文件
cd /data/software/nginx/conf/ vim nginx.conf
- Nginx基本配置如下:
worker_processes auto; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm index.php; } location /zabbix { root html/; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } 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
nginx -s reload3、前端部署
- 创建前端目录
mkdir -p /data/software/nginx/html/zabbix
- 拷贝前端文件
cp -r /data/temp/zabbix-5.2.6/ui/* /data/software/nginx/html/zabbix/4、修改Zabbix字体
为了避免出现以下情况:
我们可以修改Zabbix字体,具体步骤如下:
-
在本机找到控制面板——字体,找到自己喜欢的字体(这里以微软雅黑为例)
-
复制——粘贴到桌面
-
将字体上传至zabbix-server服务器的/data/software/nginx/html/zabbix/assets/fonts目录下,然后执行以下命令:
cd /data/software/nginx/html/zabbix/assets/fonts mv DejaVuSans.ttf DejaVuSans.ttf.bak mv msyh.ttc DejaVuSans.ttf
-
正常显示,效果如下
- 编辑Php配置文件
vim /data/software/php7/etc/php.ini
- 修改以下配置:
post_max_size =16M max_execution_time =300 max_input_time =300 mysqli.default_socket = /data/software/mysql_3306/tmp/mysql.sock6、修改Zabbix配置
- 修改/data/software/zabbix/etc/zabbix_server.conf配置如下:
# cat /data/software/zabbix/etc/zabbix_server.conf|grep -v "^#"|grep -v "^$" LogFile=/data/logs/zabbix_server.log DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix DBPort=3306 Timeout=4 LogSlowQueries=3000 User=zabbix StatsAllowedIP=127.0.0.1
-
附Zabbix_server.conf配置文件参数详解:
DBHost #数据库主机地址; DBName #数据库名称; DBPassword #数据库密码; DBPort #数据库端口,默认为3306; alertscriptsPath #告警脚本存放路径; CacheSize #存储监控数据的缓存; CacheUpdateFrequency #更新一次缓存时间; DebugLevel #日志级别; LogFile #日志文件; LogFileSize #日志文件大小,超过自动切割; LogSlowQueries #数据库慢查询记录,单位毫秒; PidFile #PID文件; ProxyConfigFrequency #Proxy被动模式下,Server多少秒同步配置文件至proxy; ProxyDataFrequency #被动模式下,Server间隔多少秒向proxy请求历史数据; StartDiscoverers #发现规则线程数; Timeout #连接Agent超时时间; TrendCacheSize #历史数据缓存大小; User #Zabbix运行的用户; HistoryCacheSize #历史记录缓存大小; ListenIP #监听本机的IP地址; ListenPort #监听端口; LoadModule #模块名称; LoadModulePath #模块路径。
-
Zabbix_Proxy.conf配置文件参数详解:
ProxyMode #Proxy工作模式,默认为主动模式,主动发送数据至Server; Server #指定Server端地址; ServerPort #Server端PORT; Hostname #Proxy端主机名; ListenPort #Proxy端监听端口; LogFile #Proxy代理端日志路径; PidFile #PID文件的路径; DBHost #Proxy端数据库主机名; DBName #Proxy端数据库名称; DBUser #Proxy端数据库用户; DBPassword #Proxy端数据库密码; DBSocket #Proxy数据库SOCKET路径; DBPort #Proxy数据库端口号; DataSenderFrequency #Proxy向Server发送数据的时间间隔; StartPollers #Proxy程池数量; StartDiscoverers #Proxy端自动发现主机的线程数量; CacheSize #内存缓存配置; StartDBSyncers #同步数据线程数; HistoryCacheSize #历史数据缓存大小; LogSlowQueries #慢查询日志记录,单位为毫秒; Timeout #超时时间。
-
Zabbix_agentd.conf配置文件参数详解:
EnableRemoteCommands #运行服务端远程至客户端执行命令或者脚本; Hostname #客户端主机名; ListenIP #监听的IP地址; ListenPort #客户端监听端口; LoadModulePath #模块路径; LogFile #日志文件路径; PidFile #PID文件名; Server #指定Server IP地址; ServerActive #Zabbix主动监控server的ip地址; StartAgents #Agent启动进程,如果设置为0,表示禁用被动监控; Timeout #超时时间 User #运行Zabbix的用户; UserParameter #用户自定义key; BufferSize #缓冲区大小; DebugLevel #Zabbix日志级别。
systemctl start nginx systemctl start php-fpm systemctl start zabbix.service8、访问Zabbix并初始化
-
浏览器访问:http://192.168.91.17/zabbix
-
语言选择中文
-
配置DB连接
-
自定义名称
-
时区选择亚洲/上海
-
安装前的汇总
-
按照下面提示下载并上传zabbix.conf.php配置文件到指定目录
-
使用默认账号密码登录:Admin/zabbix
-
上传源码包至/data/temp/目录下并解压
cd /data/temp/ tar -xf zabbix-5.2.6.tar.gz cd zabbix-5.2.6
-
编译
./configure --prefix=/data/software/zabbix-agent --enable-agent
-
安装
make && make install
-
修改/data/software/zabbix-agent/etc/zabbix_agentd.conf配置文件如下:
LogFile=/data/logs/zabbix_agentd.log #定义日志路径 Server=192.168.91.18 #被动模式服务器IP, 用于定义允许谁来采集数据 # StartAgents=3 #被动模式情况下, 预生成的子进程数, 默认为3. 如果设置为0, 将关闭被动模式 ServerActive=192.168.91.18 #主动模式服务器IP, 主动向谁上传数据 Hostname=192.168.91.17 #配置自己的主机名, 在后续配置监控项时要与此名称一致
cd /data/software/zabbix-agent/sbin/ ./zabbix_agentd
x-agent部署
1、安装-
上传源码包至/data/temp/目录下并解压
cd /data/temp/ tar -xf zabbix-5.2.6.tar.gz cd zabbix-5.2.6
-
编译
./configure --prefix=/data/software/zabbix-agent --enable-agent
-
安装
make && make install
-
修改/data/software/zabbix-agent/etc/zabbix_agentd.conf配置文件如下:
LogFile=/data/logs/zabbix_agentd.log #定义日志路径 Server=192.168.91.18 #被动模式服务器IP, 用于定义允许谁来采集数据 # StartAgents=3 #被动模式情况下, 预生成的子进程数, 默认为3. 如果设置为0, 将关闭被动模式 ServerActive=192.168.91.18 #主动模式服务器IP, 主动向谁上传数据 Hostname=192.168.91.17 #配置自己的主机名, 在后续配置监控项时要与此名称一致
cd /data/software/zabbix-agent/sbin/ ./zabbix_agentd七、配置指引
未完待续…
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)