環境:CentOS 6.4(最小化安裝)
php
執行截圖:html
#!/bin/bash #date:2015-6-14 #author:yfshare #mail:838554604@qq.com echo '' echo -e "\t###########################################################" echo -e "\t###\t\t\t\t\t\t\t###" echo -e "\t###\twelcome to use Zabbix&Nginx Install Scripts\t###" echo -e "\t###\tZabbix version:\t2.0.14\t\t\t\t###" echo -e "\t###\tRequirement:\t\t\t\t\t###" echo -e "\t###\tSystem:\t\tCentOS 6.x\t\t\t###" echo -e "\t###\tprocessor:\tx86_64\t\t\t\t###" echo -e "\t###\t\t\t\t\t\t\t###" echo -e "\t###########################################################" echo '' zabbix_filename="zabbix-2.0.14.tar.gz" nginx_filename="nginx-1.6.2.tar.gz" php_filename="php-5.3.8.tar.bz2" pcre_filename="pcre-8.12.tar.bz2" zlib_filename="zlib-1.2.7.tar.gz" openssl_filename="openssl-1.0.1c.tar.gz" function check_service() { network=`netstat -tunlp |grep ${1} |wc -l` Process=`ps -ef|grep ${1}|grep -v grep|wc -l` while true do if [ ${network} -ge 1 ] || [ ${Process} -ge 1 ];then echo -e "${1} started successfully" break else echo -e "${1} failed to start" /bin/sh $2 sleep 2 fi done } function Content() { read -p 'please input software path:' path read -p 'please input the install zabbix remote host ip address:' remote_ip read -p 'please input the Zabbix mysql database username:' zabbix_username read -p 'please input the Zabbix mysql database password:' zabbix_pass echo '' read -p 'Confirm input correctly [Y/N]?' key1 if [[ "${key1}" != 'Y' ]]||[[ ! "${path}" ]]||[[ ! "$remote_ip" ]]||[[ ! "$zabbix_username" ]]||[[ ! "zabbix_pass" ]];then echo -e 'Input error,Please rerun the ZABBIX setup script' exit 1 else echo 'Start installation...(Source installation about half an hour)' sed -i "/^#grant/agrant all privileges on zabbix.* to \'"$zabbix_username"\'@'localhost' identified by \'"$zabbix_pass"\'\;" "${path}"/conf/initial_database.sql sed -i "/^grant/agrant all privileges on zabbix\.\* to \'"$zabbix_username"\'\@\'"${remote_ip}"\' identified by \'"$zabbix_pass"\'\;" "${path}"/conf/initial_database.sql sed -i "/server_name/s/localhost/"$remote_ip"/g" "$path"/conf/nginx.conf exit 1 mkdir "${path}"/log log=""${path}"/log/install.log" yum -y install gcc gcc-c++ make>>${log} 2>&1 #install PHP yum -y install libxml2 libxml2-devel libjpeg-devel libpng-devel bzip2-devel libcurl-devel gd-devel >>${log} 2>&1 tar -jxvf "${path}"/"$php_filename" -C "${path}">>${log} 2>&1 cd "${path}"/`tar -jxvf "$php_filename"|head -n 1|awk -F/ '{print $1}'` ./configure --prefix=/usr/local/php --with-bz2 --with-curl --enable-ftp --enable-sockets --enable-bcmath --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local/photo --with-png-dir=/usr/local/photo --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1 cp php.ini-production /usr/local/php/lib/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf sed -i '/max_execution_time/s/30/300/' /usr/local/php/lib/php.ini sed -i '/post_max_size/s/8/16/' /usr/local/php/lib/php.ini sed -i '/max_input_time/s/60/300/' /usr/local/php/lib/php.ini sed -i '/^;date.timezone/adate.timezone \= \"Asia\/Shanghai\"' /usr/local/php/lib/php.ini sed -i '/^\;date\.timezone \=/d' /usr/local/php/lib/php.ini sed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.conf sed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf sed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf sed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local /usr/local/php/sbin/php-fpm check_service php "/usr/local/php/sbin/php-fpm" #install Nginx tar -jxvf "${path}"/"$pcre_filename" -C "${path}" >>${log} 2>&1 cd "${path}"/`tar -jxvf "${path}"/"$pcre_filename"|head -n 1|awk -F/ '{print $1}'` ./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1 tar -zxvf "${path}"/"$zlib_filename" -C "${path}" >>${log} 2>&1 cd "${path}"/`tar -zxvf "${path}"/"$zlib_filename"|head -n 1|awk -F/ '{print $1}'` ./configure >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1 tar -zxvf "${path}"/"$openssl_filename" -C "${path}" >>${log} 2>&1 cd "${path}"/`tar -zxvf "${path}"/"$openssl_filename"|head -n 1|awk -F/ '{print $1}'` ./config >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1 tar -zxvf "${path}"/"$nginx_filename" -C "${path}">>${log} 2>&1 cd "${path}"/`tar -zxvf "${path}"/"$nginx_filename"|head -n 1|awk -F/ '{print $1}'` ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre="${path}"/`tar -jxvf "${path}"/"$pcre_filename"|head -n 1|awk -F/ '{print $1}'` --with-zlib="${path}"/`tar -zxvf "${path}"/"$zlib_filename"|head -n 1|awk -F/ '{print $1}'` --with-openssl="${path}"/`tar -zxvf "${path}"/"$openssl_filename"|head -n 1|awk -F/ '{print $1}'` --with-http_stub_status_module >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1 cp "${path}"/conf/etc_init.d_nginx /etc/init.d/nginx chmod 775 /etc/init.d/nginx cp "${path}"/conf/nginx.conf /usr/local/nginx/conf chkconfig --add nginx chkconfig nginx on /etc/init.d/nginx start check_service nginx "/etc/init.d/nginx start" #install mysql yum -y install mysql* >>${log} 2>&1 /etc/init.d/mysqld start |tail -n 1 check_service mysqld "/etc/init.d/mysqld start" chkconfig mysqld on mysqladmin -uroot password redhat #install zabbix yum -y install net-snmp net-snmp-devel libxml2-devel libcurl-devel libssh2-devel OpenIPMI ipmitool OpenIPMI-devel *openjdk-devel >>${log} 2>&1 tar -zxvf "${path}"/"$zabbix_filename" -C "${path}">>${log} 2>&1 cd "${path}"/`tar -zxvf "${path}"/"$zabbix_filename"|head -n 1|awk -F/ '{print $1}'` zabbix_install=""${path}"/`tar -zxvf "${path}"/"$zabbix_filename"|head -n 1|awk -F/ '{print $1}'`" ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-ssh2 --with-openipmi --enable-java --enable-ipv6 >>${log} 2>&1 &&make >>${log} 2>&1 &&make install >>${log} 2>&1 useradd -s /sbin/nologin zabbix #initial database mysql -uroot -predhat < "${path}"/conf/initial_database.sql mysql -u"$zabbix_username" -p"$zabbix_pass" zabbix < ${zabbix_install}/database/mysql/schema.sql mysql -u"$zabbix_username" -p"$zabbix_pass" zabbix < ${zabbix_install}/database/mysql/p_w_picpaths.sql mysql -u"$zabbix_username" -p"$zabbix_pass" zabbix < ${zabbix_install}/database/mysql/data.sql cp ${zabbix_install}/misc/init.d/fedora/core/zabbix_* /etc/init.d/ chmod 775 /etc/init.d/zabbix_* sed -i '/LogFile/s/tmp/var\/log/' /usr/local/zabbix/etc/zabbix_server.conf sed -i "/^DBUser\=/s/root/"$zabbix_username"/" /usr/local/zabbix/etc/zabbix_server.conf sed -i '/DBPassword\=$/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf sed -i '/DBPassword\=$/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_server.conf sed -i "/DBPassword\=$/s/\=/&"$zabbix_pass"/g" /usr/local/zabbix/etc/zabbix_server.conf sed -i -e '/DBPort\=/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf -e '/DBPort\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_server.conf sed -i -e '/ListenPort\=/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf -e '/ListenPort\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_server.conf sed -i "/^Server/s/127.0.0.1/${remote_ip}/g" /usr/local/zabbix/etc/zabbix_agent.conf sed -i "/^Server/s/127.0.0.1/${remote_ip}/g" /usr/local/zabbix/etc/zabbix_agentd.conf sed -i "/^ServerActive/s/127\.0\.0\.1/${remote_ip}\:10051/g" /usr/local/zabbix/etc/zabbix_agentd.conf sed -i "/^Hostname/s/Zabbix server/${remote_ip}/g" /usr/local/zabbix/etc/zabbix_agentd.conf mkdir /usr/local/nginx/html/zabbix cp -rf ${zabbix_install}/frontends/php/* /usr/local/nginx/html/zabbix/ chown zabbix:zabbix /usr/local/nginx/html/zabbix/ -R chmod o+w /usr/local/nginx/html/zabbix/conf ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ touch /var/log/zabbix_server.log chown zabbix:zabbix /var/log/zabbix_server.log chmod 775 /var/log/zabbix_server.log cp "${path}"/simkai.ttf /usr/local/nginx/html/zabbix/fonts sed -i '/ZBX_FONT_NAME/s/DejaVuSans/simkai/g' /usr/local/nginx/html/zabbix/include/defines.inc.php sed -i '/ZBX_GRAPH_FONT_NAME/s/DejaVuSans/simkai/g' /usr/local/nginx/html/zabbix/include/defines.inc.php #Zabbix Agent config sed -i '/PidFile\=/s/^#//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/PidFile\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/^LogFile/s/tmp/var\/log/g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/EnableRemoteCommands\=/s/^#//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/EnableRemoteCommands\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/^EnableRemoteCommands/s/0/1/g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i "/^Server\=/s/127\.0\.0\.1/${remote_ip}/g" /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/ListenPort\=/s/^#//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/ListenPort\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/StartAgents\=/s/^#//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/StartAgents\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/StartAgents\=/s/3/8/g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i "/^ServerActive\=/s/127\.0\.0\.1/${remote_ip}:10051/g" /usr/local/zabbix/etc/zabbix_agentd.conf sed -i "/^Hostname\=/s/Zabbix server/`echo $HOSTNAME`/g" /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/^Timeout\=/s/^#//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/^Timeout\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_agentd.conf sed -i '/^Timeout\=/s/3/30/g' /usr/local/zabbix/etc/zabbix_agentd.conf touch /var/log/zabbix_agentd.log chown zabbix:zabbix /var/log/zabbix_agentd.log -R chmod 775 /var/log/zabbix_agentd.log /etc/init.d/zabbix_server start check_service zabbix_server "/etc/init.d/zabbix_server start" /etc/init.d/zabbix_agentd start check_service zabbix_agentd "/etc/init.d/zabbix_agentd start" chkconfig --add zabbix_server chkconfig --add zabbix_agentd chkconfig zabbix_server on chkconfig zabbix_agentd on touch /usr/local/nginx/logs/zabbix.access.log /etc/init.d/nginx reload sed -i '/^\:OUTPUT/a\-A INPUT \-p tcp \-m state \-\-state NEW \-m tcp \-\-dport 80 \-j ACCEPT' /etc/sysconfig/iptables sed -i '/^\:OUTPUT/a\-A INPUT \-p tcp \-m state \-\-state NEW \-m tcp \-\-dport 3306 \-j ACCEPT' /etc/sysconfig/iptables sed -i '/^\:OUTPUT/a\-A INPUT \-p tcp \-m state \-\-state NEW \-m tcp \-\-dport 10050 \-j ACCEPT' /etc/sysconfig/iptables sed -i '/^\:OUTPUT/a\-A INPUT \-p tcp \-m state \-\-state NEW \-m tcp \-\-dport 10051 \-j ACCEPT' /etc/sysconfig/iptables /etc/init.d/iptables restart >>${log} 2>&1 echo '' ip=`ip a|grep -o '\<[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\>'|grep -v 127|head -n 1` echo 'mysql database password for root is redhat' echo "installer log files are saved at "${path}"/log/install.log,Thanks for Using" echo 'Zabbix Server listen port:10051;Zabbix Agent listen port:10050' echo "please input in Configuration-->Hosts-->Create Host--->Host name:`echo ${HOSTNAME}`" echo "Access http://${ip}/zabbix configuration zabbxi" echo '' fi } # ret_code=`curl -I -s --connect-timeout 15 www.baidu.com -w %{http_code}|tail -n 1` System=`cat /proc/version |grep -io Centos` ID=`cat /proc/version |awk -F'(' '{print $1}'` processor=`uname -p` if [[ ${ret_code} != '200' ]];then echo '' echo -e "\033[31;49;1m[Error]Network exception, please try again\033[39;49;0m" exit 1 else if [[ ${System} != 'centos' ]] || [[ ${processor} != 'x86_64' ]];then echo 'Warn message:' echo -e "The current operation system:${ID} is not in the system support list\nSystem environment check fails, it may affect the program to run" read -p "Ignored the warning messages [Y/N]? " key if [[ ${key} != [Yy] ]];then echo -e "\033[31;49;1mThanks for using\033[39;49;0m" echo '' else echo '' echo -e "\033[31;49;1mBegin...\033[39;49;0m" Content exit 1 fi else echo '' echo -e "\033[31;49;1mBegin...\033[39;49;0m" Content exit 1 fi fi