您好,登錄后才能下訂單哦!
目的
一鍵自動化安裝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服務已啟動"
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。