[参考资料](Tinyproxy安装与配置(ip代理) - 林先生 (downdawn.com))

1.一键安装脚本

vim proxy.sh
#! /bin/bash

# 配置文件
CONFIG_FILE="/etc/tinyproxy/tinyproxy.conf" # 下载
wget -P /opt/software https://github.com/tinyproxy/tinyproxy/releases/download/1.11.0-rc1/tinyproxy-1.11.0-rc1.tar.gz # 解压
mkdir /opt/module
cd /opt/software
tar -zxvf tinyproxy-1.11.0-rc1.tar.gz -C /opt/module/ # 编译安装
cd /opt/module/tinyproxy-1.11.0-rc1/
yum -y install gcc ./configure
make
make install # 添加配置
mkdir /etc/tinyproxy
#cp /usr/local/etc/tinyproxy/tinyproxy.conf /etc/tinyproxy/tinyproxy.conf
echo "User nobody" >> $CONFIG_FILE
echo "Group nobody" >> $CONFIG_FILE
echo "Port 8888" >> $CONFIG_FILE
echo "Timeout 20" >> $CONFIG_FILE
echo "DefaultErrorFile \"/usr/local/share/tinyproxy/default.html\"" >> $CONFIG_FILE
echo "StatFile \"/usr/local/share/tinyproxy/stats.html\"" >> $CONFIG_FILE
echo "LogFile \"/var/log/tinyproxy/tinyproxy.log\"" >> $CONFIG_FILE
echo "LogLevel Info" >> $CONFIG_FILE
echo "MaxClients 500" >> $CONFIG_FILE
echo "ViaProxyName \"tinyproxy\"" >> $CONFIG_FILE
echo "BasicAuth 你自己的用户名 你自己的密码" >> $CONFIG_FILE # 创建日志
mkdir /var/log/tinyproxy
touch /var/log/tinyproxy/tinyproxy.log
chmod 777 /var/log/tinyproxy/tinyproxy.log echo '启动'
ps -ef|grep tinyproxy|grep -v grep|awk '{print "kill -9 "$2}'|sh
nohup tinyproxy -d -c /etc/tinyproxy/tinyproxy.conf > /dev/null 2>&1 &

添加权限

chmod 777 proxy.sh

运行proxy.sh

sh proxy.sh

检测

tinyproxy -v

2.控制程序脚本

vim /usr/bin/tp
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start")
echo " =================== 启动 ==================="
nohup tinyproxy -d -c /etc/tinyproxy/tinyproxy.conf > /dev/null 2>&1 &
;;
"stop")
echo " =================== 关闭 ==================="
ps -ef|grep tinyproxy|grep -v grep|awk '{print "kill -9 "$2}'|sh
;;
"restart")
echo " =================== 重启 ==================="
ps -ef|grep tinyproxy|grep -v grep|awk '{print "kill -9 "$2}'|sh
nohup tinyproxy -d -c /etc/tinyproxy/tinyproxy.conf > /dev/null 2>&1 &
;;
"status")
echo " =================== 状态 ==================="
ps -ef|grep tinyproxy|grep -v grep
;;
*)
echo "Input Args Error..."
;;
esac

添加权限

chmod 777 /usr/bin/tp

测试脚本

tp start
tp stop
tp status
tp restart

查看日志

tail -f /var/log/tinyproxy/tinyproxy.log

3.测试tinyproxy

# 不加验证参数不会正常返回
curl -x http://127.0.0.1:8888 http://httpbin.org/get
Proxy Authentication Required # 正常返回
curl -x http://admin:123456@127.0.0.1:8888 http://httpbin.org/get

注意,如果外部测试无反应,请检测是否开通服务器安全组和防火墙的8888端口。

iptables开放8888端口

iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
# 查询端口是否开放
firewall-cmd --query-port=8888/tcp
# 开放80端口
firewall-cmd --permanent --add-port=8888/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload

加入是阿里云ECS还需要去配置该实例的安全组规则

JAVA代码测试

public class TinyProxyTest {

    public static void main(String[] args) throws IOException {

        final String authUser = "代理认证用户名";
final String authPassword = "代理认证密码"; //当Jsoup请求https资源时,需要解注释下面两句 //System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "false");
//System.setProperty("jdk.http.auth.proxying.disabledSchemes", "false"); Authenticator.setDefault(
new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
authUser, authPassword.toCharArray());
}
}
); Document doc = Jsoup.connect("http://www.bilibili.com").proxy("代理ip", 代理端口)
//.header("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 10; COL-AL10 Build/HUAWEICOL-AL10)")
.ignoreContentType(true).timeout(120 * 1000)
.get();
System.out.println(doc);
}
}

最新文章

  1. ADB常用命令(Android Debug Bridge)
  2. nuget pack
  3. Java中将16进制字符串转换成汉字
  4. checking it the current os is a 32bit or 64bit version 检查操作系统是32位还是64位
  5. easyui源码翻译1.32--Pagination(分页)
  6. 为什么在Windows有两个临时文件夹的环境变量Temp和Tmp?
  7. python字符集选择
  8. autoprefixer安装或者里sass的$mixin处理浏览器前缀
  9. LeetCode第[11]题(Java):Container With Most Water 标签:Array
  10. 信号处理引发的cpu高
  11. js的继承实现
  12. oss对象云存储
  13. 【Java每日一题】20170207
  14. 【cf789B】Masha and geometric depression(分类讨论/暴力)
  15. BZOJ4036 [HAOI2015]按位或 FWT
  16. CentOS No manual entry for man 没有 xx 的手册页条目
  17. JavaScript之函数,词法分析,内置对象和方法
  18. 在windows、linux中开启nginx的Gzip压缩大大提高页面、图片加载速度<转>
  19. 如何去掉IE文本框后的那个X css代码
  20. Linux nmap命令详解

热门文章

  1. Linux音频采集和在国产化平台中遇到的坑(二)
  2. 使用VMware Converter Standalone P2V(物理机转换虚拟机)
  3. 12月2日内容总结——边框属性,display属性,css盒子模型,浮动、溢出、定位、z-index属性和建议博客页面搭建
  4. Django-request、django连接数据库、ORM
  5. 【大型软件开发】浅谈大型Qt软件开发(四)动态链接库的宏冲突问题、COM组件开发的常见问题
  6. bind使用场景之一
  7. WAVE音频文件格式及其64位扩展格式的简要介绍
  8. 工控领域上云实践-Zstack和软赢
  9. 图说论文《An Empirical Evaluation of In-Memory Multi-Version Concurrency Control》
  10. navicat无法连接linux内的防火墙