#!/bin/bash # 这个脚本用来安装游戏服务端 # 先调用依赖函数 source ./Functionlib/variable.sh # 提供函数( Echo_Red , Echo_Green , Tips_Confirm , See_Install_Loading ) # 这个函数先定义目录变量, 路径需要以脚本路劲为基本路径 function Ready_Install(){ BASE_DIR=`pwd` Packages_Save_Dir="./Install_Packages" # 软件安装包的目录 Game_Dir="./trunk" # 游戏目录(如果需要安装环境后打开游戏) Game_BuShu_Dir="/root/" # 游戏部署目录 # 如果需要安装环境后打开游戏, 就取消下面行的注释 # [ ! -d $Game_Dir ] && Echo_Red "ERROR: No Such This Dir!" && exit # Game_Dir=$BASE_DIR/$Game_Dir [ ! -d $Packages_Save_Dir ] && Echo_Red "ERROR: No Such This Dir!" && exit Packages_Save_Dir=$BASE_DIR/$Packages_Save_Dir [ ! -d $Game_BuShu_Dir ] && Echo_Red "ERROR: No Such This Dir!" && exit } # 这个函数用来确定软件版本 function Soft_Version(){ function Check_Version (){ if [ ! -e $Packages_Save_Dir/$1 ] then Echo_Red "[NO]\t$1" Echo_Red "Please Make Sure Soft Version!: $1" && exit else Echo_Green "[OK]\t$1" fi } for i in \ "boost_1_64_0.tar.gz" \ "google_apputils-0.4.2-py2.7.egg" \ "hiredis-master.zip" \ "libevent-2.1.8-stable.tar.gz" \ "lua-5.3.0.tar.gz" \ "lua-cjson-2.1.0.tar.gz" \ "lualogging-1.1.4.tar.gz" \ "luasocket-2.0.2.tar.gz" \ "protobuf-2.6.1.tar.gz" \ "protoc-gen-lua-master.zip" \ "Python-3.6.1.tgz" \ "redis-4.0.2.tar.gz" \ "setuptools-41.2.0-py2.py3-none-any.whl" do Check_Version $i done echo } # 确定安装游戏 function Check_install(){ yum install which make gcc-c++ -y # 安装需要的软件 Install_Path="./Install_Path" [ ! -d $Install_Path ] && mkdir $Install_Path Install_Path=$BASE_DIR/$Install_Path echo -e "\033[34m\033[01mGameService Will Install\033[0m" read -p "Path is $Install_Path ? Input Yes or Y install !" confirm Tips_Confirm $confirm # 当前运行目录./(BASE_DIR) Echo_Green "Start Install...See $Install_Path/Install_Status To Check Status!" Echo_Red "Can Press Ctrl+c Cancel now" sleep 10 [ ! -e $Install_Path/Install_Status ] && echo " [NO] boost_1_64_0.tar.gz [NO] google_apputils-0.4.2-py2.7.egg [NO] hiredis-master.zip [NO] libevent-2.1.8-stable.tar.gz [NO] lua-5.3.0.tar.gz [NO] lua-cjson-2.1.0.tar.gz [NO] lualogging-1.1.4.tar.gz [NO] luasocket-2.0.2.tar.gz [NO] protobuf-2.6.1.tar.gz [NO] protoc-gen-lua-master.zip [NO] Python-3.6.1.tgz [NO] redis-4.0.2.tar.gz [NO] setuptools-41.2.0-py2.py3-none-any.whl " > $Install_Path/Install_Status } ########################################################## 检查完成 ############################################ ######################################################### 下面开始安装 ############################################ ###################################################### 安装libevent ############################################### function Install_libevent(){ cd $Install_Path See_Install_Loading # 当前运行目录( ./Install_Path ) Echo_Green "Install libevent.....!" sleep 10 sed -i "/libevent-2.1.8-stable.tar.gz/s/NO/INSTALL/" ./Install_Status mv $Packages_Save_Dir/libevent-2.1.8-stable.tar.gz ./ tar xf libevent-2.1.8-stable.tar.gz && rm -rf libevent-2.1.8-stable.tar.gz cd libevent-2.1.8-stable # 当前目录 ( ./Install_Path/libevent-2.1.8-stable ) ./configure --prefix=/usr sed -i '/^CFLAGS/s/-Wlogical-op/-Wlogical-op -fPIC/' Makefile make clean make -j `cat /proc/cpuinfo | grep proce | wc -l` make install cd $Install_Path rm -rf $Install_Path/libevent-2.1.8-stable # 当前目录 ( ./Install_Path ) ls /usr/lib | grep libevent if [ $? -eq 0 ] then sed -i "/libevent-2.1.8-stable.tar.gz/s/INSTALL/YES/" ./Install_Status Echo_Green "libevent SUCCESS!" else sed -i "/libevent-2.1.8-stable.tar.gz/s/INSTALL/FAILURE/" ./Install_Status Echo_Red "libevent FAILURE!" fi sleep 5 See_Install_Loading } ###################################################### 安装Lua ############################################### function Install_lua(){ cd $Install_Path See_Install_Loading # 当前目录( ./Install_Path ) Echo_Green "Install Lua.....!" sleep 10 sed -i "/lua-5.3.0.tar.gz/s/NO/INSTALL/" ./Install_Status mv $Packages_Save_Dir/lua-5.3.0.tar.gz ./ tar xf lua-5.3.0.tar.gz && rm -rf lua-5.3.0.tar.gz cd lua-5.3.0 # 当前目录 ( ./Install_Path/lua-5.3.0 ) yum install ncurses-devel readline-devel -y make linux make install cd $Install_Path # 当前目录 ( ./Install_Path ) rm -rf $Install_Path/lua-5.3.0 if [ -e /usr/local/include/lua.h ] then sed -i "/lua-5.3.0.tar.gz/s/INSTALL/YES/" ./Install_Status Echo_Green "Lua SUCCESS!" else sed -i "/lua-5.3.0.tar.gz/s/INSTALL/FAILURE/" ./Install_Status Echo_Red "Lua FAILURE!" fi sleep 5 See_Install_Loading } ###################################################### 安装luasocket ############################################### function Install_luasocket() { cd $Install_Path See_Install_Loading # 当前目录 , ( ./Install_Path ) Echo_Green "Install luasocket.....!" sleep 10 sed -i "/luasocket-2.0.2.tar.gz/s/NO/INSTALL/" ./Install_Status mv $Packages_Save_Dir/luasocket-2.0.2.tar.gz ./ tar xf luasocket-2.0.2.tar.gz rm -rf luasocket-2.0.2.tar.gz cd luasocket-2.0.2 # 当前目录 ( ./Install_Path/luasocket-2.0.2 ) sed -i 's/luaL_Reg/luaL_reg/g' /usr/local/include/lauxlib.h make && make install cd $Install_Path rm -rf $Install_Path/luasocket-2.0.2 # 当前目录 ( ./Install_Path ) if [ -e /usr/local/share/lua/5.1/socket.lua ] then sed -i "/luasocket-2.0.2.tar.gz/s/INSTALL/YES/" ./Install_Status Echo_Green "luasocket SUCCESS!" else sed -i "/luasocket-2.0.2.tar.gz/s/INSTALL/FAILURE/" ./Install_Status Echo_Red "luasocket FAILURE!" fi sleep 5 See_Install_Loading } ###################################################### 安装lualogging ############################################### function Install_lualogging(){ cd $Install_Path # 当前目录 ( ./Install_Path ) Echo_Green "Install lualogging.....!" sleep 10 sed -i "/lualogging-1.1.4.tar.gz/s/NO/INSTALL/" ./Install_Status mv $Packages_Save_Dir/lualogging-1.1.4.tar.gz ./ tar xf lualogging-1.1.4.tar.gz rm -rf lualogging-1.1.4.tar.gz cd lualogging-1.1.4 # 当前目录 ( ./Install_Path/lualogging-1.1.4 ) make make install cd $Install_Path # 当前目录 ( ./Install_Path ) rm -rf $Install_Path/lualogging-1.1.4 if [ -e /usr/local/share/lua/5.1/logging.lua ] then sed -i "/lualogging-1.1.4.tar.gz/s/INSTALL/YES/" ./Install_Status Echo_Green "lualogging SUCCESS!" else sed -i "/lualogging-1.1.4.tar.gz/s/INSTALL/FAILURE/" ./Install_Status Echo_Red "lualogging FAILURE!" fi sleep 5 See_Install_Loading } ###################################################### 安装Luacjson ############################################### function Install_lua_csjson(){ cd $Install_Path # 当前目录 ( ./Install_Path ) See_Install_Loading Echo_Green "Instlal luacjson.....!" sleep 10 sed -i "/lua-cjson-2.1.0.tar.gz/s/NO/INSTALL/" ./Install_Status mv $Packages_Save_Dir/lua-cjson-2.1.0.tar.gz ./ tar xf lua-cjson-2.1.0.tar.gz rm -rf lua-cjson-2.1.0.tar.gz cd lua-cjson-2.1.0 # 当前工作目录, 安装目录/ lua-cjson-2.1.0 sed -i 's/luaL_Reg/luaL_reg/' lua_cjson.c make make install cd $Install_Path # 当前目录 ( ./Install_Path ) rm -rf $Install_Path/lua-cjson-2.1.0 if [ -e /usr/local/lib/lua/5.1/cjson.so ] then sed -i "/lua-cjson-2.1.0.tar.gz/s/INSTALL/YES/" ./Install_Status Echo_Green "luacjson SUCCESS!" else sed -i "/lua-cjson-2.1.0.tar.gz/s/INSTALL/FAILURE/" ./Install_Status Echo_Green "luacjson FAILURE!" fi sleep 5 See_Install_Loading } ###################################################### 安装boost库 ############################################### function Install_BOOST(){ yum install gcc gcc-c++ -y cd $Install_Path See_Install_Loading # 当前目录 ( ./Install_Path ) Echo_Green "Install Boost.....!" sleep 10 sed -i "/boost_1_64_0.tar.gz/s/NO/INSTALL/" ./Install_Status mv $Packages_Save_Dir/boost_1_64_0.tar.gz ./ tar xf boost_1_64_0.tar.gz rm -rf boost_1_64_0.tar.gz cd boost_1_64_0 ./bootstrap.sh prefix=path/to/installation/prefix ./bjam install cd $Install_Path rm -rf $Install_Path/boost_1_64_0 ls /usr/local/lib/libboost_* if [ $? -eq 0 ] then sed -i "/boost_1_64_0.tar.gz/s/INSTALL/YES/" ./Install_Status Echo_Green "Boost SUCCESS!" else sed -i "/boost_1_64_0.tar.gz/s/INSTALL/FAILURE/" ./Install_Status Echo_Red "Boost FAILURE!" fi sleep 10 See_Install_Loading } ###################################################### 安装protocol ##################################################### function Install_protocol(){ cd $Install_Path See_Install_Loading Echo_Green "Install protocol.....!" sleep 10 sed -i "/protobuf-2.6.1.tar.gz/s/NO/INSTALL/" ./Install_Status mv $Packages_Save_Dir/protobuf-2.6.1.tar.gz ./ tar xf protobuf-2.6.1.tar.gz rm -rf protobuf-2.6.1.tar.gz cd protobuf-2.6.1 ./configure make make install sed -i "/google_apputils-0.4.2-py2.7.egg/s/NO/INSTALL/" ../Install_Status Echo_Green "Install google_apputils-0.4.2-py2.7.....!" sleep 5 See_Install_Loading cd python mv $Packages_Save_Dir/google_apputils-0.4.2-py2.7.egg ./ yum install python3 -y # 当前目录 ( ./Install_Path/protocol/python ) python setup.py install cd $Install_Path # 当前工作目录, 安装目录 # rm -rf $Install_Path/protobuf-2.6.1 if [ -d /usr/local/include/google/protobuf/ ] then sed -i "/protobuf-2.6.1.tar.gz/s/INSTALL/YES/" ./Install_Status sed -i "/google_apputils-0.4.2-py2.7.egg/s/INSTALL/YES/" ./Install_Status Echo_Green "protocol SUCCESS!" Echo_Green "google_apputils SUCCESS!" else sed -i "/protobuf-2.6.1.tar.gz/s/INSTALL/FAILURE/" ./Install_Status sed -i "/google_apputils-0.4.2-py2.7.egg/s/INSTALL/FAILURE/" ./Install_Status Echo_Green "protocol FAILURE!" Echo_Green "google_apputils FAILURE!" fi sleep 10 See_Install_Loading } ###################################################### 安装protoc-gen-lua ################################################### function Install_protoc_gen_lua(){ cd $Install_Path See_Install_Loading Echo_Green "Install protoc-gen-lua" sleep 5 sed -i '/protoc-gen-lua-master.zip/s/NO/INSTALL/' ./Install_Status mv $Packages_Save_Dir/protoc-gen-lua-master.zip ./ yum install unzip -y unzip protoc-gen-lua-master.zip rm -rf protoc-gen-lua-master.zip cd protoc-gen-lua-master cd protobuf make ln -sf $Install_Path/protoc-gen-lua-master/plugin/protoc-gen-lua /usr/local/bin/ cd $Install_Path sed -i "/protoc-gen-lua-master.zip/s/INSTALL/YES/" ./Install_Status Echo_Green "protocol SUCCESS!" sleep 2 See_Install_Loading } ###################################################### 安装hiredis-master ############################################### function Install_hiredis_master(){ cd $Install_Path See_Install_Loading # 当前工作目录, 安装目录 Echo_Green "Install hiredis-master" sleep 2 sed -i "/hiredis-master.zip/s/NO/INSTALL/" ./Install_Status mv $Packages_Save_Dir/hiredis-master.zip ./ yum install unzip -y unzip hiredis-master.zip rm -rf hiredis-master.zip cd hiredis-master # 当前工作目录, 安装目录/ hiredis-master make make install cd $Install_Path # 当前工作目录, 安装目录 sed -i "/hiredis-master/s/INSTALL/YES/" ./Install_Status Echo_Green "hiredis-master SUCCESS!" sleep 2 See_Install_Loading } ########################################## 部署 ########################### function BuShu_Game(){ # systemctl disable firewalld # systemctl stop firewalld setenforce 0 echo "ulimit -c " >> /etc/bashrc echo "ulimit -n 65535" >> /etc/bashrc } function must_run(){ Ready_Install # 提供全局变量, 必须运行 Soft_Version # 确定软件包版本, 必须运行 Check_install # 确认安装, 必须运行 } function start_install() { Install_libevent # libevent Install_lua # lua Install_luasocket # luasocket Install_lualogging # lualogging Install_lua_csjson # luacjson Install_BOOST # boost #Install_protocol # protocol Install_protoc_gen_lua } function main(){ must_run start_install BuShu_Game for i in {1..50} do Echo_Green "Server Install Success!!!!!" done } version="2.0" main