自动安装nginx和varnish
脚本还有待完善,请大家多多指正!
脚本如下:
#!/bin/sh
#nginx varnish auto install script
#wb
#data 2010-11-19
nginx_ver=0.7.67
nginx_path=/opt/nginx
varnish_ver=2.1.3
varnish_path=/opt/varnish
ip=`ip a | grep eth0 | grep inet | awk '{print $2}' | cut -d "/" -f1`
echo -e "\033[40;32m"
cat << EOF
#######################
1、Nginx install
2、Varnish install
#######################
EOF
pcre_install(){
printf "pcre、pcre-devel安装\n"
sleep 5
yum install pcre pcre-devel -y
}
nginx_install(){
echo -e "\033[40;37m"
cd /root
if [ -f /root/nginx-$nginx_ver.tar.gz ];then
printf "nginx-$nginx_ver.tar.gz 程序已存在,程序退出!\n"
echo -e "\033[40;37m"
exit 1
else
pcre_install
echo -e "\033[40;33m"
printf "正在下载nginx-$nginx_ver 程序...\n"
sleep 5
echo -e "\033[40;37m"
wget http://www.nginx.org/download/nginx-$nginx_ver.tar.gz
echo -e "\033[40;33m"
printf "创建用户|用户组www,并安装nginx-$nginx_ver服务器...\n"
sleep 5
echo -e "\033[40;37m"
useradd www -s /sbin/nologin -d /dev/null
tar zxvf nginx-$nginx_ver.tar.gz
cd nginx-$nginx_ver
test -d /opt/$nginx_path || mkdir -p /opt/$nginx_path
./configure --prefix=$nginx_path \
--user=www \
--group=www \
--with-http_stub_status_module \
--without-http_map_module \
--without-http_geo_module \
--with-http_gzip_static_module \
--with-http_flv_module
make && make install
/opt/nginx/sbin/nginx
echo -e "\033[40;33m"
printf "nginx-$nginx_ver.tar.gz 已经安装完成,请访问http://$ip\n"
echo -e "\033[40;37m"
fi
}
varnish_install(){
echo -e "\033[40;37m"
cd /root
if [ -f /root/nginx-$varnish_ver.tar.gz ];then
printf "nginx-$varnish_ver.tar.gz 程序已存在,程序退出!\n"
echo -e "\033[40;37m"
exit 1
else
pcre_install
echo -e "\033[40;33m"
printf "正在下载varnish-$varnish_ver 程序...\n"
sleep 5
echo -e "\037[40;37m"
wget http://sourceforge.net/projects/varnish/files/varnish/$varnish_var/varnish-$varnnish_ver.tar.gz/
echo -e "\033[40;33m"
printf "创建用户|用户组www,并安装varnish-$varnish_ver服务器...\n"
sleep 5
echo -e "\037[40;37m"
useradd www -s /sbin/nologin -d /dev/null
tar zxf varnish-$varnish_ver.tar.gz
cd varnish-$varnish_ver
test -d /opt/$varnish_path || mkdir -p /opt/$varnish_path
test -d /opt/$varnish_path || mkdir -p /data/varnish_cache
./configure --prefix=$varnish_path
make && make install
ulimit -SHn 51200
/opt/varnish/sbin/varnishd -u www \
-g www \
-f /opt/varnish/etc/varnish/default.vcl \
-a $ip:80 \
-s file,/data/varnish_cache/varnish_cache.data,2G \
-w 1024,51200,10 \
-t 3600 \
-T $ip:3500
echo -e "\033[40;33m"
printf "varnish-$varnish_ver.tar.gz 已经安装完成,请访问http://$ip"
echo -e "\037[40;37m"
fi
}
echo -e "\033[40;33m"
read -p "请输入安装程序编号:" n
case $n in
1)
echo -e "\033[40;33m"
read -p "确定要安装nginx-$nginx_ver.tar.gz程序吗?[Y/y]" s
if [ $s == "Y" -o $s == "y" ];then
nginx_install
else
printf "没有选择[Y/y]安装程序,程序退出!\n"
echo -e "\033[40;37m"
exit 1
fi
;;
2)
echo -e "\033[40;33m"
read -p "确定要安装varnish-$varnish_ver.tar.gz程序吗?[Y/y]" s
if [ $s == "Y" -o $s == "y" ];then
varnish_install
else
printf "没有选择[Y/y]安装程序,程序退出!\n"
echo -e "\033[40;37m"
exit 1
fi
;;
*)
echo "没有选择安装程序编号,程序退出!"
echo -e "\033[40;37m"
exit 1
esac
本文出自 “网海过客” 博客,请务必保留此出处http://cqfish.blog.51cto.com/622299/407805