新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
目的
成都创新互联主营仁寿网站建设的网络公司,主营网站建设方案,成都app软件开发公司,仁寿h5微信小程序搭建,仁寿网站营销推广欢迎仁寿等地区企业咨询
一键自动化安装zabbix服务。
环境
OS:CentOS 6.2
zabbix版本:2.2.4
配置
#!/bin/bash # 脚本名称:一键自动化安装zabbix服务 # 注意事项: # 1.该脚本仅在CentOS最小化安装环境中测试成功,不一定适用于其他环境。 # 2.如需修改MySQL数据库的root和zabbix用户的密码,请注意修改下面这两个变量! mysql_user_root_password="redhat" mysql_user_zabbix_password="zabbix" echo -n "正在关闭SELinux……" setenforce 0 > /dev/null 2>&1 sed -i '/^SELINUX=/s/=.*/=disabled/' /etc/selinux/config && echo "OK" echo -n "正在配置iptables防火墙……" iptables -F iptables -X iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT iptables -A INPUT -p icmp -j ACCEPT iptables -A INPUT -i lo -j ACCEPT iptables -P INPUT DROP iptables -P FORWARD DROP service iptables save > /dev/null 2>&1 && echo "OK" echo -n "正在安装zabbix的相关软件……" yum -y install make gcc httpd mysql-server mysql-devel net-snmp-devel libcurl-devel php php-mysql php-bcmath php-mbstring php-gd php-xml wget > /dev/null 2>&1 && echo "OK" echo -n "正在添加zabbix用户……" useradd -M -s /sbin/nologin zabbix && echo "OK" echo -n "正在启动mysqld服务……" service mysqld start > /dev/null 2>&1 && echo "OK" echo -n "正在为mysql的root用户设置密码……" mysqladmin -uroot password $mysql_user_root_password && echo "OK" echo "正在执行mysql语句……" mysql -uroot -p$mysql_user_root_password -e "create database zabbix character set utf8" && echo "已执行1/2" mysql -uroot -p$mysql_user_root_password -e "grant all privileges on zabbix.* to zabbix@localhost identified by '$mysql_user_zabbix_password'" && echo "已执行2/2" echo -n "正在下载zabbix源码包……" wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.4/zabbix-2.2.4.tar.gz > /dev/null 2>&1 && echo "OK" echo -n "正在解压……" tar zxf zabbix-2.2.4.tar.gz > /dev/null 2>&1 && echo "OK" echo -n "正在安装……" cd zabbix-2.2.4 && ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl > /dev/null 2>&1 && make install > /dev/null 2>&1 && echo "OK" echo "正在导入数据库……" mysql -uzabbix -p$mysql_user_zabbix_password zabbix < $PWD/database/mysql/schema.sql && echo "已完成1/3" mysql -uzabbix -p$mysql_user_zabbix_password zabbix < $PWD/database/mysql/images.sql && echo "已完成2/3" mysql -uzabbix -p$mysql_user_zabbix_password zabbix < $PWD/database/mysql/data.sql && echo "已完成3/3" echo -n "正在复制zabbix_server和zabbix_agentd服务到/etc/init.d/目录……" cp $PWD/misc/init.d/fedora/core/zabbix_* /etc/init.d/ && echo "OK" echo -n "正在复制php网页数据到/var/www/html/zabbix目录……" cp -R $PWD/frontends/php/ /var/www/html/zabbix && echo "OK" echo -n "正在修改/usr/local/zabbix/etc/zabbix_server.conf文件……" sed -i '/^DBUser=/s/=.*/=zabbix/;/DBPassword=/s/$/\n\nDBPassword=zabbix/' /usr/local/zabbix/etc/zabbix_server.conf && echo "OK" echo -n "正在修改/etc/init.d/zabbix_server和/etc/init.d/zabbix_agentd文件……" sed -i '/BASEDIR=/s/$/\/zabbix/' /etc/init.d/zabbix_* && echo "OK" echo -n "正在修改/etc/httpd/conf/httpd.conf文件……" sed -i '/^DirectoryIndex/s/$/ index.php/' /etc/httpd/conf/httpd.conf && echo "OK" echo -n "正在修改/etc/php.ini文件……" sed -i '/^post_max_size/s/= .*/= 16M/;/^max_execution_time/s/= .*/= 300/;/^max_input_time/s/= .*/= 300/;/^;date.timezone/{s/;//;s/$/ Asia\/Shanghai/}' /etc/php.ini && echo "OK" echo -n "正在修改/var/www/html/zabbix/conf/zabbix.conf.php文件……" cp /var/www/html/zabbix/conf/zabbix.conf.php.example /var/www/html/zabbix/conf/zabbix.conf.php sed -i 's/zabbix_password/'$mysql_user_zabbix_password'/' /var/www/html/zabbix/conf/zabbix.conf.php echo "OK" echo "正在添加服务到自动启动……" chkconfig --add mysqld && chkconfig mysqld on && echo "mysqld服务已添加到自动启动" chkconfig httpd on && echo "httpd服务已添加到自动启动" chkconfig --add zabbix_server && chkconfig zabbix_server on && echo "zabbix_server服务已添加到自动启动" chkconfig --add zabbix_agentd && chkconfig zabbix_agentd on && echo "zabbix_agentd服务已添加到自动启动" echo "正在启动服务……" service httpd start > /dev/null 2>&1 && echo "httpd服务已启动" service zabbix_server start > /dev/null 2>&1 && echo "zabbix_server服务已启动" service zabbix_agentd start > /dev/null 2>&1 && echo "zabbix_agentd服务已启动"