centos 7 版本 + apache
[root@modelmachine ~] # mysql_secure_installation (安全初始化)简单的进行数据库优化,移除不必要的数据库和表 5.7之后的版本就没有test数据库了 Securing the MySQL server deployment. Enter password for user root: //当前root用户密码 The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 0 Change the password for root ? ((Press y|Y for Yes, any other key for No) : n //是否改变当前root用户密码 ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y //是否移除匿名用户 Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y //禁用root用户远程登录 Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y //是否删除test数据库并访问它 - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y //是否立即重新加载权限表 Success. All done!
可以使用脚本安装
[root@modelmachine ~] # vim zabbixinstall.sh #!/usr/bin/bash #httpd + zabbix 安装脚本 yum makecache fast yum -y install systemctl start mysqld echo "validate_password=off" >> /etc/my.cnf systemctl restart mysqld passwd=$(cat /var/log/mysqld.log | grep password | awk 'NR==1{print $11}') mysqladmin -uroot -p"$passwd" password 1 rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm yum clean all yum makecache fast yum install zabbix-server-mysql zabbix-agent -y yum install centos-release-scl -y sed -i '11s/0/1/' /etc/yum.repos.d/zabbix.repo yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y mysql -uroot -p1 -e "create database zabbix character set utf8 collate utf8_bin;" mysql -uroot -p1 -e "create user zabbix@localhost identified by 'password';" mysql -uroot -p1 -e "grant all privileges on zabbix.* to zabbix@localhost;" mysql -uroot -p1 -e "set global log_bin_trust_function_creators = 1;" zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -ppassword zabbix mysql -uroot -p1 -e "set global log_bin_trust_function_creators = 0;" echo "DBPassword=password" >> /etc/zabbix/zabbix_server.conf sed -i 's/Europe\/Riga/Asia\/Shanghai/' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
以下是脚本解释
#!/usr/bin/bash #httpd + zabbix 安装脚本 #首先自行安装MySQL systemctl start mysqld #启动服务 echo "validate_password=off" >> /etc/my.cnf #修改弱密码策略 systemctl restart mysqld #重启服务 passwd=$(cat /var/log/mysqld.log | grep password | awk 'NR==1{print $11}') #将密码设置为变量 mysqladmin -uroot -p"$passwd" password 1 #更改密码 rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm #配置zabbix的yum源 yum clean all #清理缓存 yum install zabbix-server-mysql zabbix-agent -y yum install centos-release-scl -y sed -i '11s/0/1/' /etc/yum.repos.d/zabbix.repo //修改为enabled为1,开启状态 yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y mysql -uroot -p1 -e "create database zabbix character set utf8 collate utf8_bin;" #创建数据库设置语言格式 mysql -uroot -p1 -e "create user zabbix@localhost identified by 'password';" #创建用户并设置密码 mysql -uroot -p1 -e "grant all privileges on zabbix.* to zabbix@localhost;" #给zabbix用户授权 mysql -uroot -p1 -e "set global log_bin_trust_function_creators = 1;" #启用 MySQL 中的 log_bin_trust_function_creators 全局系统变量。MySQL 会信任函数/存储过程的创建者, zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -ppassword zabbix #解压缩并导入数据 mysql -uroot -p1 -e "set global log_bin_trust_function_creators = 0;" #导入数据之后再将其禁用 echo "DBPassword=password" >> /etc/zabbix/zabbix_server.conf #给配置文件中加入密码选项 sed -i 's/;Europe\/Riga/Asia\/Shanghai/' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf #修改时区 systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm #重启服务 systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
agent端安装
# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm # yum clean all # yum install zabbix-agent # systemctl restart zabbix-agent # systemctl enable zabbix-agent 修改配置文件 vim /etc/zabbix/zabbix_agentd.conf Server=server端的IP地址 ServerActive=server端的IP地址 Hostname=agent的主机名 UnsafeUserParamete