首页 > 其他分享 >记录一次阿里云ECS搭建代理服务器的过程

记录一次阿里云ECS搭建代理服务器的过程

时间:2022-10-19 15:36:06浏览次数:79  
标签:grep log 代理服务器 echo ECS FILE tinyproxy CONFIG 搭建

[参考资料](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:[email protected]: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 = "代理认证密码";

        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);
    }
}

标签:grep,log,代理服务器,echo,ECS,FILE,tinyproxy,CONFIG,搭建
From: https://www.cnblogs.com/zhenhunfan2/p/16806376.html

相关文章

  • K8S二进制搭建问题云集
    一、故障描述Errorfromserver:Get"https://k8s-node01:10250/containerLogs/kube-system/calico-node-98cv6/calico-node":x509:certificatesignedbyunknownaut......
  • python+selenium环境搭建
    1、首先命令行进入到python安装目录的scripts目录下2、使用pip3installselenium,由于我是安装过的,所以会提示这个3、将谷歌浏览器的driver放到python安装目录下4、代码验证......
  • 深入剖析Redis系列: Redis集群模式搭建与原理详解
    前言在Redis3.0之前,使用 哨兵(sentinel)机制来监控各个节点之间的状态。RedisCluster是Redis的 分布式解决方案,在3.0版本正式推出,有效地解决了Redis在 分布式 ......
  • 如何快速搭建k8s的kubemark性能测试环境
    Kubemark学习文档搭建k8s集群......
  • DSC集群搭建
    一、集群介绍  DMDSC集群是一个多实例、单数据库的系统。多个数据库实例可以同时访问、修改同一个数据库的数据。用户可以登录集群中的任意一个数据库实例,获得完整的数......
  • ansible搭建基本使用
    一、安装ansible配置yum源RHEL/CentOS6:#yuminstallhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpmRHEL/CentOS7:#yuminstallh......
  • 从0搭建vue3组件库:Shake抖动组件
    先看下效果其实就是个抖动效果组件,实现起来也非常简单。之所以做这样一个组件是为了后面写Form表单的时候会用到它做一个规则校验,比如下面一个简单的登录页面,当点击登录......
  • 拿到40k的offer入职,第一个任务就是搭建一套最牛监控平台!
    转载:以下文章来源于架构悟道 ,作者veezeanhttps://mp.weixin.qq.com/s?__biz=MzU0OTk3ODQ3Ng==&mid=2247565686&idx=1&sn=f7887ff74a54ca4c80859763cca712cc&chksm=fba429......
  • 3天用flask搭建平台实战教程四:使用flask-restful-swagger-2.0自动生成swagger文档
    flask-restful-swagger-2是适用于flask-restful的包装器,根据swagger2.0规范支持swagger,flask-restful-swagger-2基于flashrestfulswagger,但flashrestfulswagger仅支持......
  • Selenium+Python系列 - 开发环境搭建
    一、写在前面我从未想过自己会写python系列的自动化文章,有些同学会问,那你现在为什么又开始写了?不止一个人找过我,问我可以写一些Python自动化的文章吗,答案是肯定的。笔......