#!/bin/sh
#本腳本用於安裝外網服務器
#安裝在Centos5.10及以上版本的純淨機裏
#主要實現如下功能:
# 1.下載安裝G++ C++編譯環境
# 2.命令行工具、拼寫工具
# 3.安裝MySQL
# 4.安裝PHP
# 5.安裝Nginx
# 6.安裝Rsync同步工具
echo "安裝g++ gcc-c++ curses...."
yum -y install g++
yum -y install gcc-c++
yum -y install ncurses
yum -y install ncurses-devel
echo "建立本地遊戲目錄"
mkdir /data
mkdir /data/nginx_logs/
mkdir /data/game/
mkdir /data/game/Server/
mkdir /data/www/
mkdir /data/www/MuArt/
mkdir /data/www/game_web/
echo "安裝 gamin..."
yum -y install gamin
yum -y install gamin-devel
echo "安裝 gflags..."
tar -xzvf gflags-2.0.tar.gz
cd gflags-2.0
./configure
make && make install
cd ..
echo "安裝 boost..."
cd boost
rpm -ivh boost-test-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-regex-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-math-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-date-time-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-system-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-filesystem-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-graph-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-serialization-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-signals-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-python-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-program-options-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-iostreams-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-thread-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-wave-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-1.39.0-9.el5.x86_64.rpm --nodeps
rpm -ivh boost-devel-1.39.0-9.el5.x86_64.rpm --nodeps
cd ..
echo /usr/local/lib >> /etc/ld.so.conf
ldconfig
echo "安裝mysql開發版*********這個步驟必定必定不能少!!!!************"
mkdir /data
yum -y install mysql-devel
echo "安裝 mysql.."
tar -xzvf mysql-5.0.95.tar.gz
cd mysql-5.0.95
./configure --prefix=/usr/local/mysql --datadir=/data/mysql --enable-thread-safe-client --without-isam --without-bench --without-innodb --enable-ssembler CFLAGS="-m64 -fPIC" CXX=gcc CXXFLAGS="-m64 -felide-constructors -fno-rtti -fPIC"
make && make install
#複製已經作好的mysql配置文件到etc下面
cd ..
cp my.cnf /etc/my.cnf
cd mysql-5.0.95
cp support-files/mysql.server /etc/init.d/mysqld
#增長mysql用戶、用戶組
groupadd mysql
useradd -g mysql mysql
#給予受權
chown -R root /usr/local/mysql
chgrp -R mysql /usr/local/mysql
cd /usr/local/mysql
chown mysql.mysql -R .
chown mysql.mysql -R /data/mysql
chmod 777 /etc/init.d/mysqld
bin/mysql_install_db --user=mysql --datadir=/data/mysql
#開啓服務
service mysqld start
#添加MySQL服務的自啓動
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
#將MySQL設置絕對路徑
echo PATH=$PATH:$HOME/bin:/usr/local/mysql/bin >> /etc/profile
export PATH
. /etc/profile
cd -
cd ..
#受權密碼登錄
/usr/local/mysql/bin/mysqladmin -u root password 123456
#受權數據庫本機以密碼123456登錄
mysql -uroot -p123456 < grant.sql
echo "安裝libxm及開發版"
yum -y install libxml2
yum -y install libxml2-devel
echo "安裝curl開發版"
yum -y install curl-devel
echo "安裝PHP"
tar -zxvf php-5.5.12RC1.tar.gz
cd php-5.5.12RC1
#配置時支持MySQL(MySQL的路徑必定要正確),並安裝PHP管理器PHP-fpm
./configure --prefix=/usr/local/php --enable-cgi --enable-fpm --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/usr/local/mysql --with-mysql=/usr/local/mysql --enable-sockets --with-curl --enable-mbstring
make && make install
cp php.ini-production /usr/local/php/lib/php.ini
#建立fpm的配置文件,源碼包中已經自帶了一個默認的配置文件這須要將配置文件更名便可使用
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
echo "啓動PHP"
/usr/local/php/sbin/php-fpm
echo "設置PHP的開機自啓動"
echo /usr/local/php/sbin/php-fpm>> /etc/rc.d/rc.local
cd ..
echo "安裝nginx"
yum -y install pcre-devel
tar -zxvf nginx-1.2.9.tar.gz
cd nginx-1.2.9
./configure --prefix=/usr/local/nginx
make && make install
cd ..
echo "設置nginx的開機自啓動"
echo /usr/local/nginx/sbin/nginx >> /etc/rc.d/rc.local
echo "刪除nginx默認的conf並將已經寫好的conf複製到對應目錄"
rm -rf /usr/local/nginx/conf/nginx.conf
cp nginx.conf /usr/local/nginx/conf/nginx.conf
#這一份nginx配置表的根目錄是 /data/www/
echo "啓動nginx"
/usr/local/nginx/sbin/nginx
chmod -R 777 /data
echo "安裝RS同步工具"
tar -zxvf rsync-3.1.1.tar.gz
cd rsync-3.1.1
./configure --prefix=/usr/local/rsync
make && make install
#這裏的密碼是根據服務器的密碼來寫入的,若是服務器修改了密碼,腳本這裏作一下相應的修改便可
echo "建立密碼文件,默認密碼是datacenter服務端的密碼:963852"
touch /etc/rsync.pas
echo 963852 >> /etc/rsync.pas
echo "修改受權"
chmod 600 /etc/rsync.pas
mkdir /etc/rsync/
touch /etc/rsync/exclude_client.conf
echo "配置環境變量"
echo cd /data/ >> ~/.bashrc
echo ulimit -u 102400 >> ~/.bashrc
echo ulimit -n 102400 >> ~/.bashrc
echo ulimit -d unlimited >> ~/.bashrc
echo ulimit -m unlimited >> ~/.bashrc
echo ulimit -s unlimited>> ~/.bashrc
echo ulimit -t unlimited>> ~/.bashrc
echo ulimit -v unlimited>> ~/.bashrc
echo ulimit -c unlimited>> ~/.bashrc
echo "安裝完畢"php