- 环境:
192.168.117.132——zabbix server
192.168.117.133——zabbix proxy - 安装路径为/zabbix
- 安装mysql
1.安装包下载
https://dev.mysql.com/downloads/mysql/
此次使用的二进制版5.7.31
2.安装依赖
yum install -y libaio-devel numactl-libs
3.添加用户
useradd -m mysql
4.创建目录
mkdir /zabbix/mysql/ mkdir /zabbix/mysql/data mkdir /zabbix/mysql/logs
5.解压安装包
tar -xf mysql-5.7.31-el7-x86_64.tar.gz mv mysql-5.7.31-el7-x86_64 /zabbix/mysql/mysql
6.编辑配置文件
cat > /etc/my.cnf << EOF [client] default-character-set = utf8 port = 3306 socket = /zabbix/mysql/logs/mysql.sock [mysqld] character-set-server = utf8 basedir = /zabbix/mysql datadir = /zabbix/mysql/data bind-address = 192.168.117.132 port = 3306 socket = /zabbix/mysql/logs/mysql.sock skip-external-locking skip-name-resolve key_buffer_size = 16M max_allowed_packet = 128M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M max_connections=1000 event_scheduler=ON innodb_file_per_table=1 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash default-character-set = utf8 [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M EOF #修改配置文件权限 chown mysql.mysql /etc/my.cnf
7.初始化
#复制二进制文件至全局变量中 cp /zabbix/mysql/mysql/bin/* /usr/sbin/ #修改数据目录和日志目录的所属用户 chown mysql.mysql /zabbix/mysql/data /zabbix/mysql/logs #执行初始化 mysqld --initialize-insecure --user=mysql --explicit_defaults_for_timestamp
#此时会创建root@localhost,密码为空。直接输入mysql后回车即可进入
8.添加systemctl
cat > /usr/lib/systemd/system/mysqld.service << EOF [Unit] Description=MySQL Server Documentation=man:mysqld(7) Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql Type=forking PIDFile=/zabbix/mysql/logs/mysqld.pid TimeoutSec=0 ExecStart=/zabbix/mysql/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize --pid-file=/zabbix/mysql/logs/mysqld.pid LimitNOFILE = 5000 Restart=on-failure RestartPreventExitStatus=1 PrivateTmp=false EOF
9.启动mysql
systemctl start mysqld
#添加开机启动
systemctl enable mysqld
10.设置root@ip用户密码
mysql> GRANT ALL ON *.* TO ‘root‘@‘192.168.117.132‘ IDENTIFIED BY ‘paasword‘;
11.添加zabbix用户,数据,授权
mysql> CREATE DATABASE zabbix character set utf8 collate utf8_bin; mysql> GRANT ALL ON zabbix.* TO ‘zabbix‘@‘localhost‘ IDENTIFIED BY ‘zabbxpasswd‘;
至此mysql安装完成