一健安装游戏环境脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一健安装游戏环境脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash #脚本功能:nginx1.10.2安装,SVN1.9.5安装,Redis3.0.5安装,Memcached1.4.24安装,Tomcat7.0.73安装,jdk-8u101-linux-x64安装,mysql5.1安装 ######################################源码包下载链接######################################## #========tomcat链接========= #http://mirrors.cnnic.cn/apache/tomcat/tomcat-7/v7.0.73/bin/apache-tomcat-7.0.73.tar.gz #=========redis链接========= #http://download.redis.io/releases/redis-3.0.5.tar.gz #=======libevent链接======== #http://down1.chinaunix.net/distfiles/libevent-2.0.20-stable.tar.gz #=======memcahed链接======== #http://www.memcached.org/files/memcached-1.4.24.tar.gz #=======pcre链接======== #http://exim.mirror.fr/pcre/pcre-8.38.tar.gz #=======openssl链接======== #http://distfiles.macports.org/openssl/openssl-1.0.2f.tar.gz #=======zlib链接======== #http://down1.chinaunix.net/distfiles/zlib-1.2.7.tar.gz #=======nginx链接======== #http://nginx.org/download/nginx-1.10.2.tar.gz ########################################################### ### 定义变量 ### ########################################################### #-----------安装包名和安装包文件夹名定义-------------- #===jdk8安装包名和包文件名定义==== JDK_PCAKGE=‘jdk-8u101-linux-x64.tar.gz‘ JDK_DIRECTORY=‘jdk1.8.0_101‘ #===Tomcat7安装包名和包文件名定义=== TOMCAT_PCAKGE=‘apache-tomcat-7.0.73.tar.gz‘ TOMCAT_DIRECTORY=‘apache-tomcat-7.0.73‘ #===redis安装包名和包文件名定义=== REDIS_PCAKGE=‘redis-3.0.5.tar.gz‘ REDIS_DIRECTORY=‘redis-3.0.5‘ #===libevent安装包名和包文件名定义=== LIBEVENT_PCAKGE=‘libevent-2.0.20-stable.tar.gz‘ LIBEVENT_DIRECTORY=‘libevent-2.0.20-stable‘ #===makecache安装包名和包文件名定义=== MAKECACHE_PCAKGE=‘memcached-1.4.24.tar.gz‘ MAKECACHE_DIRECTORY=‘memcached-1.4.24‘ #===pcre安装包名和包文件名定义=== PCRE_PCAKGE=‘pcre-8.38.tar.gz‘ PCRE_DIRECTORY=‘pcre-8.38‘ #===openssl安装包名和包文件名定义=== OPENSSL_PCAKGE=‘openssl-1.0.2f.tar.gz‘ OPENSLL_DIRECTORY=‘openssl-1.0.2f‘ #===zlib安装包名和包文件名定义=== ZLIB_PCAKGE=‘zlib-1.2.8.tar.gz‘ ZLIB_DIRECTORY=‘zlib-1.2.8‘ #===nginx安装包名和包文件名定义=== NGINX_PCAKGE=‘nginx-1.10.2.tar.gz‘ NGINX_DIRECTORY=‘nginx-1.10.2‘ #===svn.repo文件名=== SVN_PACKAGE=‘wandisco-svn.repo‘ #-------------颜色定义------------------------- BLUEH="\033[36m" TAILS="\033[0m" OUTPUT="echo -e" RED="\033[31m" GREEN="\033[32m" GREEN="\033[32m" FLICKER="\033[05m" #-------------------路径与文件名定义----------------- FILE=‘file‘ DIR=`dirname $0` LOG_NAME=‘install.log‘ PACKAGE_PATH=`cd $DIR && pwd` FILE_PATH=$PACKAGE_PATH/$FILE INSTALL_LOG=$FILE_PATH/$LOG_NAME #---------------------安装包下载地址和命令------------------ GET=‘wget -c -P‘ URL=‘http://192.168.1.1/‘ #-----------检测与创建定义的文件、目录---------------- [ -d $FILE_PATH ] || mkdir $FILE_PATH > $INSTALL_LOG #------------------服务器IP地址定义------------------ IP=`ifconfig | grep ‘inet addr‘ | head -1 | awk -F‘:‘ ‘{print $2}‘ | awk ‘{print $1}‘` #--------------------加载函数库--------------------- . /etc/init.d/functions ###########################输出提示信息############################ echo ‘‘ echo ‘‘ echo ‘‘ echo "###########################################################" echo "### ###" echo "### 《特战英雄》服务端运行环境 一键安装脚本 ###" echo "### ###" echo "###########################################################" echo ‘‘ ########################################################### ### 定义函数 ### ########################################################### #下载Yum function yumInstall { #安装编译依赖包 yum -y install gcc gcc-c++ wget elink mysql-server mysql if [ $? -eq 1 ];then #检查网络 $OUTPUT --------------------$BLUEH【 正在检查网络,请稍候 】$TAILS-------------------- echo echo "#Yum安装" >> $INSTALL_LOG ping www.baidu.com -c 3 &> /dev/null [ $? -eq 0 ] && echo "网络正常" >> $INSTALL_LOG || { action "你的网络不通,请修复你的网络,然后再进行安装,脚本退出" /bin/false echo "@你的网络不通,请修复你的网络,然后再进行安装,脚本在此步退出" >> $INSTALL_LOG exit 2 } [ -d /etc/yum.repos.d/other ] || mkdir /etc/yum.repos.d/other mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/other wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo [ $? -eq 0 ] && echo "yum源下载成功" >> $INSTALL_LOG || { action "yum源下载失败,脚本退出" /bin/false echo "@yum源下载失败,脚本在此步退出" >> $INSTALL_LOG exit 2 } echo >> $INSTALL_LOG echo >> $INSTALL_LOG yum clean all yum makecache fi } #Svn安装 function svnInstall { echo "############# Svn1.8安装 #############" >> $INSTALL_LOG $GET /etc/yum.repos.d/ $URL$SVN_PACKAGE [ $? -eq 0 ] && echo "svn包下载成功" >> $INSTALL_LOG || echo "svn包下载失败" >> $INSTALL_LOG yum clean all yum -y install subversion-1.8.4 subversion-devel-1.8.4 [ $? -eq 0 ] && echo "yum安装成功" >> $INSTALL_LOG || echo "yum安装失败" >> $INSTALL_LOG echo >> $INSTALL_LOG echo >> $INSTALL_LOG sleep 2 } #Jdk安装 function jdkInstall { echo "############# Jdk8u101安装 #############" >> $INSTALL_LOG $GET $FILE_PATH $URL$JDK_PCAKGE cd $FILE_PATH && tar xf $JDK_PCAKGE [ $? -eq 0 ] && echo "jdk包解压成功" >> $INSTALL_LOG || echo "@jdk包解压失败" >> $INSTALL_LOG [ -d /usr/local/jdk ] && rm -rf /usr/local/jdk mv $JDK_DIRECTORY /usr/local/jdk [ $? -eq 0 ] && echo "jdk目录移动成功" >> $INSTALL_LOG || echo "@jdk目录移动失败" >> $INSTALL_LOG echo ‘export JRE_HOME=/usr/local/jdk‘ >> /etc/profile echo ‘export JAVA_BIN=/usr/local/jdk/bin‘ >> /etc/profile echo ‘export PATH=$JRE_HOME/bin:$PATH‘ >> /etc/profile echo ‘export CLASSPATH=.:$JRE_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar‘ >> /etc/profile echo ‘export JRE_HOME JAVA_BIN PATH CLASSPATH‘ >> /etc/profile . /etc/profile echo >> $INSTALL_LOG echo >> $INSTALL_LOG } #Tomcat安装 function tomcatAllInstall { function tomcat_install { echo "############# Tomcat7.0.73安装 #############" >> $INSTALL_LOG $GET $FILE_PATH $URL$TOMCAT_PCAKGE [ $? -eq 0 ] && echo "tomcat包下载成功" >> $INSTALL_LOG || echo "@tomcat下载失败" >> $INSTALL_LOG cd $FILE_PATH && tar zxf $TOMCAT_PCAKGE [ $? -eq 0 ] && echo "tomcat包解压成功" >> $INSTALL_LOG || echo "@tomcat包解压失败" >> $INSTALL_LOG [ -d /usr/local/tomcat ] && rm -rf /usr/local/tomcat cp -r $TOMCAT_DIRECTORY /usr/local/tomcat [ $? -eq 0 ] && echo "tomcat目录拷贝成功" >> $INSTALL_LOG || echo "@tomcat目录拷贝失败" >> $INSTALL_LOG chmod +x /usr/local/tomcat/bin/*.sh [ $? -eq 0 ] && echo "tomcat的sh文件添加权限成功" >> $INSTALL_LOG || echo "@tomcat的sh文件添加权限失败" >> $INSTALL_LOG #/usr/local/tomcat/bin/startup.sh #[ $? -eq 0 ] && echo "tomcat启动成功" >> $INSTALL_LOG || echo "@tomcat启动失败" >> $INSTALL_LOG echo >> $INSTALL_LOG echo >> $INSTALL_LOG } tomcat_install } #Redis安装 function redisInstall { echo "############# Redis3.0.5安装 ############# " >> $INSTALL_LOG $GET $FILE_PATH $URL$REDIS_PCAKGE [ $? -eq 0 ] && echo "redis包下载成功" >> $INSTALL_LOG || echo "@redis下载失败" >> $INSTALL_LOG cd $FILE_PATH && tar xf $REDIS_PCAKGE [ $? -eq 0 ] && echo "redis包解压成功" >> $INSTALL_LOG || echo "@redis包解压失败" >> $INSTALL_LOG cd $REDIS_DIRECTORY [ $? -eq 0 ] && echo "redis进入目录成功" >> $INSTALL_LOG || echo "@redis进入目录失败" >> $INSTALL_LOG make MALLOC=libc [ $? -eq 0 ] && cd ..;echo "redis包配置成功" >> $INSTALL_LOG || echo "@redis包配置失败" >> $INSTALL_LOG cd $FILE_PATH/$REDIS_DIRECTORY make PREFIX=/usr/local/redis install [ $? -eq 0 ] && echo "redis包编译成功" >> $INSTALL_LOG || echo "@redis包编译失败" >> $INSTALL_LOG echo ‘PATH=/usr/local/redis/bin:$PATH‘ >> /etc/profile . /etc/profile [ -d /usr/local/redis/conf ] || mkdir /usr/local/redis/conf cp redis.conf /usr/local/redis/conf/ [ $? -eq 0 ] && echo "redis.conf配置文件拷贝成功" >> $INSTALL_LOG || echo "@redis.conf配置文件拷贝失败" >> $INSTALL_LOG #sed -i "46s#/var/run/redis.pid#/usr/local/redis/conf/redis.pid#" /usr/local/redis/conf/redis.conf #[ $? -eq 0 ] && echo "redis.pid修改路径成功" >> $INSTALL_LOG || echo "@redis.pid修改路径失败" >> $INSTALL_LOG sed -i "192s#./#/usr/local/redis/conf/#" /usr/local/redis/conf/redis.conf [ $? -eq 0 ] && echo "redis.conf修改路径成功" >> $INSTALL_LOG || echo "@redis.conf修改路径失败" >> $INSTALL_LOG echo vm.overcommit_memory = 1 >> /etc/sysctl.conf #nohup redis-server /usr/local/redis/conf/redis.conf &> /dev/null & #[ $? -eq 0 ] && echo "redis启动成功" >> $INSTALL_LOG || echo "@redis启动失败" >> $INSTALL_LOG echo >> $INSTALL_LOG echo >> $INSTALL_LOG } #Memcached安装 function memAllInstall { #安装libevent包 function libevent_install { echo "############# Memcached1.4.24安装 #############" >> $INSTALL_LOG echo "#libevent依赖包安装" >> $INSTALL_LOG $GET $FILE_PATH $URL$LIBEVENT_PCAKGE [ $? -eq 0 ] && echo "libevent包下载成功" >> $INSTALL_LOG || echo "@libevent下载失败" >> $INSTALL_LOG cd $FILE_PATH && tar zxf $LIBEVENT_PCAKGE [ $? -eq 0 ] && echo "libevent包解压成功" >> $INSTALL_LOG || echo "@bevent包解压失败" >> $INSTALL_LOG cd $FILE_PATH/$LIBEVENT_DIRECTORY [ $? -eq 0 ] && echo "libevent进入目录成功" >> $INSTALL_LOG || echo "@libevent进入目录失败" >> $INSTALL_LOG ./configure [ $? -eq 0 ] && echo "libevent包配置成功" >> $INSTALL_LOG || echo "@libevent包配置失败" >> $INSTALL_LOG make [ $? -eq 0 ] && echo "libevent包编译成功" >> $INSTALL_LOG || echo "@libevent包编译失败" >> $INSTALL_LOG make install [ $? -eq 0 ] && echo "libevent包安装成功" >> $INSTALL_LOG || echo "@libevent包安装失败" >> $INSTALL_LOG echo "/usr/local/lib" > /etc/ld.so.conf.d/libevent.conf [ $? -eq 0 ] && echo "/usr/local/lib重定向成功" >> $INSTALL_LOG || echo "@/usr/local/lib重定向失败" >> $INSTALL_LOG ldconfig [ $? -eq 0 ] && echo "ldconfig成功" >> $INSTALL_LOG || echo "@ldconfig失败" >> $INSTALL_LOG echo >> $INSTALL_LOG } #安装memcached包 function memcached_install { echo "#memcached包安装" >> $INSTALL_LOG $GET $FILE_PATH $URL$MAKECACHE_PCAKGE [ $? -eq 0 ] && echo "memcached包下载成功" >> $INSTALL_LOG || echo "@memcached下载失败" >> $INSTALL_LOG cd $FILE_PATH && tar zxf $MAKECACHE_PCAKGE [ $? -eq 0 ] && echo "memcached包解压成功" >> $INSTALL_LOG || echo "@memcached包解压失败" >> $INSTALL_LOG cd $FILE_PATH/$MAKECACHE_DIRECTORY [ $? -eq 0 ] && echo "memcached进入目录成功" >> $INSTALL_LOG || echo "@memcached进入目录失败" >> $INSTALL_LOG ./configure --prefix=/usr/local/memcached [ $? -eq 0 ] && echo "memcached包配置成功" >> $INSTALL_LOG || echo "@memcached包配置失败" >> $INSTALL_LOG make [ $? -eq 0 ] && cecho "memcached包编译成功" >> $INSTALL_LOG || echo "@memcached包编译失败" >> $INSTALL_LOG make install [ $? -eq 0 ] && echo "memcached包安装成功" >> $INSTALL_LOG || echo "@memcached包安装失败" >> $INSTALL_LOG #/usr/local/memcached/bin/memcached -l $IP -u root -c 200 -m 500M -n 10 -f 2 -d #[ $? -eq 0 ] && echo "memcached启动成功" >> $INSTALL_LOG || echo "@memcached启动失败" >> $INSTALL_LOG echo >> $INSTALL_LOG echo >> $INSTALL_LOG } libevent_install memcached_install } #Nginx安装 function nginxInstall { echo "############# Nginx1.10.2安装 #############" >> $INSTALL_LOG id nginx &> /dev/null || useradd nginx #pcre包下载解压 $GET $FILE_PATH $URL$PCRE_PCAKGE [ $? -eq 0 ] && echo "pcre包下载成功" >> $INSTALL_LOG || echo "@pcre下载失败" >> $INSTALL_LOG cd $FILE_PATH && tar xf $PCRE_PCAKGE -C /usr/local [ $? -eq 0 ] && echo "pcre包解压成功" >> $INSTALL_LOG || echo "@pcre包解压失败" >> $INSTALL_LOG #openssl包下载解压 $GET $FILE_PATH $URL$OPENSSL_PCAKGE [ $? -eq 0 ] && echo "openssl包下载成功" >> $INSTALL_LOG || echo "@openssl下载失败" >> $INSTALL_LOG tar xf $OPENSSL_PCAKGE -C /usr/local [ $? -eq 0 ] && echo "openssl包解压成功" >> $INSTALL_LOG || echo "@openssl包解压失败" >> $INSTALL_LOG #zlib包下载解压 $GET $FILE_PATH $URL$ZLIB_PCAKGE [ $? -eq 0 ] && echo "zlib包下载成功" >> $INSTALL_LOG || echo "@zlib下载失败" >> $INSTALL_LOG tar xf $ZLIB_PCAKGE -C /usr/local [ $? -eq 0 ] && echo "zlib包解压成功" >> $INSTALL_LOG || echo "@zlib包解压失败" >> $INSTALL_LOG #nginx包下载解压 $GET $FILE_PATH $URL$NGINX_PCAKGE [ $? -eq 0 ] && echo "nginx包下载成功" >> $INSTALL_LOG || echo "@nginx下载失败" >> $INSTALL_LOG tar -zxf $NGINX_PCAKGE [ $? -eq 0 ] && echo "nginx包解压成功" >> $INSTALL_LOG || echo "@nginx包解压失败" >> $INSTALL_LOG #进入目录 NGINX_PCAKGE cd $FILE_PATH/$NGINX_DIRECTORY [ $? -eq 0 ] && echo "nginx进入目录成功" >> $INSTALL_LOG || echo "@nginx进入目录失败" >> $INSTALL_LOG #配置 ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-ipv6 --with-pcre=/usr/local/$PCRE_DIRECTORY --with-zlib=/usr/local/$ZLIB_DIRECTORY --with-openssl=/usr/local/$OPENSLL_DIRECTORY [ $? -eq 0 ] && echo "Nginx配置成功" >> $INSTALL_LOG || echo "@Nginx配置失败" >> $INSTALL_LOG #编译 cd $FILE_PATH/nginx-1.10.2 make [ $? -eq 0 ] && echo "Nginx编译成功" >> $INSTALL_LOG || echo "@Nginx包编译失败" >> $INSTALL_LOG #安装 cd $FILE_PATH/nginx-1.10.2 make install [ $? -eq 0 ] && echo "Nginx安装成功" >> $INSTALL_LOG || echo "@Nginx安装失败" >> $INSTALL_LOG #w创建目录 [ -d /var/cache/nginx ] || mkdir /var/cache/nginx -p #启动服务 #/usr/local/nginx/sbin/nginx #[ $? -eq 0 ] && echo "Nginx启动成功" >> $INSTALL_LOG || echo "@Nginx启动失败" >> $INSTALL_LOG echo >> $INSTALL_LOG echo >> $INSTALL_LOG } #检查服务 function checkService { #Svn检查 echo echo "###################################################" svn --version &> /dev/null && $OUTPUT " " $GREEN Svn安装成功 $TAILS " " || $OUTPUT " " $RED$FLICKER Svn安装失败,请检查 $TAILS " " echo "###################################################" #Redis检查 echo echo echo "###################################################" [ -f /usr/local/redis/conf/redis.conf ] && $OUTPUT " " $GREEN Redis安装成功 $TAILS " " || $OUTPUT " " $RED$FLICKER Redis安装失败,请检查 $TAILS " " ss -tlnp | grep 6379 &> /dev/null && $OUTPUT " " $GREEN Redis已经启动 $TAILS " " || $OUTPUT " " $RED$FLICKER Redis没有启动,请启动 $TAILS " " echo "###################################################" #Memcached检查 echo echo echo "###################################################" [ -d /usr/local/memcached/ ] && $OUTPUT " " $GREEN Memcached安装成功 $TAILS " " || $OUTPUT " " $RED$FLICKER Memcached安装失败,请检查 $TAILS " " ss -tlnp | grep 11211 &> /dev/null && $OUTPUT " " $GREEN Memcached已经启动 $TAILS " " || $OUTPUT " " $RED$FLICKER Memcached没有启动,请启动 $TAILS " " echo "###################################################" #Tomcat检查 echo echo echo "###################################################" [ -d /usr/local/tomcat/ ]&& $OUTPUT " " $GREEN Tomcat安装成功 $TAILS " " || $OUTPUT " " $RED$FLICKER tomcat安装失败,请检查 $TAILS " " ss -tlnp | grep 8005 &> /dev/null && $OUTPUT " " $GREEN Tomcat已经启动 $TAILS " " || $OUTPUT " " $RED$FLICKER Tomcat没有启动,请启动 $TAILS " " echo "###################################################" #Nginx检查 echo echo echo "###################################################" [ -d /usr/local/nginx/ ] && $OUTPUT " " $GREEN Nginx安装成功 $TAILS " " || $OUTPUT " " $RED$FLICKER Nginx安装失败,请检查 $TAILS " " ss -tlnp | grep nginx &> /dev/null && $OUTPUT " " $GREEN Nginx已经启动 $TAILS " " || $OUTPUT " " $RED$FLICKER Nginx没有启动,请启动 $TAILS " " echo "###################################################" } ########################################################### ### 安装函数调用 ### ########################################################### #========= 下面安装顺序请勿修改 ============= yumInstall svnInstall jdkInstall tomcatAllInstall redisInstall memAllInstall nginxInstall checkService
本文出自 “wsyht90的博客” 博客,请务必保留此出处http://wsyht90.blog.51cto.com/9014030/1893601
以上是关于一健安装游戏环境脚本的主要内容,如果未能解决你的问题,请参考以下文章