1 #!/bin/bash 2 #auto make install LAMP+Cacti 3 #by authors zhang 2016 4 5 #RRDtool define path variable 6 R_FILES=rrdtool-1.4.8.tar.gz 7 R_FILES_DIR=rrdtool-1.4.8 8 R_PREFIX=/usr/src/rrdtool-1.4.8/ 9 10 11 #Cacti define path variable 12 C_FILES=cacti-0.8.8b.tar.gz 13 C_FILES_DIR=cacti-0.8.8b 14 C_PREFIX=/usr/src/cacti-0.8.8b/ 15 16 #httpd define path variable 17 H_FILES=httpd-2.2.17.tar.gz 18 H_FILES_DIR=httpd-2.2.17 19 H_PREFIX=/usr/local/httpd 20 21 #mysql define path variable 22 M_FILES=mysql-5.5.22.tar.gz 23 M_FILES_DIR=mysql-5.5.22 24 M_PREFIX=/usr/local/mysql/ 25 26 27 #php define path variable 28 29 P_FILES1=libmcrypt-2.5.8.tar.gz 30 P_FILES_DIR1=libmcrypt-2.5.8 31 P_PREFIX1=/usr/local/lib/ 32 33 P_FILES2=mhash-0.9.9.9.tar.gz 34 P_FILES_DIR2=mhash-0.9.9.9 35 P_PREFIX2=/usr/local/lib/ 36 37 P_FILES3=mcrypt-2.6.8.tar.gz 38 P_FILES_DIR3=mcrypt-2.6.8 39 P_PREFIX3=/usr/local/lib/ 40 41 P_FILES4=php-5.3.28.tar.gz 42 P_FILES_DIR4=php-5.3.28 43 P_PREFIX4=/usr/local/php 44 45 46 47 48 if [ -z "$1" ];then 49 echo -e "\033[36m请选择下面选项:\033[0m" 50 echo -e "\033[32m1)编译安装Apache服务器\033[1m" 51 echo "2)编译安装MySQL服务器" 52 echo "3)编译安装PHP服务器" 53 echo "4)配置index.php并启动LAMP服务" 54 echo "5)部署phpMyAdmin系统" 55 echo "6)安装RRDtool工具" 56 echo "7)安装Cacti监控服务" 57 echo "8)配置Cacti客户端" 58 echo -e "\033[31m使用: { /bin/sh $0 1|2|3|4|help}\033[0m" 59 exit 60 fi 61 62 63 #auto install Apache 64 if [ $1 -eq 1 ];then 65 rpm -e httpd --nodeps 66 tar -zxvf $H_FILES &&cd $H_FILES_DIR ;./configure --prefix=$H_PREFIX --enable-so --enable-rewrite --enable-charset-lite --enable-cgi 67 68 if [ $? -eq 0 ];then 69 make &&make install 70 echo -e "\033[32mThe $H_FILES_DIR Server Install successfully!(Apache服务安装已完成!)\033[0m" 71 else 72 echo -e "\033[32mThe $H_FILES_DIR Server Install failed,please check...\033[0m" 73 exit 74 fi 75 fi 76 77 #auto install Mysql 78 if [ $1 -eq 2 ];then 79 rpm -e mysql-server mysql --nodeps 80 tar -zxvf cmake-2.8.6.tar.gz -C /usr/src/ && cd /usr/src/cmake-2.8.6/;./configure 81 if [ $? -eq 0 ];then 82 gmake &&gmake install 83 echo -e "\033[32mThe cmake Server Install successfully!(cmake编译安装完成!)\033[0m" 84 else 85 echo -e "\033[32mThe cmake Server Install failed,please check...\033[0m" 86 exit 87 fi 88 useradd -M -u 27 -s /sbin/nologin mysql 89 cd /root 90 tar -zxvf $M_FILES -C /usr/src/;cd /usr/src/$M_FILES_DIR && cmake -DCMAKE_INSTALL_PREFIX=$M_PREFIX -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all 91 if [ $? -eq 0 ];then 92 make &&make install 93 echo -e "\033[32mThe mysql $M_FILES_DIR Install successfully!(MySQL服务安装已完成!)\033[0m" 94 else 95 echo -e "\033[32mThe mysql $M_FILES_DIR Install failed,please check...\033[0m" 96 exit 97 fi 98 chown -R mysql:mysql /usr/local/mysql/ 99 cd /usr/src/$M_FILES_DIR 100 cp support-files/my-medium.cnf /etc/my.cnf 101 $M_PREFIX/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ 102 cd /usr/src/$M_FILES_DIR 103 ln -s /usr/local/mysql/bin/* /usr/local/bin/ 104 cp support-files/mysql.server /etc/init.d/mysqld 105 chmod +x /etc/rc.d/init.d/mysqld 106 chkconfig --add mysqld 107 chkconfig mysqld on 108 service mysqld stop 109 service mysqld start 110 netstat -anpt | grep 3306 111 fi 112 113 114 115 #PHP define path variable 116 117 if [ $1 -eq 3 ];then 118 tar -zxvf $P_FILES1 -C /usr/src/;cd /usr/src/$P_FILES_DIR1/ && ./configure && make && make install && ln -s /$P_PREFIX1/libmcrypt.* /usr/lib/ 119 cd /root/ 120 tar -zxvf $P_FILES2 -C /usr/src/;cd /usr/src/$P_FILES_DIR2/ && ./configure && make && make install && ln -s /$P_PREFIX2/libmhash* /usr/lib/ 121 cd /root/ 122 tar -zxvf $P_FILES3 -C /usr/src/;cd /usr/src/$P_FILES_DIR3/ && export LD_LIBRARY_PATH=/$P_PREFIX3:$LD_LIBRARY_PATH && ./configure && make && make install 123 cd /root/ 124 tar -zxvf $P_FILES4 -C /usr/src/;cd /usr/src/$P_FILES_DIR4/ && ./configure --prefix=$P_PREFIX4 --with-mcrypt --with-apxs2=$H_PREFIX/bin/apxs --with-mysql=$M_PREFIX --with-config-file-path=$P_PREFIX4 --enable-mbstring --enable-sockets 125 if [ $? -eq 0 ];then 126 make &&make install 127 echo -e "\033[32mThe $P_FILES_DIR4 Server Install successfully!(PHP安装已完成!)\033[0m" 128 else 129 echo -e "\033[32mThe $P_FILES_DIR4 Server Install failed,please check...\033[0m" 130 exit 131 fi 132 fi 133 134 #配置并启动PHP 135 if [ $1 -eq 4 ];then 136 sed -i '/DirectoryIndex/s/index.html/index.php index.html/g' $H_PREFIX/conf/httpd.conf 137 echo "AddType application/x-httpd-php .php" >>$H_PREFIX/conf/httpd.conf 138 IP=`ifconfig eth0|grep "Bcast"|awk '{print $2}'|cut -d: -f2` 139 echo "You can access http://$IP/" 140 141 cat >$H_PREFIX/htdocs/index.php <<EOF 142 <?php 143 phpinfo(); 144 ?> 145 EOF 146 fi 147 148 ##PHP MyAdmin define path variable 149 if [ $1 -eq 5 ];then 150 tar -zxvf phpMyAdmin-4.2.5-all-languages.tar.gz 151 mv phpMyAdmin-4.2.5-all-languages/ /usr/local/httpd/htdocs/phpMyAdmin 152 cd /usr/local/httpd/htdocs/phpMyAdmin 153 cp config.sample.inc.php config.inc.php 154 if [ $? -eq 0 ];then 155 echo -e "\033[32mphpMyAdmin系统安装完成!\033[0m" 156 else 157 echo -e "\033[31mphpMyAdmin系统安装失败!\033[0m" 158 fi 159 160 fi 161 162 #RRDtool define path variable 163 if [ $1 -eq 6 ];then 164 yum -y install net-snmp net-snmp-utils 165 yum -y install cairo-devel zlib libxml2 libxml2-devel glib2 glib2-devel libpng libpng-devel freetype freetype-devel libart_lgpl pango pango-devel pear pear-devel perl-CPAN 166 tar -zxvf $R_FILES -C /usr/src/ && cd $R_PREFIX && ./configure --prefix=$R_PREFIX 167 if [ $? -eq 0 ];then 168 make &&make install 169 echo -e "\033[32mRRDtool工具安装完成!)\033[0m" 170 else 171 echo -e "\033[31mRRDtool工具安装失败!\033[0m" 172 exit 173 fi 174 fi 175 176 #Cacti define path variable 177 if [ $1 -eq 7 ];then 178 tar -zxvf $C_FILES -C /usr/src/ && cp -r $C_PREFIX $H_PREFIX/htdocs/cacti 179 useradd cacti 180 chown -R cacti:cacti $H_PREFIX/htdocs/cacti/ 181 echo "create database cacti default character set utf8;" | mysql -u root -p123.com 182 echo "grant all on cacti.* to 'cacti'@'localhost' identified by '123.com';" | mysql -u root -p123.com 183 mysql -u root -p cacti < $H_PREFIX/htdocs/cacti/cacti.sql 184 touch $P_PREFIX4/php.ini 185 sed -i 's/$database_username = "cactiuser";/$database_username = "cacti";/' $H_PREFIX/htdocs/cacti/include/config.php 186 sed -i 's/$database_password = "cactiuser";/$database_password = "123.com";/' $H_PREFIX/htdocs/cacti/include/config.php 187 sed -i 's/;date.timezone =/date.timezone =utc/' $P_PREFIX4/php.ini 188 if [ $? -eq 0 ];then 189 echo -e "\033[32mCacti部署完毕,数据库连接设置完成\033[0m" 190 else 191 echo -e "\033[31mCacti部署失败!\033[0m" 192 exit 193 fi 194 $H_PREFIX/bin/apachectl -t 195 $H_PREFIX/bin/apachectl restart 196 fi 197 198 #Cacti客户端配置 199 200 if [ $1 -eq 8 ];then 201 yum -y install net-snmp lm_sensors 202 sed -i "s/com2sec notConfigUser default/com2sec notConfigUser 192.168.1.100/" /etc/snmp/snmpd.conf 203 sed -i 's/exact systemview none none/exact all none none/' /etc/snmp/snmpd.conf 204 sed -i 's/#view all included .1/view all included .1/' /etc/snmp/snmpd.conf 205 service snmpd restart 206 echo -e "\033[32msnmp服务重启完成\033[0m" 207 netstat -anpt | grep snmpd 208 fi 209 210 ######################### 211 ###LAMP环境下实现 212 ######访问地址:firefox http://192.168.1.1/cacti & 213 214 215 216 # netstat -tnl 217 # /usr/local/httpd/bin/apachectl -t 218 #/usr/local/httpd/bin/apachectl start 219 #ps -ef | grep http 220 # echo -e "\033[32m配置完成,打开浏览器测试结果\033[0m" 221 222 #phpMyAdmin测试:fireorx http://192.168.1.1/phpMyAdmin & 223