#!/bin/bash
#debug info
#user:houzc
#createtime:2012/7/27 and updatetime 2014/12/4
#Mysql install directory , data diretory ,version and mysql-root password setup.
DATA_DIR="/data/mysqldata/"
BASE_DIR="/usr/local/mysql"
VERSION="mysql-5.6.20"
MYSQL_PASSWD="admin"
#######apahce and php ,nginx install directory ,version.########
HTTPVERSION="httpd-2.2.21"
PHPVERSION="php-5.4.7"
APPA_DIR="/usr/local/apache-2.2.21"
NGINXVERSION="nginx-1.6.0"
NGPA_DIR="/usr/local/nginx-1.6.0"
CUR_DIR=$(pwd)
mysql_install()
{
if [ -e "$MYSQL_DIR" ];then
echo "Mysql already exists......................................"
exit 0
else
rm -rf /usr/src/$VERSION/
mkdir -p /data/mysqldata/
mkdir -p /usr/local/mysql
tar zxvf $VERSION.tar.gz -C /usr/src
cd /usr/src/$VERSION/ && echo "tar ok..................."
/usr/bin/cmake -DCMAKE_INSTALL_PREFIX=$BASE_DIR \
-DMYSQL_DATADIR=$DATA_DIR \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_unicode_ci \
-DWITH_DEBUG=0 -DMYSQL_USER=mysql
make && echo "make ok ..................................."
make install && echo "make install ok.................................."
cd - && cp -r my.cnf.hzc /etc/my.cnf
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=$BASE_DIR --datadir=$DATA_DIR --no-defaults
chown mysql:root -R $BASE_DIR
chown mysql:mysql -R $DATA_DIR
sed "26 i basedir=${BASE_DIR}" -i /etc/my.cnf
sed "27 i datadir=${DATA_DIR}" -i /etc/my.cnf
cp -r /usr/src/$VERSION/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed "48 i basedir=${BASE_DIR}" -i /etc/init.d/mysqld
sed "49 i datadir=${DATA_DIR}" -i /etc/init.d/mysqld
echo ‘PATH=$PATH:/usr/local/mysql/bin/‘ >> /etc/profile
source /etc/profile
${BASE_DIR}/bin/mysqladmin -u root password "${MYSQL_PASSWD}"
#ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
fi
}
apache_install()
{
if [ -e $APPA_DIR ];then
echo "httpd already exists.........................."
exit 0
else
rm -rf /usr/src/$HTTPVERSION
tar zxvf $HTTPVERSION.tar.gz -C /usr/src/
cd /usr/src/$HTTPVERSION/srclib/apr
./configure --prefix=/usr/local/apr
make && make install && echo "apr is ok................................"
sleep 3
cd -
cd /usr/src/$HTTPVERSION/srclib/apr-util/
./configure --prefix=/usr/local/apr-util/ \
--with-apr=/usr/local/apr
make && make install && echo "apr-util is ok.............................."
sleep 3
cd -
cd /usr/src/$HTTPVERSION
./configure --prefix=$APPA_DIR \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/ \
--enable-so \
--enable-rewrite
make && make install && echo "apache is ok.............................."
sed -i ‘s/#ServerName www.example.com:80/ServerName www.example.com:80/‘ $APPA_DIR/conf/httpd.conf
$APPA_DIR/bin/apachectl start
cd -
fi
}
php_install()
{
if [ -e "/usr/local/$PHPVERSION" ];then
echo "php already exists.........................."
exit 0
else
gd_install
rm -rf /usr/src/$PHPVERSION
tar zxvf $PHPVERSION.tar.gz -C /usr/src/
cd /usr/src/$PHPVERSION/
./configure --prefix=/usr/local/$PHPVERSION \
--with-apxs2=$APPA_DIR/bin/apxs \
--with-zlib --with-libxml-dir --enable-gd-native-ttf \
--enable-mbstring --with-gd=/usr/local/gd-2.0.33/ \
--with-mysql=$BASE_DIR \
--with-freetype-dir=/usr/local/freetype-2.4.3/ \
--with-jpeg-dir=/usr/local/jpeg-8b/ \
--with-png-dir=/usr/local/libpng-1.4.4/ \
--enable-sockets --enable-bcmath --with-gettext
make && make install && echo "php is ok.............................."
cp -r php.ini-development /usr/local/$PHPVERSION/lib/php.ini
sed -i "54 i AddType application/x-httpd-php .php " $APPA_DIR/conf/httpd.conf
sed -i ‘s/DirectoryIndex index.html/DirectoryIndex index.html index.php/‘ $APPA_DIR/conf/httpd.conf
cd -
cp -r info.php $APPA_DIR/htdocs/
$APPA_DIR/bin/apachectl stop
$APPA_DIR/bin/apachectl start
fi
}
gd_install()
{
rm -rf /usr/src/freetype-2.4.3/
tar zxvf freetype-2.4.3.tar.gz -C /usr/src/
cd /usr/src/freetype-2.4.3/
./configure --prefix=/usr/local/freetype-2.4.3
make && make install && echo "freetype is ok.............................."
sleep 5s
cd -
rm -rf /usr/src/libpng-1.4.4/
tar zxvf libpng-1.4.4.tar.gz -C /usr/src/
cd /usr/src/libpng-1.4.4/
./configure --prefix=/usr/local/libpng-1.4.4
make && make install && echo "libpng is ok.............................."
sleep 5s
cd -
rm -rf /usr/src/jpeg-8b
tar zxvf jpegsrc.v8b.tar.gz -C /usr/src/
cd /usr/src/jpeg-8b/
./configure --prefix=/usr/local/jpeg-8b
make && make install && echo "jpeg-8b is ok.............................."
sleep 5s
cd -
rm -rf /usr/src/gd-2.0.33
tar zxvf gd-2.0.33.tar.gz -C /usr/src/
cp -r gd_png.c /usr/src/gd-2.0.33/
cd /usr/src/gd-2.0.33/
./configure --prefix=/usr/local/gd-2.0.33 \
--with-jpeg=/usr/local/jpeg-8b \
--with-freetype=/usr/local/freetype-2.4.3 \
--with-png=/usr/local/libpng-1.4.4 \
--with-zlib --enable-m4_pattern_allow
make && make install && echo "gd is ok.............................."
sed -i ‘/gd_free/a \ \ void (*data);‘ /usr/local/gd-2.0.33/include/gd_io.h
sleep 5s
cd -
}
nginx_install()
{
if [ -e $NGPA_DIR ];then
echo "nginx already exists.........................."
exit 0
else
groupadd -rf www
useradd -g www www -s /bin/false
rm -rf /usr/src/pcre-8.31
rm -rf /usr/src/$NGINXVERSION
tar zxvf pcre-8.36.tar.gz -C /usr/src/
cd /usr/src/pcre-8.36
./configure
make && make install && echo "pcre is ok ..........................."
sleep 10s
cd -
tar zxvf $NGINXVERSION.tar.gz -C /usr/src/
cd /usr/src/$NGINXVERSION
./configure --prefix=$NGPA_DIR \
--user=www --group=www \
--with-http_stub_status_module \
--with-openssl=/usr --with-pcre=/usr/src/pcre-8.36
make && make install && echo "nginx is ok ......................."
ln -s /usr/local/lib/libpcre.so.1 /lib
ln -s /usr/local/lib/libpcre.so.1 /lib64
$NGPA_DIR/sbin/nginx
fi
}
pextend_install()
{
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/libiconv
make && make install
cd -
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
/sbin/ldconfig
cd libltdl
./configure --enable-ltdl-install
make && make install
cd ../../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make && make install
cd -
echo "/usr/local/lib/">> /etc/ld.so.conf
/sbin/ldconfig
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make && make install
cd -
tar -zxvf curl-7.17.1.tar.gz
cd curl-7.17.1
./configure --prefix=/usr/local/curl/
make && make install
cd -
}
nphp_install(){
if [ -e "/usr/local/$PHPVERSION" ];then
echo "php already exists.........................."
exit 0
else
gd_install
pextend_install
rm -rf /usr/src/$PHPVERSION
tar zxvf $PHPVERSION.tar.gz -C /usr/src/
cd /usr/src/$PHPVERSION/ && echo "cd is ok"
./configure --prefix=/usr/local/$PHPVERSION \
--with-mysql=$BASE_DIR\
--with-mysqli=$BASE_DIR/bin/mysql_config \
--with-freetype-dir=/usr/local/freetype-2.4.3 \
--with-jpeg-dir=/usr/local/jpeg-8b \
--with-png-dir=/usr/local/libpng-1.4.4/ \
--with-zlib --with-libxml-dir --enable-xml --enable-mbstring \
--with-openssl --with-gd=/usr/local/gd-2.0.33 \
--with-curl=/usr/local/curl/ \
--with-mhash --with-mcrypt --enable-sockets --enable-pcntl --enable-fpm \
--with-iconv=/usr/local/libiconv
make
make install
cd -
cp /usr/local/$PHPVERSION/etc/php-fpm.conf.default /usr/local/$PHPVERSION/etc/php-fpm.conf
cp /usr/src/$PHPVERSION/php.ini-development /usr/local/$PHPVERSION/lib/php.ini
sed -ri ‘s/user = nobody/user = www/‘ /usr/local/$PHPVERSION/etc/php-fpm.conf
sed -ri ‘s/group = nobody/group = www/‘ /usr/local/$PHPVERSION/etc/php-fpm.conf
sed -ri ‘/pid = run\/php-fpm.pid/apid = run\/php-fpm.pid‘ /usr/local/$PHPVERSION/etc/php-fpm.conf
cp /usr/src/$PHPVERSION/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
fi
}
cacti_install()
{
$BASE_DIR/bin/mysql -uroot -p$MYSQL_PASSWD -e "create database cacti;"
$BASE_DIR/bin/mysql -uroot -p$MYSQL_PASSWD -e "GRANT ALL ON cacti.* TO ${user1}@localhost IDENTIFIED BY ‘${passd1}‘;"
$BASE_DIR/bin/mysql -uroot -p$MYSQL_PASSWD -e "flush privileges;"
tar zxvf $CACTI_VERSION -C $CACTIPA_DIR
cact=`echo $CACTI_VERSION |cut -d . -f 1-3`
mv $CACTIPA_DIR/$cact $CACTIPA_DIR/cacti
cd $CACTIPA_DIR/cacti
$BASE_DIR/bin/mysql -u ${user1} -p${passd1} cacti < cacti.sql
}
zabbix_proxy_install()
{
yum -y install net-snmp-devel net-snmp-utils curl-devel curl
echo "The system is bing installed pack,please waitting..."
sleep 5s
useradd zabbix -m -s /sbin/nologin
rm -rf /usr/src/zabbix-2.4.1
tar -zxvf zabbix-2.4.1.tar.gz -C /usr/src/
cd /usr/src/zabbix-2.4.1
./configure --prefix=/usr/local/zabbix-proxy --enable-server --enable-proxy --enable-agent --with-mysql=$BASE_DIR/bin/mysql_config --with-net-snmp --with-libcurl && echo "./config ............is ok!"
make && make install && echo make install......................is ok! ""
$BASE_DIR/bin/mysql -uroot -p$MYSQL_PASSWD -e "create database zabbix_proxy;"
$BASE_DIR/bin/mysql -uroot -p$MYSQL_PASSWD -e "GRANT ALL ON zabbix_proxy.* TO [email protected] IDENTIFIED BY ‘123456‘;"
$BASE_DIR/bin/mysql -uroot -p$MYSQL_PASSWD -e "flush privileges;"
$BASE_DIR/bin/mysql -uroot -p$MYSQL_PASSWD zabbix_proxy < /usr/src/zabbix-2.4.1/database/mysql/schema.sql
ln -s $BASE_DIR/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
ln -s $BASE_DIR/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
read -p "Please enter the zabbix_server_ip(1.1.1.1):" -t 300 serviceip
read -p "Please enter the hostname:" -t 300 hostname
mv /usr/local/zabbix-proxy/etc/zabbix_proxy.conf /usr/local/zabbix-proxy/etc/zabbix_proxy.conf.back
echo "DBName=zabbix_proxy " >> /usr/local/zabbix-proxy/etc/zabbix_proxy.conf
echo "DBUser=zabbix " >> /usr/local/zabbix-proxy/etc/zabbix_proxy.conf
echo "DBPassword=123456 " >> /usr/local/zabbix-proxy/etc/zabbix_proxy.conf
echo "ConfigFrequency=60 " >> /usr/local/zabbix-proxy/etc/zabbix_proxy.conf
echo "DataSenderFrequency=60 " >> /usr/local/zabbix-proxy/etc/zabbix_proxy.conf
echo "Server=${serviceip} " >> /usr/local/zabbix-proxy/etc/zabbix_proxy.conf
echo "Hostname=${hostname} " >> /usr/local/zabbix-proxy/etc/zabbix_proxy.conf
/usr/local/zabbix-proxy/sbin/zabbix_proxy -c /usr/local/zabbix-proxy/etc/zabbix_proxy.conf
echo "/usr/local/zabbix-proxy/sbin/zabbix_proxy -c /usr/local/zabbix-proxy/etc/zabbix_proxy.conf" > /etc/rc.local
}
zabbix_agent_install()
{
yum -y install net-snmp-devel net-snmp-utils curl-devel curl
echo "The system is bing installed pack,please waitting..."
sleep 5s
useradd zabbix -m -s /sbin/nologin
rm -rf /usr/src/zabbix-2.4.1
tar -zxvf zabbix-2.4.1.tar.gz -C /usr/src/
cd /usr/src/zabbix-2.4.1
./configure --prefix=/usr/local/zabbix_agent --enable-agent
make && make install && echo "make instal is ok ........................................................................."
read -p "Please enter the zabbix_server_ip(1.1.1.1):" -t 300 serviceip
read -p "Please enter the hostname:" -t 300 hostname
sed -i "s/ServerActive=127.0.0.1/ServerActive=${serviceip}/" /usr/local/zabbix_agent/etc/zabbix_agentd.conf
sed -i "s/Server=127.0.0.1/Server=${serviceip}/" /usr/local/zabbix_agent/etc/zabbix_agentd.conf
sed -i "s/Hostname=Zabbix server/Hostname=${hostname}/" /usr/local/zabbix_agent/etc/zabbix_agentd.conf
cat /usr/local/zabbix_agent/etc/zabbix_agentd.conf |grep -v -E "^$|^#"
/usr/local/zabbix_agent/sbin/zabbix_agentd && echo "zabbix-agent is ok......................!!"
}
tomcat_install() {
chmod +x jdk-6u32-linux-x64.bin
./jdk-6u32-linux-x64.bin
echo -e "\r"
mv $CUR_DIR/jdk1.6.0_32/ /usr/local/
if [ $? -eq 0 ];then
mv $CUR_DIR/jdk1.6.0_32 /usr/local
echo "JAVA_HOME=/usr/local/jdk1.6.0_32" >> /etc/profile
echo "CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar">> /etc/profile
sed -i ‘$aPATH=${JAVA_HOME}/bin:$PATH‘ /etc/profile
echo "export JAVA_HOME JAVA_BIN PATH CLASSPATH">> /etc/profile
source /etc/profile
else
echo "Installation failed,please check the installation messages"
exit 3
fi
tar zxvf apache-tomcat-6.0.41.tar.gz
if [ -d apache-tomcat-6.0.41 ];then
mv apache-tomcat-6.0.41 /usr/local
else
echo "Installation failed,please check the installation messages"
exit 3
fi
/usr/local/apache-tomcat-6.0.41/bin/startup.sh && echo "Tomcat server is started sucessfull"
}
tengine_install() {
groupadd -rf www
useradd -g www www -s /bin/false
tar jxvf jemalloc-3.4.1.tar.bz2 -C /usr/src
cd /usr/src/jemalloc-3.4.1
./configure --prefix=/usr/local/jemalloc-3.4.1
make && make install
ldconfig
cd -
tar zxvf ngx_cache_purge-2.1.tar.gz -C /usr/src
tar zxvf tengine-1.5.1.tar.gz -C /usr/src
cd /usr/src/tengine-1.5.1
yum -y install pcre-devel openssl-devel gcc gcc-c++ make
./configure --user=www --group=www --prefix=/usr/local/tengine-1.5.1 --add-module=/usr/src/ngx_cache_purge-2.1 --with-http_stub_status_module \
--with-http_ssl_module --with-http_realip_module --with-http_concat_module=shared --with-http_sysguard_module=shared --with-http_limit_conn_module=shared \
--with-http_limit_req_module=shared --with-http_footer_filter_module=shared --with-http_upstream_ip_hash_module=shared --with-http_upstream_least_conn_module=shared \
--with-http_upstream_session_sticky_module=shared --with-jemalloc=/usr/src/jemalloc-3.4.1
make && make install && echo tengine is OK
}
case "$1" in
mysql_install)
if [ -f /etc/debian_version ]; then
apt-get -y install build-essential cmake libncurses5-dev bison
groupadd -r mysql && useradd -r -M -s /usr/sbin/nologin -g mysql mysql
echo "The system is bing installed pack,please waitting..."
sleep 5s
mysql_install
/etc/init.d/mysqld start
update-rc.d mysqld defaults
else
yum -y install gcc gcc-c++ libtermcap-devel ncurses-devel cmake bison make
useradd mysql -M -s /sbin/nologin
echo "The system is bing installed packe,please waitting..."
sleep 5s
mysql_install 2>&1 | tee -a /tmp/install.log
/etc/init.d/mysqld start
chkconfig --add mysqld
fi
;;
apache_install)
if [ -f /etc/debian_version ]; then
apt-get -y install build-essential cmake
else
yum -y install gcc gcc-c++ make cmake
fi
apache_install 2>&1 | tee -a /tmp/install.log
;;
nginx_install)
if [ -f /etc/debian_version ]; then
apt-get -y install build-essential cmake zlib1g-dev
else
yum -y install gcc gcc-c++ make cmake zlib zlib-devel
fi
nginx_install 2>&1 | tee -a /tmp/install.log
;;
php_install)
if [ -f /etc/debian_version ]; then
apt-get -y install zlib1g-dev libxml2-dev && php_install
else
yum -y install libxml2-devel libxml2 && php_install 2>&1 | tee -a /tmp/install.log
fi
;;
nphp_install)
if [ -f /etc/debian_version ]; then
apt-get -y install zlib1g-dev libxml2-dev openssl-dev && nphp_install
else
yum -y install libxml2-devel libxml2 openssl-devel && nphp_install 2>&1 | tee -a /tmp/install.log
fi
;;
AMP_install)
if [ -f /etc/debian_version ]; then
apt-get -y install build-essential cmake libncurses5-dev bison
groupadd -r mysql && useradd -r -M -s /usr/sbin/nologin -g mysql mysql
echo "The system is bing installed pack,please waitting..."
sleep 3
mysql_install
/etc/init.d/mysqld start
update-rc.d mysqld defaults
else
yum -y install gcc gcc-c++ libtermcap-devel ncurses-devel cmake bison make
useradd mysql -M -s /sbin/nologin
echo "The system is bing installed pack,please waitting..."
sleep 3
mysql_install 2>&1 | tee -a /tmp/install.log
/etc/init.d/mysqld start
chkconfig --add mysqld
fi
apache_install 2>&1 | tee -a /tmp/install.log
gd_install
if [ -f /etc/debian_version ]; then
apt-get -y install zlib1g-dev libxml2-dev && php_install
else
yum -y install libxml2-devel libxml2 && php_install 2>&1 | tee -a /tmp/install.log
fi
;;
NMP_install)
if [ -f /etc/debian_version ]; then
apt-get -y install build-essential cmake libncurses5-dev bison
groupadd -r mysql && useradd -r -M -s /usr/sbin/nologin -g mysql mysql
echo "The system is bing installed pack,please waitting..."
sleep 5s
mysql_install
/etc/init.d/mysqld start
update-rc.d mysqld defaults
else
yum -y install gcc gcc-c++ libtermcap-devel ncurses-devel cmake bison make
useradd mysql -M -s /sbin/nologin
echo "The system is bing installed pack,please waitting..."
sleep 5s
mysql_install 2>&1 | tee -a /tmp/install.log
/etc/init.d/mysqld start
chkconfig --add mysqld
fi
sleep 10s
nginx_install 2>&1 | tee -a /tmp/install.log
sleep 10s
if [ -f /etc/debian_version ]; then
apt-get -y install zlib1g-dev libxml2-dev openssl-dev && nphp_install
else
yum -y install libxml2-devel libxml2 openssl-devel && nphp_install 2>&1 | tee -a /tmp/install.log
fi
;;
zabbix_proxy_install)
zabbix_proxy_install 2>&1 | tee -a /tmp/install.log
;;
zabbix_agent_install)
zabbix_agent_install 2>&1 | tee -a /tmp/install.log
;;
tomcat_install)
tomcat_install 2>&1 | tee -a /tmp/install.log
;;
tengine_install)
tengine_install 2>&1 | tee -a /tmp/install.log
;;
*)
echo "Usage:sh|bash $0 {mysql_install|apache_install|php_install|AMP_install|nginx_install|nphp_install|NMP_install|zabbix_proxy_install|zabbix_agent_install|tomcat_install|tengine_install}"
exit
;;
esac