zabbix一键安装脚本



#/bin/sh

#卸载mariadb

rpm -e --nodeps `rpm -qa|grep mariadb*`


#a. Install Zabbix repository
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all

#替换阿里云镜像源
sed -i 's/repo.zabbix.com/mirrors.aliyun.com\/zabbix/g' /etc/yum.repos.d/zabbix.repo

#b. Install Zabbix server and agent
yum install -y zabbix-server-mysql zabbix-agent

#c. Install Zabbix frontend
#Enable Red Hat Software Collections
yum install -y centos-release-scl


#编辑配置文件 /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository.
sed -i '11s/enabled=0/enabled=1/' /etc/yum.repos.d/zabbix.repo

#Install Zabbix frontend packages.
yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl


#安装mysql数据库
#配置清华大学yum源,默认安装最新,安装指定版本可以将其他版本的enabled修改为0


#下载GPG-KEY导入rpm,防止报错
curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql https://repo.mysql.com/RPM-GPG-KEY-mysql
rpm --import /etc/pki/rpm-gpg/RPM*
cat > /etc/yum.repos.d/mysql-community.repo <<EOF
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


[mysql-5.6-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-\$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-\$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-\$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
EOF

yum makecache

#数据库默认安装mysql8.0

yum -y install mysql-server

systemctl start mysqld
systemctl enable mysqld

echo "mysql安装完成"

#数据库操作,更改root密码
#获取安装时的临时密码赋值给mysql_pwd

old_pwd=`grep 'temporary password' /var/log/mysqld.log |rev|cut -c-12|rev`
#mysql_pwd=Zabbix@12345
new_pwd=Zabbix@123
#修改root密码
mysql --connect-expired-password -uroot -p"$old_pwd" -e "alter user 'root'@'localhost' identified by '$new_pwd';" 2> /dev/null
mysql --connect-expired-password -uroot -p$new_pwd -e "flush privileges;" 2> /dev/null

#创建数据库zabbix
mysql --connect-expired-password -uroot -p$new_pwd -e "create database zabbix character set utf8 collate utf8_bin;" 2> /dev/null
#创建zabbix用户
mysql --connect-expired-password -uroot -p$new_pwd -e "create user zabbix@localhost identified by 'Zabbix@12345';" 2> /dev/null
#赋予权限
mysql --connect-expired-password -uroot -p$new_pwd -e "grant all privileges on zabbix.* to zabbix@localhost;" 2> /dev/null

mysql --connect-expired-password -uroot -p$new_pwd -e "flush privileges;" 2> /dev/null

echo "数据库账号设置完成"


#导入初始架构
#编辑/usr/share/doc/zabbix-server-mysql*/create.sql.gz在首行添加use zabbix;
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pZabbix@12345 zabbix 2> /dev/null

echo "数据导入完成"

#编辑配置文件 /etc/zabbix/zabbix_server.conf
sed -i '/DBPassword=/aDBPassword=Zabbix@12345' /etc/zabbix/zabbix_server.conf

#为Zabbix前端配置PHP
sed -i 's#^.*date.timezone.*$#php_value[date.timezone] = Asia/Shanghai#g' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

#启动Zabbix server和agent进程,并为它们设置开机自启
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm

systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm


配置清华大学grafana源
cat > /etc/yum.repos.d/grafana.repo << EOF
[grafana]
name=grafana
baseurl=https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm
repo_gpgcheck=0
enabled=1
gpgcheck=0
EOF

yum makecache

yum -y install grafana

#安装zabbix插件
grafana-cli plugins install alexanderzobnin-zabbix-app

#启动grafana
systemctl start grafana-server
systemctl enable grafana-server

# close ELINUX,firewall
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
echo "enforce `getenforce`"

ip=$(ifconfig|grep inet|awk '{print $2}'|head -n1)
echo "登录地址zabbix http://$ip/zabbix/
登录地址grafana http://$ip:3000
zabbix默认账号Admin/zabbix
grafana默认账号admin/admin
mysql数据库 root密码:$new_pwd
zabbix数据库的用户密码:Zabbix@12345
"|tee pwdlog.txt

经反复修改,多次测试修改,可用,版本为zabbix5.0+mysql+grafana

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zyfsky666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值