一键安装zabbix


一键安装zabbix

该脚本使用linux的shell脚本编写
以下为脚本内容;

#!/bin/bash
db_user="root"
db_password=""
db_host="localhost"
db_port="3306"
zbx_db_name="zabbix"
zbx_db_user="zabbix"
zbx_db_password="123"
zabbix_server_ip="127.0.0.1"

zabbix_repo(){
echo '  
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/zabbix/4.2/rhel/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/zabbix/4.2/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=0

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0' > /etc/yum.repos.d/zabbix.repo
}
mysql_connect="mysql -u$db_user --password="$db_password" -h$db_host -P$db_port"
# install mariadb
install_mariadb(){
	yum -y install mariadb mariadb-server
	systemctl start mariadb 
	systemctl enable mariadb
	$mysql_connect -e "create database if not exists $zbx_db_name character set utf8 collate utf8_bin;"   
	$mysql_connect -e "grant all on zabbix.* to '$zbx_db_user'@'localhost' identified by '$zbx_db_password';" 
}
config_web(){
	cp  /usr/share/zabbix/conf/zabbix.conf.php.example  /etc/zabbix/web/zabbix.conf.php
	sed -i "/DATABASE/s/zabbix/$zbx_db_name/" /etc/zabbix/web/zabbix.conf.php
	sed -i "/USER/s/zabbix/$zbx_db_user/" /etc/zabbix/web/zabbix.conf.php
	sed -i "/PASSWORD/s/''/'$zbx_db_password'/" /etc/zabbix/web/zabbix.conf.php
	chown apache.apache /etc/zabbix/web/zabbix.conf.php
}
# install zabbix server
install_zabbix(){
	server_cfg=/etc/zabbix/zabbix_server.conf
	yum -y install zabbix-server-mysql zabbix-web-mysql 
	sed -i "/^DBUser/s/root/$zbx_db_user/" $server_cfg
	sed -i "/# DBPassword/aDBPassword=$zbx_db_password" $server_cfg
    sed -i '/date.timezone/aphp_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
	zcat /usr/share/doc/zabbix-server-mysql-4.2.8/create.sql.gz | mysql zabbix
	config_web
	systemctl enable httpd zabbix-server
	systemctl start httpd zabbix-server

}

# install zabbix agent
install_agent(){

   yum -y install zabbix-agent
   sed -i "/^Server/s/127.0.0.1/$zabbix_server_ip/"  /etc/zabbix/zabbix_agentd.conf
   systemctl enable zabbix-agent
   systemctl start zabbix-agent
}
zabbix_repo
install_mariadb
install_zabbix 
install_agent
echo "zabbix部署完毕,请使用浏览器访问: http://$(hostname -I | awk '{print $1}')/zabbix"
echo zabbix_user="Admin"
echo zabbix_password="zabbix"
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页