Shell脚本实现超简洁的在Linux服务器上安装nginx、resin、java、tomcat、redis等程序

1 篇文章 0 订阅

说明:

用平常的方式在Linux服务器上安装程序,需要下载安装包、进入安装包位置、给安装包文件赋予可执行权限、执行安装、设置环境变量……等等一系列复杂的操作。并且如果有关联也需要一个一个的挨着安装。耗时并且繁琐。而用shell脚本来执行这些操作,则很好的解决了这些问题!

步骤:

  1. wget http://img006.com/badusoft/centosupNEW.sh

    // 在Linux服务器上执行wget命令下载shell脚本

  2. chmod +x centosupNEW.sh

    // 给下载下来的 centosupNEW.sh 文件赋可执行权限

  3. ./centosupNEW.sh all

    //执行命令安装所有程序,还可单独安装nginx、redis、tomcat等,如想单独安装resin,则执行 ./centosupNEW.sh resin 命令即可

截图:

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

代码:

#!/bin/bash
#version1.0
#Wangwei
#date 2015/04/02
#System Centos6.4
get_bin_tar="/bin/tar"
get_cmd_dns="/etc/resolv.conf"
get_cmd_soft="/opt/badusoft"
get_cmd_name=`/bin/uname -a | awk '{print $1,$3}'`
get_cmd_service="/usr/local/service"
get_cmd_user=`whoami`
get_cmd_cron="/var/spool/cron/"
get_cmd_url="http://img006.com/badusoft"
echo -e "System for version:\e[32m$get_cmd_name \e[0m\n"
echo -e "Nginx for version:\e[32mTengine2.1 and nginx 1.8.0\e[0m\n"
echo -e "Java for version:\e[32mJdk 1.7\e[0m\n"
echo -e "Resin pro for version:\e[32mResin pro 3.1\e[0m\n"
echo -e "Apache for tomcat version:\e[32m tomcat 7\e[0m\n"
echo -e "Redis version:\e[32m Redis 2.8\e[0m\n"
echo -e "Firewall:\e[32moff\e[0m\n"
cat /dev/null > $get_cmd_dns
echo "nameserver 114.114.114.114" >> $get_cmd_dns
echo -e "NameServer:\e[32m114.114.114.114\e[0m\n"
sleep 10
/etc/init.d/iptables stop
/sbin/chkconfig iptables off
function package(){
        for  i  in wget  gcc gcc-c++ make gzip autoconf automake lrzsz telnet zlib zlib-devel openssl openssl-devel pcre-devel pcre patch net-snmp
        do
    yum install -y $i
    sleep 1
        done
}

function del(){
if  [ ! -d $get_cmd_soft ] && [ ! -d $get_cmd_service ]; then
    mkdir /opt/badusoft >> /dev/null 2>&1
    mkdir /usr/local/service/ >> /dev/null 2>&1
else 
        rm -rf $get_cmd_soft  $get_cmd_service
        cp -f /etc/profile.bak /etc/profile
        mkdir /opt/badusoft >> /dev/null 2>&1
        mkdir /usr/local/service/ >> /dev/null 2>&1
fi
}
function timecron(){
#date cron
if [ $get_cmd_user = "root" ];then
       echo "*/30 * * * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org | /usr/sbin/hwclock -w" > $get_cmd_cron/$get_cmd_user
else
       if [ -f "$get_cmd_cron/root" ];then
               echo "*/30 * * * * /usr/sbin/ntpdate 0.rhel.pool.ntp.org | /usr/sbin/hwclock -w" >> $get_cmd_cron/$get_cmd_user 
       else
               echo "$get_cmd_user error"
               return 0
       fi
fi
}

function sysctl(){
    cd $get_cmd_soft
    if [ ! -f kernels_sysctl ] && [ ! -f limits.conf ];then
    wget $get_cmd_url/kernels_sysctl
    wget $get_cmd_url/limits.conf
    if [ -f $get_cmd_soft/kernels_sysctl ] && [ -f $get_cmd_soft/limits.conf ];then
        #cp -f /etc/sysctl.conf /etc/sysctl.conf.bak
        #cp -f /etc/security/limits.conf /etc/security/limits.conf
        cat $get_cmd_soft/kernels_sysctl > /etc/sysctl.conf
        cp -f  $get_cmd_soft/limits.conf  /etc/security/limits.conf
        /sbin/sysctl -p 
        if [ $? -eq 0 ];then
          echo -e "\e[32mcopy done\e[0m\n"
          sleep 5
        else
            echo -e "\e[31m copy error!!\e[0m\n"
            exit 0
        fi
    else
        echo -e "\e[31mfile not exits\[0m\n"
        exit 0
    fi
    else
        echo -e "\e[31mfile  exists\e[0m\n"
        exit 0
    fi 
 }
function nginx(){
    cd $get_cmd_soft
    if [ ! -f nginx-1.8.0.tar.gz ];then
       wget $get_cmd_url/nginx-1.8.0/nginx-1.8.0.tar.gz
       wget $get_cmd_url/nginx-1.8.0/nginx_upstream_check_module-master.zip
       wget $get_cmd_url/nginx-1.8.0/openssl-1.0.2c.tar.gz
       wget $get_cmd_url/nginx-1.8.0/ngx_cache_purge-2.3.tar.gz
       wget $get_cmd_url/pcre-8.12.tar.gz
       wget $get_cmd_url/zlib-1.2.5.tar.gz

       if [ $? -eq 0 ];then

        $get_bin_tar zxf nginx-1.8.0.tar.gz
        unzip nginx_upstream_check_module-master.zip
        $get_bin_tar zxf openssl-1.0.2c.tar.gz
        $get_bin_tar zxf ngx_cache_purge-2.3.tar.gz
        $get_bin_tar zxf pcre-8.12.tar.gz
        $get_bin_tar zxf zlib-1.2.5.tar.gz

        if [ $? -eq 0 ];then
           cd $get_cmd_soft/nginx-1.8.0

    patch -p1 < $get_cmd_soft/nginx_upstream_check_module-master/check_1.7.5+.patch
./configure --prefix=$get_cmd_service/nginx \
--with-pcre=$get_cmd_soft/pcre-8.12 \
--with-openssl=$get_cmd_soft/openssl-1.0.2c \
--with-zlib=$get_cmd_soft/zlib-1.2.5 \
--add-module=$get_cmd_soft/ngx_cache_purge-2.3 \
--with-http_realip_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_ssl_module \
--add-module=$get_cmd_soft/nginx_upstream_check_module-master

           if [ $? -eq 0 ];then
            make && make install
            if [ $? -eq 0 ];then
               echo -e "\e[32mtengine for nginx install done\e[0m\n"
               sleep 5
            else
               echo -e "\e[31mmake && make error!!\e[0m\n"
            fi
           else
            echo -e "\e[31mconfigure error!!\e[0m\n"
            exit 0
           fi
        else
            echo -e "\e[31mtar error!!\e[0m\n"
            exit 0
        fi  
       else 
        echo -e "\e[31mtengine for nginx download error!!\e[0m\n"
        exit 0      
       fi
    else
        sleep 5
        echo -e "\e[31mtengine for nginx found\e[0m\n"
    fi
}
function java(){
        cd $get_cmd_soft
        if [ ! -f server-jre-7u80-linux-x64.tar.gz ];then
             wget $get_cmd_url/javapath
                     wget  $get_cmd_url/server-jre-7u80-linux-x64.tar.gz
                     $get_bin_tar zxf server-jre-7u80-linux-x64.tar.gz
                if [ $? -eq 0 ];then
                    mv jdk1.7.0_80 $get_cmd_service/java
                    cp -f /etc/profile /etc/profile.bak
                    cat $get_cmd_soft/javapath >> /etc/profile
                    source /etc/profile
                    if [ $? -eq 0 ];then
                        $get_cmd_service/java/bin/java -version
                        if [ $? -eq 0 ];then
                            echo -ne "\e[32mJava install done\e[0m\n"
                            sleep 5
                        else
                            echo -ne  "\e[31mJava install error!!\e[0m\n"
                            exit 0
                        fi
                    else 
                        echo -ne "\e[31mJava path error!!\e[0m\n"
                    fi
                else 
                    echo -ne "\e[31mJava tar error!!\e[0m\n"
                    exit 0
                fi

            else
                echo -ne "\e[31mJava download error\e[0m\n"
                exit 0
            fi  

}

function resin(){
    cd $get_cmd_soft
    if [ ! -f  resin-pro-3.1.12.tar.gz ];then
        wget $get_cmd_url/licenses/004444.license
            wget $get_cmd_url/resin-pro-3.1.12.tar.gz
        if [ $? -eq 0 ];then
            $get_bin_tar zxvf resin-pro-3.1.12.tar.gz
            if [ $? -eq 0 ];then
            cd $get_cmd_soft/resin-pro-3.1.12  
            ./configure --prefix=$get_cmd_service/resin \
            --with-java-home=$get_cmd_service/java \
            --enable-64bit=yes  \
            --enable-lfs  \
            --enable-jni \
            --disable-libtool-lock

            if [ $? -eq 0 ];then
                make && make install
                mkdir $get_cmd_service/resin/licenses
                cp $get_cmd_soft/004444.license $get_cmd_service/resin/licenses
                if [ $? -eq 0 ];then
                echo -ne "\e[32mResin  install done\e[0m\n"
                sleep 5
                else 
                echo -ne "\e[31mResin install error\e[0m\n"
                exit 0
                 fi
            else
                echo -ne  "\e[31mConfigure error\e[0m\n"
                exit 0
            fi
           else
               echo -ne "\e[31mtar error\e[0m\n"
               exit 0
           fi
        else
            echo -ne "\e[31mdownload error\e[0m\n"
            exit 0
        fi
    else 
        echo -ne "\e[31mDircetory or Resin  error!!\e[0m\n"
        exit 0  
    fi
}
function tomcat(){
    mkdir /usr/local/service/apache2

cd /opt/badusoft/

wget http://img006.com/badusoft/apr-1.5.2.tar.zip
wget http://img006.com/badusoft/apr-iconv-1.2.1.tar.bz2
wget http://img006.com/badusoft/apr-util-1.5.4.tar.bz2
wget http://img006.com/badusoft/tomcat-native.tar.gz
wget http://img006.com/badusoft/apache-tomcat-7.0.42.tar.gz


tar -xvf apr-1.5.2.tar.bz2
tar -xvf apr-iconv-1.2.1.tar.bz2
tar -xvf apr-util-1.5.4.tar.bz2
tar -xvf tomcat-native.tar.gz
tar -xvf apache-tomcat-7.0.42.tar.gz

mv /opt/badusoft/apache-tomcat-7.0.42  /usr/local/service/tomcat

cd /opt/badusoft/apr-1.5.2


./configure --prefix=/usr/local/service/apache2/apr

make && make install

echo "APR step over"

###############################################################

cd /opt/badushot/apr-util-1.5.4 


./configure --prefix=/usr/local/service/apache2/apr --with-apr=/usr/local/service/apache2/apr

make && make install

echo "apr-util step over"
##############################################################################


cd /opt/badusoft/tomcat-native-1.1.33-src/jni/native

./configure --prefix=/usr/local/service/apache2/apr --with-apr=/usr/local/service/apache2/apr --with-java-home=/usr/local/service/java


make && make install

echo "tomact-native step over"


echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/service/apache2/apr/lib" >> /etc/profile

source /etc/profile

cd /opt/badusoft/

wget http://img006.com/badusoft/catalina.txt

sed -i '/# limitations under the License./r catalina.txt' /usr/local/service/tomcat/bin/catalina.sh

 }
function redis(){
    cd $get_cmd_soft
    if [ ! -f redis-2.8.12.tar.gz ];then
       wget $get_cmd_url/redis-2.8.12.tar.gz
       if [ $? -eq 0 ];then
        tar zxf redis-2.8.12.tar.gz
        if [ $? -eq 0 ];then
          cd $get_cmd_soft/redis-2.8.12
          make && make install
          if [ $? -eq 0 ];then
             mkdir $get_cmd_service/redis/
             mkdir $get_cmd_service/redis/conf
             mv /usr/local/bin $get_cmd_service/redis/
             cp -f $get_cmd_soft/redis-2.8.12/redis.conf $get_cmd_service/redis/conf/
             echo -e "\e[32m Redis install done\e[0m\n"
             sleep 5
          else
              echo -e "\e[31m make && make install error!!\e[0m\n"
              exit 0
          fi
        else
                echo -e "\e[31m tar error\e[0m\n"
            exit 0
            fi

       else 
           echo -e "\e[31m Download Redis error!!\e[0m\n"
           exit 0
       fi
    else
       echo -e "\e[31m Redis file error!!\e[0m\n"
       exit 0
    fi
}           

case $1 in

package)
    package
;;

timecron)

    package
    del
    timecron
;;

sysctl)

    package
    del
    sysctl
;;


nginx)
    package
    del
    nginx
;;

resin)
    package
    del
    java
    resin

;;
tomcat)

    package
    del
    java
tomcat

;;
redis)
    package
    del
    redis
;;

all)
    package
    del 
    timecron
    sysctl
    nginx
    java
    resin
    tomcat
    redis
;;

*)
    echo -e "\e[32m package  timecron sysctl nginx resin tomcat redis or all\e[0m\n"
;;
esac

cd /opt/badusoft/

wget http://img006.com/badusoft/service.sh

chmod +x service.sh


/opt/badusoft/service.sh
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
1. 使用Nginx作为负载均衡器 在一个高并发的网站中,我们可以使用Nginx作为负载均衡器,将请求分发到多个tomcat服务器上,以提高网站的性能和可靠性。 配置示例: ``` upstream tomcat_servers { server 127.0.0.1:8080 weight=2; server 127.0.0.1:8081 weight=1; server 127.0.0.1:8082 weight=1; } server { listen 80; server_name www.example.com; location / { proxy_pass http://tomcat_servers; } } ``` 2. 使用tomcat作为应用服务器 在一个Java Web应用中,我们可以使用tomcat作为应用服务器,部署我们的Java应用程序。我们可以通过修改tomcat的配置文件,来优化应用的性能和可靠性。 配置示例: ``` <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context path="/" docBase="/path/to/your/webapp" reloadable="true" /> ``` 3. 使用redis作为缓存服务器 在一个高并发的应用中,我们可以使用redis作为缓存服务器,将一些频繁读取的数据缓存到redis中,以减轻数据库的压力。 示例代码: ``` import redis.clients.jedis.Jedis; public class RedisCache { private static Jedis jedis; static { jedis = new Jedis("127.0.0.1", 6379); } public static void set(String key, String value) { jedis.set(key, value); } public static String get(String key) { return jedis.get(key); } } ``` 4. 使用Mysql作为数据库服务器 在一个应用中,我们可以使用Mysql作为数据库服务器,存储我们的数据。我们可以通过优化Mysql的配置,来提高数据库的性能和可靠性。 配置示例: ``` [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql symbolic-links=0 innodb_file_per_table=1 innodb_buffer_pool_size=2G innodb_flush_method=O_DIRECT innodb_flush_log_at_trx_commit=2 max_connections=1000 query_cache_type=1 query_cache_size=64M query_cache_limit=2M ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晓呆同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值