suse 服务器配置

#!/bin/bash
#作者:duanyunxi
#版本:v2.0

touch /var/installserver.tmp

##开始准备工作##
echo "##开始准备工作!##"
if [ -f /var/installserver.tmp ]; then
RETVAL=`grep 'ready' /var/installserver.tmp`
if [ "$RETVAL" == "" ]; then
echo "##确认server_2.0的路径!##"
echo "请输入server_2.0所在的位置,例如:/home/server_2.0.tar.gz"
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
read SERVERPATH
echo "您输入server_2.0所在的位置是:$SERVERPATH,请确认(y|n)?"
read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请确认server_2.0所在的位置后,重新输入:"
else
echo "server_2.0所在的位置为:$SERVERPATH"
fi
done
echo "##解压server_2.0!##"
cd /home
cp $SERVERPATH /home/server_2.0.tar.gz
tar xzf server_2.0.tar.gz
chmod 755 -R server_2.0
echo "ready ok!" >> /var/installserver.tmp
echo "准备工作已经完成!"
sleep 10
else
echo "准备工作已经做过!"
fi
fi


##开始安装JDK##
echo "##开始安装JDK!##"
if [ -f /var/installserver.tmp ]; then
RETVAL=`cat /var/installserver.tmp|grep 'jdk'|grep 'successfully'`
if [ "$RETVAL" == "" ]; then
cd /home/server_2.0
chmod u+x ./jdk-6u19-linux-i586.bin
./jdk-6u19-linux-i586.bin
mv jdk1.6.0_19 /usr/local/jdk
ln -s /usr/local/jdk/bin/java /usr/bin/java
ln -s /usr/local/jdk/bin/javac /usr/bin/javac
ln -s /usr/local/jdk/jre /usr/local/jre
echo "jdk has installed successfully!" >> /var/installserver.tmp
echo "JDK安装完成!"
sleep 10
else
echo "JDK已经安装过了!"
fi
fi

##开始配置JDK环境变量##
echo "##开始配置JDK环境变量!##"
if [ -f /var/installserver.tmp ]; then
RETVAL=`cat /etc/profile|grep 'JAVA_HOME'`
if [ "$RETVAL" == "" ]; then
echo "" >> /etc/profile
echo 'JAVA_HOME=/usr/local/jdk' >> /etc/profile
echo 'JRE_HOME=/usr/local/jre' >> /etc/profile
echo 'PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin' >> /etc/profile
echo 'CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:' >> /etc/profile
echo 'export JAVA_HOME JRE_HOME PATH CLASSPATH' >> /etc/profile
source /etc/profile
echo "JDK环境变量配置完成!"
else
echo "JDK环境变量已经配置过了!"
fi
java -version
fi


##开始安装resin##
echo "##开始安装resin!##"
if [ -f /var/installserver.tmp ]; then
RETVAL=`cat /var/installserver.tmp|grep 'resin'|grep 'successfully'`
if [ "$RETVAL" == "" ]; then

#####duanyunxi-2010-10-28
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
PORT=""
echo "请输入resin的端口号?(8000-8999)"
read PORT
if [ ${PORT} -lt 8000 ] || [ ${PORT} -gt 8999 ]; then
echo "您输入的端口号超出范围,重新输入:"
read PORT
fi
echo "您输入端口号是:$PORT,请确认(y|n)?"

read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请确认端口后,重新输入:"
else
echo "RESIN_PORT=$PORT" >> /var/installserver.tmp
echo "端口为:$PORT"
fi
done

cd /home/server_2.0
tar -zxvf resin-pro-3.1.10.tar.gz
cd resin-pro-3.1.10
./configure --prefix=/usr/local/resin --enable-jni
sleep 10
make
sleep 10
make install
sleep 10

RETVAL=`cat /etc/profile|grep 'RESIN_HOME'`
if [ "$RETVAL" == "" ]; then
echo "" >> /etc/profile
echo 'RESIN_HOME=/usr/local/resin' >> /etc/profile
echo 'export RESIN_HOME ' >> /etc/profile
source /etc/profile
echo "resin环境变量配置完成!"
fi

##duanyunxi
sed -i -e "s@8080@$PORT@" /usr/local/resin/conf/resin.conf

cp /home/server_2.0/resin.init /etc/init.d/resin
chmod +x /etc/init.d/resin

chkconfig --del resin && chkconfig --add resin
chkconfig resin on
echo "resin has installed successfully!" >> /var/installserver.tmp
echo "resin安装完成!"
sleep 10
else
echo "resin已经安装过了!"
fi
fi


##开始安装nginx##
echo "##开始安装nginx!##"
if [ -f /var/installserver.tmp ]; then
RETVAL=`cat /var/installserver.tmp|grep 'nginx'|grep 'successfully'`
if [ "$RETVAL" == "" ]; then

cd /home/server_2.0
tar -zxvf pcre-7.8.tar.gz
tar -zxvf zlib-1.2.2.tar.gz
tar zxvf openssl-0.9.8k.tar.gz
tar zxvf nginx-0.8.38.tar.gz
cd nginx-0.8.38/
./configure --prefix=/usr/local/nginx --with-pcre=/home/server_2.0/pcre-7.8 --with-zlib=/home/server_2.0/zlib-1.2.2 --with-openssl=/home/server_2.0/openssl-0.9.8k \
--with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module
sleep 10
make
sleep 10
make install
sleep 10

cp /home/server_2.0/nginx.init /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --del nginx && chkconfig --add nginx
chkconfig nginx on

echo "nginx has installed successfully!" >> /var/installserver.tmp
echo "nginx安装完成!"
else
echo "nginx已经安装过了!"
sleep 10
fi
fi


##开始安装mysql##
echo "##开始安装mysql!##"
if [ -f /var/installserver.tmp ]; then
RETVAL=`cat /var/installserver.tmp|grep 'mysql'|grep 'successfully'`
if [ "$RETVAL" == "" ]; then
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
ENCODE=""
echo "请选择mysql的编码(g:gbk|u:utf8)?"
read ENCODE
if [ "$ENCODE" == "G" ] || [ "$ENCODE" == "g" ]; then
echo "您选择的编码是gbk,请确认(y|n)?"
ENCODE="gbk"
elif [ "$ENCODE" == "U" ] || [ "$ENCODE" == "u" ]; then
echo "您选择的编码是utf8,请确认(y|n)?"
ENCODE="utf8"
fi

read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请确认后,重新输入:"
else
echo "MYSQL_ENCODE=$ENCODE" >> /var/installserver.tmp
echo "mysql的编码为:$ENCODE"
fi
done

#####duanyunxi-2010-10-28

INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
PORT=""
echo "请输入mysql的端口号?(8000-8999)"
read PORT
if [ ${PORT} -lt 8000 ] || [ ${PORT} -gt 8999 ]; then
echo "您输入的端口号超出范围,重新输入:"
read PORT
fi
echo "您输入端口号是:$PORT,请确认(y|n)?"

read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请确认端口后,重新输入:"
else
echo "MYSQL_PORT=$PORT" >> /var/installserver.tmp
echo "端口为:$PORT"
fi
done

INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
DATAPATH=""
echo "请输入数据存放位置,例如:/var/data"
read DATAPATH
echo "您输入数据存放位置是:$DATAPATH,请确认(y|n)?"

read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请确认数据存放位置后,重新输入:"
else
echo "DATA_PATH=$DATAPATH" >> /var/installserver.tmp
echo "数据存放位置为:$DATAPATH"
fi
done


INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
PASSWORD=""
echo "请输入mysql管理员用户root的密码?"
read PASSWORD
echo "您输入密码是:$PASSWORD,请确认(y|n)?"

read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请确认密码后,重新输入:"
else
echo "密码为:$PASSWORD"
fi
done

rm -rf /etc/my.cnf
groupadd mysql
useradd -g mysql mysql
cd /home/server_2.0
tar -zxvf mysql-5.1.45.tar.gz
cd mysql-5.1.45


./configure --prefix=/usr/local/mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --enable-assembler --with-extra-charsets=gb2312,big5,utf8,binary,ascii --enable-thread-safe-client --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
sleep 10
make
sleep 10
make install
sleep 10
cp support-files/my-medium.cnf /etc/my.cnf
RETVAL=`cat /etc/my.cnf|grep 'default-character-set'`
if [ "$RETVAL" == "" ]; then
sed -i -e "s@\[client\]@\[client\]\ndefault-character-set = $ENCODE@" /etc/my.cnf
sed -i -e "s@\[mysqld\]@\[mysqld\]\ndefault-character-set = $ENCODE@" /etc/my.cnf
fi

##duanyunxi
sed -i -e "s@3306@$PORT@" /etc/my.cnf

cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql

###duanyunxi
sed -i -e "40,50s@basedir=@basedir=/usr/local/mysql@" /etc/init.d/mysql
sed -i -e "40,50s@datadir=@datadir=$DATAPATH@" /etc/init.d/mysql

chkconfig --del mysql && chkconfig --add mysql
chkconfig mysql on

cd /usr/local/mysql
bin/mysql_install_db --user=mysql --datadir=$DATAPATH

chown -R root .
chown -R mysql var
chgrp -R mysql .
service mysql start


rm -rf /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin

####duanyunxi
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump

mysqladmin -u root password "$PASSWORD"
mysqladmin -h localhost -u root password "$PASSWORD"
mysqladmin -uroot -p$PASSWORD version 1> /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "mysql has installed successfully!" >> /var/installserver.tmp
echo "mysql安装完成!"
fi

touch /var/mysql.sql
echo "SET NAMES utf8;" >> /var/mysql.sql
echo "USE \`mysql\`;" >> /var/mysql.sql
echo "INSERT INTO \`user\` VALUES ('%','root',PASSWORD('$PASSWORD'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','N','N','N','N','','','','',0,0,0,0);" >> /var/mysql.sql
mysql -uroot -p$PASSWORD mysql</var/mysql.sql
rm -rf /var/mysql.sql

service mysql stop
sleep 10
else
echo "mysql已经安装过了!"
fi
fi

# ##设置防火墙##
# echo "##设置防火墙!##"
# if [ -f /var/installserver.tmp ]; then
# RETVAL=`cat /etc/sysconfig/SuSEfirewall2|grep 'FW_SERVICES_EXT_TCP'|grep '80 8080 443 3306'`
# if [ "$RETVAL" == "" ]; then
# sed -i -e "s@FW_SERVICES_EXT_TCP=\"\"@FW_SERVICES_EXT_TCP=\"80 8080 443 3306\"@" /etc/sysconfig/SuSEfirewall2
# fi
#
# RETVAL=`cat /etc/sysconfig/SuSEfirewall2|grep 'FW_SERVICES_EXT_UDP'|grep '177'`
# if [ "$RETVAL" == "" ]; then
# sed -i -e "s@FW_SERVICES_EXT_UDP=\"\"@FW_SERVICES_EXT_UDP=\"177\"@" /etc/sysconfig/SuSEfirewall2
# fi
# rcSuSEfirewall2 restart
# echo "防火墙设置完成!"
# fi


######duanyunxi
##设置防火墙##
echo "##设置防火墙!##"
if [ -f /var/installserver.tmp ]; then
RETVAL=`cat /var/installserver.tmp|grep 'SuSEfirewall2'|grep 'successfully'`
if [ "$RETVAL" == "" ]; then
INPUT="n"
until [ "$INPUT" == "Y" ] || [ "$INPUT" == "y" ]
do
PORTS=""
echo "请输入开放resin,mysql的端口号?(*空格隔开)"
read PORTS
echo "您输入端口号是:$PORTS,请确认(y|n)?"

read INPUT
if [ "$INPUT" != "Y" ] && [ "$INPUT" != "y" ]; then
echo "请确认开放端口后,重新输入:"
else
echo "SuSEfirewall2_PORTS=$PORTS" >> /var/installserver.tmp
echo "SuSEfirewall2 has set successfully!" >> /var/installserver.tmp
echo "开放resin,mysql的端口有:$PORTS"
fi

sed -i -e "s@FW_SERVICES_EXT_TCP=\"@FW_SERVICES_EXT_TCP=\"$PORTS 80 22 443 @" /etc/sysconfig/SuSEfirewall2
sed -i -e "s@FW_SERVICES_EXT_UDP=\"\"@FW_SERVICES_EXT_UDP=\"177\"@" /etc/sysconfig/SuSEfirewall2
done
rcSuSEfirewall2 restart
echo "防火墙设置完成!"
fi
fi


echo "service resin (start|stop|restart)"
echo "service nginx (start|stop|restart)"
echo "service mysql (start|stop|restart|status)"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

zhangkang0808

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

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

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

打赏作者

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

抵扣说明:

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

余额充值