zabbix学习1--zabbix6.x单机

文章目录

  • 1. 环境
  • 2. MYSQL8.0
    • 2.1 单节点
    • 2.2 配置主从
  • 3. 依赖组件
  • 4. zabbix-server
  • 5. agent
    • 5.1 yum
    • 5.2 编译
  • 附录
    • my.cnf
    • JDK
    • 默认端口号

1. 环境

进入官网查看所需部署环境配置以及应用版本要求https://www.zabbix.com/documentation/current/zh/manual/installation/requirements
zabbix学习1--zabbix6.x单机_第1张图片
zabbix学习1--zabbix6.x单机_第2张图片
zabbix学习1--zabbix6.x单机_第3张图片

2. MYSQL8.0

2.1 单节点

# 获取mysql
wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm 
rpm -ivh mysql80-community-release-el7-7.noarch.rpm  
yum clean all;yum makecache

# 安装mysql
yum install -y mysql-community-server mysql-community-devel \
   mysql-community-libs

# 启动
systemctl start mysqld  
systemctl status mysqld  
systemctl enable mysqld  

# 获取初始密码
cat /var/log/mysqld.log|grep password|rev|cut -d ':' -f1|rev|sed 's/ //g'         

# 修改密码
# mysql -uroot -p
> alter user root@'localhost' identified by 'Honops@123';
> flush privileges;

# 配置
systemctl stop mysqld 
1. 备份原配置
    cp /etc/my.cnf /etc/my.cnf.bk
2. 删除或mv原来最初数据
    rm /var/lib/mysql/* /var/log/mysqld.log -rf  
3. 创建路径
    mkdir -p /data/mysql/{install,data,log,run}
    chown -R mysql:mysql /data/mysql/{install,data,log,run}
    mkdir -p /data/mysql/log/{binlog,relaylog}
    chown mysql.mysql -R /data/mysql/log/{binlog,relaylog}
4. 创建配置文件,信息如【附录】,注意修改ip、id等
5. 初始化
    mysqld --initialize  --user=mysql 
6. 启动mysql
    systemctl start mysqld  
    systemctl status mysqld  
7. 获取初始密码/修改默认密码
【获取初始密码如上;日志文件:/data/mysql/log/mysqld.log】
    mysql  -uroot --socket=/data/mysql/run/mysql.socket -p
    > alter user root@'localhost' identified by 'Honops@123';
    > CREATE USER 'root'@'192.168.20.61' IDENTIFIED BY 'Honops@123'; 
    > GRANT all PRIVILEGES on *.* to 'root'@'192.168.20.61';      
    > flush privileges;


给予grant_priv(GRANT OPTION)权限
> select user,host,grant_priv from mysql.user where user="root";
> update  mysql.user set grant_priv="Y"  where user="root" and host="192.168.20.61";
> flush privileges;

2.2 配置主从

配置主从 
master主机执行
> CREATE USER 'repl'@'%' IDENTIFIED BY 'Slave123'; 
> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
> ALTER USER 'repl'@'%' IDENTIFIED WITH mysql_native_password BY 'Slave123';
> flush privileges;
> show master status;
slave主机执行
> change master to master_host='master主机ip',master_user='repl',
  -> master_password='Slave123', master_log_file='xxxx.xxxx',
  -> master_log_pos=xxxxx;
> start slave;
> show slave status\G

3. 依赖组件

#Nginx的yum源
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

#安装Nginx
# yum install nginx -y

# 替换epel源和新加webtatic源
yum install epel-release.noarch -y
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm

#安装PHP  
yum -y install php74-php-xml php74-php-mysqlnd php74-php-bcmath   \
php74-php-mbstring php74-php-ldap php74-php-gd  php74-php-cli php74-php-fpm 

//cp /etc/php.ini /etc/php.ini.zabbixbak
cp /etc/opt/remi/php74/php.ini /etc/opt/remi/php74/php.ini.bk
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/opt/remi/php74/php.ini
sed -i '/max_input_time =/s/60/300/' /etc/opt/remi/php74/php.ini
sed -i '/mbstring.func_overload = 0/a\mbstring.func_overload = 1' /etc/opt/remi/php74/php.ini
sed -i '/post_max_size =/s/8M/32M/' /etc/opt/remi/php74/php.ini
sed -i '/;date.timezone =/a\date.timezone = Asia/Shanghai' /etc/opt/remi/php74/php.ini

# 启动
systemctl enable nginx  php74-php-fpm  --now 

# 获取源码包
       【https://www.zabbix.com/cn/download_sources】
mkdir -p /data/zabbix/{data,install,logs,php}
mkdir -p /var/run/zabbix
tar xf zabbix-6.4.3.tar.gz -C /data/zabbix/install/ 
cd /data/zabbix/install && mv zabbix-6.4.3/* . 

# 初始化mysql
> create database zabbix charset utf8 collate utf8_bin;
> CREATE USER 'zabbix'@'192.168.20.61' IDENTIFIED BY 'Zabb@321'; 
> GRANT all PRIVILEGES on zabbix.* to 'zabbix'@'192.168.20.61';   
> CREATE USER 'zabbix'@'localhost' IDENTIFIED BY 'Zabb@321'; 
> GRANT all PRIVILEGES on zabbix.* to 'zabbix'@'localhost';   
> CREATE USER 'zabbix'@'192.168.20.62' IDENTIFIED BY 'Zabb@321'; 
> GRANT all PRIVILEGES on zabbix.* to 'zabbix'@'192.168.20.62';   
> flush privileges;
> use zabbix;
> source /data/zabbix/install/database/mysql/schema.sql
> source /data/zabbix/install/database/mysql/images.sql 
> source /data/zabbix/install/database/mysql/data.sql
> source /data/zabbix/install/database/mysql/double.sql 
> source /data/zabbix/install/database/mysql/history_pk_prepare.sql

zabbix学习1--zabbix6.x单机_第4张图片

4. zabbix-server

# yum依赖
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 gcc gcc-c++ unixODBC-devel \
gnutls-devel  gnutls   		

groupadd zabbix
useradd zabbix -g zabbix
echo "Os@pass12"| passwd --stdin zabbix

# 安装[安装jdk,见附录]
cd /data/zabbix/install 
export CFLAGS="-std=gnu99"
./configure --prefix=/data/zabbix/data --enable-server \
--with-mysql=/usr/bin/mysql_config  \
--with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib \
 --with-libpthread --with-libevent --with-openssl --with-ldap \
 --with-libcurl --with-libpcre  --enable-java --with-unixodbc \
 --with-jabber  
 #--with-gnutls
 
make install

# 配置文件
chown zabbix.zabbix /data/zabbix/{data,logs}/ -R 
chown zabbix.zabbix /var/run/zabbix/ -R 
cd /data/zabbix/data/etc/
cp zabbix_server.conf    zabbix_server.conf.bk 

ListenPort=10051
LogFile=/data/zabbix/logs/zabbix_server.log  
DBHost=192.168.20.61
DBName=zabbix
DBUser=zabbix
DBPassword=Zabb@321
DBPort=3306
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
CacheSize=2048M
HANodeName=zab1
NodeAddress=192.168.20.61:10051
SocketDir=/var/run/zabbix
PidFile=/var/run/zabbix/zabbix_server.pid    

# 启动
# vi /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=mysqld.service

[Service]
User=zabbix
Group=zabbix
Environment="CONFFILE=/data/zabbix/data/etc/zabbix_server.conf"
Type=forking
PIDFile=/var/run/zabbix/zabbix_server.pid
Restart=on-failure
KillMode=control-group
ExecStart=/data/zabbix/data/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
 
[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start zabbix-server
systemctl status zabbix-server
systemctl enable zabbix-server


#####
# 替换zabbix前端
cp  -r /data/zabbix/install/ui/* /data/zabbix/php/

# 配置nginx
vi /etc/nginx/conf.d/conn.conf  
server {                                                                                                                                                     
    listen       80;                                                                                                                                     
    server_name  192.168.20.61;                                                                                                                          
location / {                                                                                                                                                 
    root /data/zabbix/php;                                                                                                                          
    try_files $uri $uri/ /index.php?query_string;                                                                                                   
    index index.php index.html index.htm;                                                                                                           
    }                                                                                                                                                    
location ~ .php$ {                                                                                                                                           
    root   /data/zabbix/php;                                                                                                                         
    fastcgi_pass   127.0.0.1:9000;                                                                                                                   
    fastcgi_index  index.php;                                                                                                                        
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                                                                                
    include        fastcgi_params;                                                                                                                   
    }                                                                                                                                                    
}  

重启nginx后
访问ip/zabix
配置并下一步
Zabbix图形会出现无法显示中文字体的情况 :

windows的字体路径C:\Windows\Fonts  随便【中文】字体
替换  /data/zabbix/php/assets/fonts/DejaVuSans.ttf  名称保留DejaVuSans
之后刷新页面

5. agent

5.1 yum

rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/7/x86_64/zabbix-release-latest.el7.noarch.rpm        
yum repolist   
  
yum install zabbix-agent2 -y

cp /etc/zabbix/zabbix_agent2.conf  /etc/zabbix/zabbix_agent2.conf.bk 

https://zhuanlan.zhihu.com/p/322151059
修改配置:
Server=192.168.20.61 
ServerActive=192.168.20.61 
Hostname=zab1 

【注意,ServerActive在ha模式时候,用;分隔】

systemctl enable zabbix-agent2  --now 

5.2 编译

# yum install go -y  

mkdir -p /data/zabbix_agent/{data,logs,install}
mkdir -p /var/run/zabbix_agent

tar xf zabbix-6.4.3.tar.gz -C /data/zabbix_agent/install/ 
cd /data/zabbix_agent/install && mv zabbix-6.4.3/* . 

cd /data/zabbix_agent/install 
export CFLAGS="-std=gnu99"
./configure --prefix=/data/zabbix_agent/data  --enable-agent2 
make install

# 配置文件
chown zabbix.zabbix /data/zabbix_agent/{data,logs}/ -R 
chown zabbix.zabbix /var/run/zabbix_agent/ -R 
cd /data/zabbix_agent/data/etc/
cp zabbix_agent2.conf   zabbix_agent2.conf.bk
修改配置:
Server=192.168.20.64
ServerActive=192.168.20.64 
Hostname=pro



# vi /usr/lib/systemd/system/zabbix-agent2.service
[Unit]
Description=Zabbix Agent 2
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/data/zabbix_agent/data/etc/zabbix_agent2.conf"
Type=simple
Restart=on-failure
PIDFile=/var/run/zabbix_agent/zabbix_agent2.pid 
KillMode=control-group
ExecStart=/data/zabbix_agent/data/sbin/zabbix_agent2 -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
LimitNOFILE=8192

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start zabbix-agent2
systemctl status zabbix-agent2
systemctl enable zabbix-agent2

附录

my.cnf

[mysqld]
character-set-server=utf8
datadir=/data/mysql/data
socket=/data/mysql/run/mysql.socket
bind-address=192.168.30.51
port=3306
user=mysql
slow_query_log=1
slow_query_log_file=/data/mysql/log/slow-query.log
log-error=/data/mysql/log/mysqld.log
max_connections=1000
sql_mode=''
expire_logs_days = 3 
#开启 GTID
gtid_mode=ON
enforce_gtid_consistency=ON
# innodb
default-storage-engine=innodb
innodb_buffer_pool_size=4086M
innodb_data_file_path=ibdata1:1G:autoextend
innodb_file_per_table=1
innodb_flush_log_at_trx_commit=0
innodb_lock_wait_timeout=50
innodb_log_buffer_size=32M
innodb_log_file_size=256M
innodb_log_files_in_group=4
innodb_strict_mode=off
innodb_thread_concurrency=16
interactive_timeout=10800
key_buffer_size=64M
log_bin=/data/mysql/log/binlog/binlog.bin
log_bin_trust_function_creators=1
log_error_verbosity=1
log_slave_updates=1
log_slow_admin_statements=ON
log_timestamps=SYSTEM
long_query_time=1
max_allowed_packet=256M
max_binlog_size=256M
max_connect_errors=99999999
myisam_sort_buffer_size=64M
net_read_timeout=999
net_write_timeout=999
performance_schema=OFF
read_buffer_size=2M
relay_log_recovery=1
relay-log=/data/mysql/log/relaylog/relay-log.bin
replicate-wild-ignore-table=mysql.%
secure_file_priv=
skip-external-locking
skip-name-resolve
skip-symbolic-links
slave_compressed_protocol=1
slave_exec_mode=idempotent
slave_parallel_workers=0
sort_buffer_size=2M
stored_program_cache=1024
sync_binlog=0
table_open_cache=2000
thread_cache_size=8
wait_timeout=10800
server-id=1

JDK

mkdir -p /jdk
vi + /etc/profile
#new add
export JAVA_HOME=/jdk/TencentKona-11.0.14.b1
export JAVA_BIN=/jdk/TencentKona-11.0.14.b1/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

source /etc/profile

默认端口号

zabbix学习1--zabbix6.x单机_第5张图片

你可能感兴趣的:(自动运维,zabbix,学习)