#!/bin/bash |
#自动安装ats3.2.4stable脚本V1.2 |
#仅为搭建测试环境使用,CentOS6测试通过 |
#修改监听端口为80,只考虑为第一次安装,如果之前有安装过请先清理干净。 |
#by 纸鸢 |
WARNING () { |
echo -e "\033[0;31;1m$*\033[0m\n" |
} |
echo "nameserver 8.8.8.8" >> /etc/resolv.conf |
echo "安装ntp对时程序" |
yum install -y ntp |
WARNING "开始对时" |
/usr/sbin/ntpdate ntp0.cs.mu.OZ.AU |
WARNING "注意:如果系统时间不对,使用将会有些问题" |
WARNING "开始安装ats所需环境……" |
useradd trafficserver -s /sbin/nologin |
yum install make gcc gcc-c++ glibc-devel db4-devel openssl-devel tcl-devel expat-devel pcre-devel wget perl perl-devel -y |
if [ ! -d "/root/ats_source" ]; then |
mkdir /root/ats_source |
fi |
cd ats_source |
WARNING "清理目录" && rm -rf tra* |
WARNING "开始下载ats程序3.2.4stable版并安装……" |
wget -t 2 http://apache.etoak.com/trafficserver/trafficserver-3.2.4. tar .bz2 || wget -t 5 http://labs.mop.com/apache-mirror/trafficserver/trafficserver-3.2.4. tar .bz2 || wget -t 5 http://apache.etoak.com/trafficserver/trafficserver-3.2.4. tar .bz2 || wget http://www.fayea.com/apache-mirror/trafficserver/trafficserver-3.2.4. tar .bz2 || WARNING "下载ats失败,请检查网络再重试!" |
tar -jxvf trafficserver-3.2.4. tar .bz2 |
if [ ! -f "trafficserver-3.2.4.tar.bz2" ]; then |
WARNING "现在正在`pwd`,error,bz包不存在,将停止安装" |
exit 0 |
fi |
cd trafficserver-3.2.4 |
WARNING "开始编译ats" |
./configure -with-user=trafficserver -with-group=trafficserver |
WARNING "开始安装ats,需要稍等片刻" |
make && make install && WARNING "安装完成" |
#ln -s /usr/local/trafficserver/bin/* /sbin/ |
WARNING "开始修改ats监听端口" |
duankou=` grep "CONFIG proxy.config.http.server_ports STRING 8080" /usr/ local /etc/trafficserver/records.config` |
if [ -n "$duankou" ]; then |
sed -i 's/CONFIG proxy.config.http.server_ports STRING 8080/CONFIG proxy.config.http.server_ports STRING 80/g' /usr/ local /etc/trafficserver/records.config && echo "监听端口是:80" |
fi |
WARNING "开始启动ats服务……" |
trafficserver start |
WARNING "等待10秒钟让进程全部起来……" |
sleep 10 |
WARNING "ats进程情况如下" |
echo "##################################################" |
ps aux | grep traffic | grep - v grep |
echo "##################################################" |
jinchengshu=` ps aux | grep traffic | grep - v grep | wc -l` |
if [ "$jinchengshu" - eq "3" ]; then |
WARNING "启动ats成功" |
else |
WARNING "error启动ats失败,将重试一次" && trafficserver restart |
WARNING "ats进程情况如下" |
echo "##################################################" |
ps aux | grep traffic | grep - v grep |
echo "##################################################" |
fi |
WARNING "监听端口如下" |
echo "##################################################" |
netstat -lnpt | grep traffic |
echo "##################################################" |
traffic_line -s proxy.config.url_remap.remap_required - v 0 |
traffic_line -x |
echo "配置启用正向缓存成功" |
##添加via头 |
traffic_line -s proxy.config.http.insert_request_via_str - v 1 |
traffic_line -s proxy.config.http.insert_response_via_str - v 2 |
traffic_line -x |
echo "添加via头成功" |
#配置ats不检验响应头缓存 |
traffic_line -s proxy.config.http.cache.required_headers - v 0 |
traffic_line -s proxy.config.http.cache.enable_default_vary_headers - v 1 |
traffic_line -x |
WARNING "程序执行结束,愉快使用~" |
exit 0 |