#!/bin/bash
#install_package
#2016/10/28 by Chris_JD
#Basic configuration
soft_ftp_server="192.168.1.111"
ftp_user="ftp"
ftp_password="******"
package_dir=/root
install_path="/usr/local"
red_col="\e[1;31m"
blue_col="\e[1;34m"
reset_col="\e[0m"
green_col="\e[0;32m"
#nginx
nginx_install_package="nginx-1.8.0.tar.gz"
pcre_install_package="pcre-8.35.tar.gz"
nginx_start_sh="nginx"
#memcached
memcached_shell="memcached"
memcached_install_package="memcached-1.4.15.tar.gz"
libevent_install_package="libevent-2.0.21-stable.tar.gz"
#redis
redis_install_package="redis-2.8.17.tar.gz"
#redis-3.0.5
redis3_install_package="redis-3.0.5.tar.gz"
#rabbitmq
erlang_install_package="otp_src_18.2.1.tar.gz"
rabbitmq_install_package="rabbitmq-server-3.5.7.tar.gz"
#kestrel
soft_path="/root"
sbt_install_package="sbt-launch.jar"
scala_install_package="scala-2.9.2.rpm"
daemon_install_package="daemon-0.6.4.tar.gz"
kestrel_install_package="kestrel-2.2.0.zip"
sbt_install_path="/usr/local/bin"
install_log="/root/install_servers.log"
#node
node_install_package="node-v5.1.1-linux-x64.tar.gz"
#jdk1.6
jdk_install_package="jdk-7u6-linux-x64.tar.gz"
#jdk1.8
jdk8_install_package="jdk-8u92-linux-x64.gz"
#mongodb
mongodb_install_package="mongodb-linux-x86_64-2.6.3.tgz"
#mysql
mysql_install_package="mysql.package.tar.gz"
MYSQL_PATH="/usr/local/mysql"
#htop
htop_install_package="epel-release-5-4.noarch.rpm"
menu() {
cat <<-EOF
+-----------------------------------------------+
| |
| ====================== |
| Linux包管理系统 v2.0 |
| by Chris_JD |
| ====================== |
| 1. 安装nginx-1.8.0 |
| 2. 安装memcached-1.4.15 |
| 3. 安装redis-2.8.17 |
| 4. 安装rabbitmq-3.5.7 |
| 5. 安装kestrel-2.2.0 |
| 6. 安装node-v5.1.1 |
| 7. 安装jdk-7u6 |
| 8. 安装mongodb2.6.3 |
| 9. 安装mysql-5.6.29 |
| 10. 安装jdk-8u92 |
| 11. 安装redis-3.0.5 |
| 12. 安装Htop |
| q. 退出管理程序 |
| |
+-----------------------------------------------+
EOF
}
package_install_init() {
#ps -ef | grep ${process_name}* | grep -v grep &>/dev/null
cd /usr/local/${process_name} > /dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "${red_col}${process_name}软件已存在,请检查后再安装!${reset_col}"
exit
else
echo -e "${red_col}本机未安装${process_name}软件!${reset_col}"
fi
}
Prompt_information() {
echo -en "${blue_col}确认继续安装${process_name} 请输入[y]: ${reset_col}"
read mysql_install
if [ ! "${mysql_install}" = "y" ];then
echo -e "$red_col输入不正确! $reset_col"
continue
fi
}
install_finish() {
echo -e " ${green_col}${process_name}安装完成,请查看! ${green_col} "
continue
}
nginx_package_install() {
cd ${package_dir}
yum -y install perl wget gcc-c++ make elinks zlib-devel
if [ ! -f "$nginx_install_package" ]; then
wget ftp://$soft_ftp_server/$nginx_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
if [ ! -f "$pcre_install_package" ]; then
wget ftp://$soft_ftp_server/$pcre_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
if [ ! -f "$nginx_start_sh" ]; then
wget ftp://$soft_ftp_server/$nginx_start_sh --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $pcre_install_package
tar -zxf $nginx_install_package
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --with-pcre=/root/pcre-8.35 --with-http_stub_status_module && make && make install
if [ $? -eq 0 ];then
echo -e "\e[32;1m install nginx successful \e[0m"
sleep 2
fi
cd /root
cp nginx /etc/init.d/
chmod 755 /etc/init.d/nginx
mkdir /usr/local/nginx/conf/conf.d
sed -i '116s/$/include \/usr\/local\/nginx\/conf\/conf.d\/*.conf;/g' /usr/local/nginx/conf/nginx.conf
echo -e "upstream www.test.com {
# ip_hash;
server 127.0.0.1:8080;
}
server
{
listen 80;
server_name www.test.com;
location / {
proxy_pass http://www.test.com;
proxy_redirect off;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
" >> /usr/local/nginx/conf/conf.d/default.conf
rm -rf /root/pcre*
/etc/init.d/nginx start
echo "/etc/init.d/nginx start" >> /etc/rc.local
netstat -ntpl |grep "80"
}
memcached_package_install() {
cd ${package_dir}
yum install libevent wget gcc-c++ make -y
if [ ! -f "$memcached_install_package" ]; then
wget ftp://$soft_ftp_server/$memcached_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
if [ ! -f "$libevent_install_package" ]; then
wget ftp://$soft_ftp_server/$libevent_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
if [ ! -f "$memcached_shell" ]; then
wget ftp://$soft_ftp_server/$memcached_shell --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $libevent_install_package
tar -zxf $memcached_install_package
cd libevent-2.0.21-stable
./configure --prefix=$install_path/libevent && make && make install
cd ../memcached-1.4.15
./configure --prefix=$install_path/memcached --with-libevent=$install_path/libevent && make && make install
cd ../
echo "$install_path/memcached/bin/memcached -d -m 256 -u root -p 11211 -c 1024 -P /tmp/memcached.pid" > $install_path/memcached/start.sh
echo "kill \`cat /tmp/memcached.pid\`" > $install_path/memcached/shutdown.sh
chmod 755 $install_path/memcached/shutdown.sh
chmod 755 $install_path/memcached/start.sh
cp -ri $memcached_shell /etc/init.d
chmod 755 /etc/init.d/$memcached_shell
/etc/init.d/$memcached_shell/ start.sh
echo "/etc/init.d/$memcached_shell start" >> /etc/rc.local
}
redis_package_install() {
cd ${package_dir}
yum install wget make gcc-c++ -y
if [ ! -f "$redis_install_package" ]; then
wget ftp://$soft_ftp_server/$redis_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $redis_install_package -C $install_path
mv /usr/local/redis-2.8.17 /usr/local/redis
cd $install_path/redis/
make
echo -e "export REDIS_HOME=\"$install_path/redis\"
export PATH=\"\$PATH:\$REDIS_HOME/src\"" >> /etc/profile
cd /root
. /etc/profile
#cp -ri redisd /etc/init.d/
#chmod 755 /etc/init.d/redisd
#echo "/etc/init.d/redisd start" >> /etc/rc.local
redis-server &
netstat -ntpl |grep "6379"
}
redis3_package_install() {
cd ${package_dir}
yum install wget make gcc-c++ -y
if [ ! -f "$redis3_install_package" ]; then
wget ftp://$soft_ftp_server/$redis3_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $redis3_install_package -C $install_path
mv /usr/local/redis-3.0.5 /usr/local/redis
cd $install_path/redis/
make
echo -e "export REDIS_HOME=\"$install_path/redis\"
export PATH=\"\$PATH:\$REDIS_HOME/src\"" >> /etc/profile
cd /root
. /etc/profile
#cp -ri redisd /etc/init.d/
#chmod 755 /etc/init.d/redisd
#echo "/etc/init.d/redisd start" >> /etc/rc.local
#/etc/init.d/redisd start
redis-server &
netstat -ntpl |grep "6379"
}
rabbitmq_package_install() {
cd ${package_dir}
yum install perl gcc-c++ mesa* freeglut* wget ncurses-devel openssl-devel unixODBC-devel zip unzip xmlto httpd -y
if [ ! -f "$erlang_install_package" ]; then
wget ftp://$soft_ftp_server/$erlang_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
if [ ! -f "$rabbitmq_install_package" ]; then
wget ftp://$soft_ftp_server/$rabbitmq_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $erlang_install_package
cd otp_src_18.2.1
./configure --prefix=/usr/local/erlang --without-javac
make
make install
cd /root
echo -e "export ERL_HOME=\"/usr/local/erlang\"
export PATH=\"\$PATH:\$ERL_HOME/bin\"" >> /etc/profile
. /etc/profile
chmod +x $rabbitmq_install_package
tar -zxf $rabbitmq_install_package
cd rabbitmq-server-3.5.7
make
make install TARGET_DIR=/usr/local/mq/rabbitmq SBIN_DIR=/usr/local/mq/rabbitmq/sbin MAN_DIR=/usr/local/mq/rabbitmq/man
cd /usr/local/mq/rabbitmq/sbin/
mkdir /etc/rabbitmq/
./rabbitmq-plugins enable rabbitmq_management
./rabbitmq-server start &
}
kestrel_package_install() {
yum install gcc-c++ wget perl-Module-Install.noarch libtool openssl-devel make -y
[ ! -f $install_log ] && touch $install_log && chattr +i $install_log
##################################
# Open the lock
##################################
chattr -i $install_log
##################################
# Get Install Package
##################################
cd ${package_dir}
egrep "${kestrel_install_package%.zip} installed" $install_log
if [ $? != 0 ]; then
[ ! -f $soft_path/$kestrel_install_package ] && echo -e "\e[32;1m [Info] Now download ${kestrel_install_package%.zip}\e[0m" \
&& wget ftp://$soft_ftp_server/$kestrel_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password \
|| echo -e "\e[32;1m [Info] $kestrel_install_package Exists! \e[0m"
else
echo -e "\e[32;1m [Info] ${kestrel_install_package%.zip} is already installed! \e[0m"
exit
fi
egrep "${scala_install_package%.rpm} installed" $install_log
if [ $? != 0 ]; then
[ ! -f $soft_path/$scala_install_package ] && echo -e "\e[32;1m [Info] Now download ${scala_install_package%.rpm}\e[0m" \
&& wget ftp://$soft_ftp_server/$scala_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password \
|| echo -e "\e[32;1m [Info] $scala_install_package Exists! \e[0m"
fi
egrep "${daemon_install_package%.tar.gz} installed" $install_log
if [ $? != 0 ]; then
[ ! -f $soft_path/$daemon_install_package ] && echo -e "\e[32;1m [Info] Now download ${daemon_install_package%.tar.gz}\e[0m" \
&& wget ftp://$soft_ftp_server/$daemon_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password \
|| echo -e "\e[32;1m [Info] $daemon_install_package Exists! \e[0m"
fi
egrep "${sbt_install_package%.jar} installed" $install_log
if [ $? != 0 ]; then
[ ! -f $soft_path/$sbt_install_package ] && echo -e "\e[32;1m [Info] Now download ${sbt_install_package%.jar}\e[0m" \
&& wget ftp://$soft_ftp_server/$sbt_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password \
|| echo -e "\e[32;1m [Info] $sbt_install_package Exists! \e[0m"
fi
##################################
# Check Install Package Exists
##################################
cd $soft_path
ls $kestrel_install_package $sbt_install_package $scala_install_package $daemon_install_package > /dev/null 2>&1
[[ $? != 0 ]] && echo -e "\e[31;1m [ERROR] soft not find , please 'cd /home/soft' , check soft ($kestrel_install_package;$sbt_install_package;$scala_install_package;$daemon_install_package)! \e[0m" && exit 1 || echo -e "\e[32;1m [Info] Check the installation package OK,continue installation! \e[0m"
##################################
# Install SBT and scala and Daemon
##################################
egrep "${sbt_install_package%.jar} installed" $install_log
if [ $? == 0 ]; then
echo -e "\e[32;1m${sbt_install_package%.jar} installed\e[0m"
else
\cp -rf $sbt_install_package $sbt_install_path
echo 'SBT_OPTS="-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M"' >> $sbt_install_path/sbt
echo 'java $SBT_OPTS -jar `dirname $0`/sbt-launch.jar "$@"' >> $sbt_install_path/sbt
chmod u+x $sbt_install_path/sbt
[ ! -f $sbt_install_path/sbt ] && echo -e "\e[31;1m [ERROR] SBT installation failed! please check the reason! \e[0m" && exit 2 \
|| echo -e "\e[32;1m [Info] SBT installation Success! \e[0m"
echo "${sbt_install_package%.jar} installed" >> $install_log
fi
egrep "${scala_install_package%.rpm} installed" $install_log
if [ $? == 0 ]; then
echo -e "\e[32;1m${scala_install_package%.rpm} installed\e[0m"
else
rpm -ivh --force $scala_install_package
[[ $? != 0 ]] && echo -e "\e[31;1m [ERROR] Scala installation failed! please check the reason! \e[0m" && exit 3 \
|| echo -e "\e[32;1m [Info] Scala installation Success! \e[0m"
echo "${scala_install_package%.rpm} installed" >> $install_log
fi
egrep "${daemon_install_package%.tar.gz} installed" $install_log
if [ $? == 0 ]; then
echo -e "\e[32;1m${daemon_install_package%.tar.gz} installed\e[0m"
else
tar zxf $daemon_install_package
cd ${daemon_install_package%.tar.gz}
./configure && make && make install
[[ $? != 0 ]] && echo -e "\e[31;1m [ERROR] Daemon installation failed! please check the reason! \e[0m" && exit 4 \
|| echo -e "\e[32;1m [Info] Daemon installation Success! \e[0m"
echo "${daemon_install_package%.rpm} installed" >> $install_log
cd -
fi
##################################
# Install Kestrel
##################################
yum -y install unzip
unzip $kestrel_install_package
mv ${kestrel_install_package%.zip} $install_path/kestrel
mkdir $install_path/kestrel/current
cp $install_path/kestrel/*.jar $install_path/kestrel/current
[ ! -d $install_path/kestrel/current/ ] && echo -e "\e[31;1m [ERROR] kestrel/current Create failed! please check the reason! \e[0m" && exit 5 \
|| echo -e "\e[32;1m [Info] Kestrel installation Success! \e[0m"
echo "nohup java -jar $install_path/kestrel/kestrel_2.9.1-2.2.0.jar &" >> $install_path/kestrel/start.sh
chmod u+x $install_path/kestrel/start.sh
echo "${kestrel_install_package%.zip} installed" >> $install_log
##################################
# Close the lock
##################################
chattr +i $install_log
}
node_package_install() {
cd ${package_dir}
yum install wget -y
if [ ! -f "$node_install_package" ]; then
wget ftp://$soft_ftp_server/$node_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $node_install_package -C /usr/local/
mv /usr/local/node-v5.1.1-linux-x64 /usr/local/node
echo -e "export NODE_HOME=\"/usr/local/node\"
export PATH=\"\$PATH:\$NODE_HOME/bin\"" >> /etc/profile
. /etc/profile
sudo npm install forever -g
npm install forever -gd
}
jdk_package_install() {
cd ${package_dir}
yum install wget -y
if [ ! -f "$jdk_install_package" ]; then
wget ftp://$soft_ftp_server/$jdk_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $jdk_install_package -C $install_path
mv /usr/local/jdk1.7.0_06 /usr/local/jdk
echo -e "JAVA_HOME=$install_path/jdk
JRE_HOME=$install_path/jdk/jre
PATH=\$PATH:\$JAVA_HOME/bin:\$JRE_HOME/bin:\$HOME/bin:/sbin:/usr/bin:/usr/sbinexport:/usr/local/sbin:/usr/local/bin:/bin:/usr/sbin:/root/bin
CLASSPATH=.:\$JAVA_HOME/lib/jt.jar:\$JAVA_HOME/lib/tools.jar:\$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH" >> /etc/profile
. /etc/profile
java -version
}
jdk8_package_install() {
cd ${package_dir}
yum install wget -y
if [ ! -f "$jdk8_install_package" ]; then
wget ftp://$soft_ftp_server/$jdk8_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $jdk8_install_package -C $install_path
mv /usr/local/jdk1.8.0_92 /usr/local/jdk
echo -e "JAVA_HOME=$install_path/jdk
JRE_HOME=$install_path/jdk/jre
PATH=\$PATH:\$JAVA_HOME/bin:\$JRE_HOME/bin:\$HOME/bin:/sbin:/usr/bin:/usr/sbinexport:/usr/local/sbin:/usr/local/bin:/bin:/usr/sbin:/root/bin
CLASSPATH=.:\$JAVA_HOME/lib/jt.jar:\$JAVA_HOME/lib/tools.jar:\$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH" >> /etc/profile
. /etc/profile
java -version
}
mongodb_package_install() {
cd ${package_dir}
yum install wget -y
if [ ! -f "$mongodb_install_package" ]; then
wget ftp://$soft_ftp_server/$mongodb_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $mongodb_install_package -C /usr/local/
mv /usr/local/mongodb-linux-x86_64-2.6.3 /usr/local/mongodb
mkdir /usr/local/mongodb/data
mkdir /usr/local/mongodb/logs
echo -e "export MONGODB_HOME=\"/usr/local/mongodb\"
export PATH=\"\$PATH:\$MONGODB_HOME/bin\"" >> /etc/profile
. /etc/profile
mongod --port 27017 --fork --dbpath=/usr/local/mongodb/data/ --logpath=/usr/local/mongodb/logs/mongodb.log --logappend
}
mysql_package_install() {
cd ${package_dir}
yum install gcc-c++ wget ncurses-devel perl-Module-Install.noarch libtool openssl-devel make -y
if [ ! -f "$mysql_install_package" ]; then
wget ftp://$soft_ftp_server/$mysql_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
tar -zxf $mysql_install_package -C /usr/local
groupadd mysql
useradd -g mysql -s /sbin/nologin -M mysql
chown mysql.mysql -R $MYSQL_PATH
$MYSQL_PATH/scripts/mysql_install_db --user=mysql --basedir=$MYSQL_PATH --datadir=$MYSQL_PATH/data
rm -rf /etc/my.cnf
cp $MYSQL_PATH/support-files/mysql.server /etc/init.d/mysqld
sed -i '46s/$/\/usr\/local\/mysql/g' /etc/init.d/mysqld
sed -i '47s/$/\/usr\/local\/mysql\/data/g' /etc/init.d/mysqld
sed -i '263s/datadir/basedir/g' /etc/init.d/mysqld
echo "[mysqld]
basedir=$MYSQL_PATH
datadir=$MYSQL_PATH/data
socket=$MYSQL_PATH/mysqld.sock
user = mysql
port = 3306
server_id = 2
#log-bin = mysql-bin
#log_bin_index = binlog.index
character_set_server = utf8
#lower_case_table_names = 1
#binlog_ignore_db = mysql
#replicate-do-db = mysql
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
innodb_file_per_table=1
[mysql.server]
character_set_server = utf8
socket=$MYSQL_PATH/mysqld.sock
[client]
socket=$MYSQL_PATH/mysqld.sock
#character_set_server = utf8
default-character-set = utf8
[mysqld_safe]
log-error=$MYSQL_PATH/mysqld.errorlog
pid-file=$MYSQL_PATH/localhost.localdomain.pid
character_set_server = utf8
[mysql]
socket=$MYSQL_PATH/mysqld.sock
#character_set_server = utf8
default-character-set = utf8
[mysqldump]
socket=$MYSQL_PATH/mysqld.sock
default-character-set = utf8
[mysqladmin]
socket=$MYSQL_PATH/mysqld.sock
character_set_server = utf8" > $MYSQL_PATH/my.cnf
echo -e "export MYSQL_HOME=\"$MYSQL_PATH\"
export PATH=\"\$PATH:\$MYSQL_HOME/bin\"" >> /etc/profile
. /etc/profile
echo "mysql -V"
mysql -V
sleep 5
/etc/init.d/mysqld start
netstat -ntpl |grep "3306"
}
htop_package_install() {
cd ${package_dir}
yum install wget -y
if [ ! -f "$htop_install_package" ]; then
wget ftp://$soft_ftp_server/$htop_install_package --ftp-user=$ftp_user --ftp-password=$ftp_password
fi
rpm -ivh $htop_install_package
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
yum install htop -y
}
#prompt_message() {
#}
menu
while :
do
echo -en "${blue_col}请选择相应的操作[1-11], 显示菜单[m]: ${reset_col}"
read choice
case $choice in
1)
process_name="nginx"
package_install_init
Prompt_information
nginx_package_install
install_finish
;;
2)
process_name="memcached"
package_install_init
Prompt_information
memcached_package_install
install_finish
;;
3)
process_name="redis"
package_install_init
Prompt_information
redis_package_install
install_finish
;;
4)
process_name="rabbitmq"
package_install_init
Prompt_information
rabbitmq_package_install
install_finish
;;
5)
process_name="kestrel"
package_install_init
Prompt_information
kestrel_package_install
install_finish
;;
6)
process_name="node"
package_install_init
Prompt_information
node_package_install
install_finish
;;
7)
process_name="jdk"
package_install_init
Prompt_information
jdk_package_install
install_finish
;;
8)
process_name="mongodb"
package_install_init
Prompt_information
mongodb_package_install
install_finish
;;
9)
process_name="mysql"
package_install_init
Prompt_information
mysql_package_install
install_finish
;;
10)
process_name="jdk"
package_install_init
Prompt_information
jdk8_package_install
install_finish
;;
11)
process_name="redis"
package_install_init
Prompt_information
redis3_package_install
install_finish
;;
12)
process_name="htop"
package_install_init
Prompt_information
htop_package_install
install_finish
;;
m|M)
clear
menu
;;
q|Q)
exit
;;
'')
;;
*)
echo -e "$red_col输入错误,请重新输入! $reset_col"
esac
done