ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

关于搭建代理服务器的全过程详细

2021-11-15 15:58:43  阅读:251  来源: 互联网

标签:00 ip 代理服务器 网卡 全过程 tinyproxy 172.18 服务器 搭建


腾讯云的规定是一个账号一个地区只能有20个公网IP:

1)点击实例名

2)添加辅助网卡

3)绑定弹性公网ip

4)为辅助网卡绑定安全组

5)修改网卡配置文件


  1. ### 复制eth0的网卡文件 ###

  2. [root@VM_1_62_centos ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth{0,1}

  3. ### 修改eth1文件 ###

  4. [root@VM_1_62_centos ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1

  5. # Created by cloud-init on instance boot automatically, do not edit.

  6. #

  7. #第一张网卡信息

  8. # Created by cloud-init on instance boot automatically, do not edit.

  9. #

  10. BOOTPROTO=static

  11. DEVICE=eth0

  12. HWADDR=52:54:00:88:ed:94

  13. # 配置主ip

  14. IPADDR=172.18.1.10

  15. # # # # 配置辅助ip1

  16. IPADDR1=172.18.1.11

  17. # # # 配置辅助iP2

  18. IPADDR2=172.18.1.12

  19. IPADDR3=172.18.1.13

  20. IPADDR4=172.18.1.14

  21. IPADDR5=172.18.1.15

  22. IPADDR6=172.18.1.16

  23. IPADDR7=172.18.1.17

  24. IPADDR8=172.18.1.18

  25. IPADDR9=172.18.1.19

  26. # # # 配置子网掩码

  27. NETMASK=255.255.255.0

  28. # #

  29. # #

  30. # # # # 配置网关

  31. GATEWAY=172.18.1.1

  32. NM_CONTROLLED=no

  33. ONBOOT=yes

  34. PERSISTENT_DHCLIENT=yes

  35. TYPE=Ethernet

  36. USERCTL=no

  37. #第二张网卡信息

  38. BOOTPROTO=static

  39. DEVICE=eth1

  40. #HWADDR=52:54:00:88:ed:94

  41. # 配置主ip

  42. IPADDR=172.18.1.20

  43. # # # # # 配置辅助ip1

  44. IPADDR1=172.18.1.21

  45. # # # # 配置辅助iP2

  46. IPADDR2=172.18.1.22

  47. IPADDR3=172.18.1.23

  48. IPADDR4=172.18.1.24

  49. IPADDR5=172.18.1.25

  50. IPADDR6=172.18.1.26

  51. IPADDR7=172.18.1.27

  52. IPADDR8=172.18.1.28

  53. IPADDR9=172.18.1.29

  54. # # # # 配置子网掩码

  55. NETMASK=255.255.255.0

  56. # # #

  57. # # #

  58. # # # # # 配置网关

  59. GATEWAY=172.18.1.1

  60. NM_CONTROLLED=no

  61. ONBOOT=yes

  62. PERSISTENT_DHCLIENT=yes

  63. TYPE=Ethernet

  64. USERCTL=no

  65. **** 其中的内网对应自己在腾讯云上设置的内网

  66. ### 关闭 rp_filter 校验 ###

  67. [root@VM_1_62_centos ~]# vim /etc/sysctl.conf

  68. # 找到第16行的rp_filter,如果有,就注释掉

  69. # net.ipv4.conf.default.rp_filter = 1 如果有就注释掉

  70. # 在文件结尾加上如下4行

  71. net.ipv4.conf.default.rp_filter = 0

  72. net.ipv4.conf.all.rp_filter = 0

  73. net.ipv4.conf.eth0.rp_filter = 0

  74. net.ipv4.conf.eth1.rp_filter = 0

  75. ### 使其生效 ###

  76. [root@VM_1_62_centos ~]# sysctl -p

  77. ### 重启网卡 ###

  78. [root@VM_1_62_centos ~]# systemctl restart network.service

  79. ### 查看配置后的效果 ###

  80. [root@VM_1_62_centos ~]# ip a

  81. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1

  82. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

  83. inet 127.0.0.1/8 scope host lo

  84. valid_lft forever preferred_lft forever

  85. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

  86. link/ether 52:54:00:8a:7a:64 brd ff:ff:ff:ff:ff:ff

  87. inet 10.2.1.62/24 brd 10.2.1.255 scope global eth0

  88. valid_lft forever preferred_lft forever

  89. inet 10.2.1.101/24 brd 10.2.1.255 scope global secondary eth0

  90. valid_lft forever preferred_lft forever

  91. inet 10.2.1.102/24 brd 10.2.1.255 scope global secondary eth0

  92. valid_lft forever preferred_lft forever

  93. 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

  94. link/ether 20:90:6f:16:2d:be brd ff:ff:ff:ff:ff:ff

  95. inet 10.2.1.211/24 brd 10.2.1.255 scope global eth1

  96. valid_lft forever preferred_lft forever

  97. inet 10.2.1.212/24 brd 10.2.1.255 scope global secondary eth1

  98. valid_lft forever preferred_lft forever

6)ping辅助网卡上的公网ip

7)在自己的服务器上编写端口映射脚本

端口映射脚本


  1. #!/bin/sh

  2. set -x

  3. iptables -t nat -F #删除之前规则

  4. for ((i=1;i<19;i++))

  5. do

  6.         ip="172.18.1."$[i+9]

  7.         iptables -t nat -I POSTROUTING -m state --state NEW -p tcp -m statistic --mode nth  --every $i  --packet 0 -j SNAT --to-source $ip

  8. done

  9. iptables-save > /etc/sysconfig/iptables

测试脚本


  1. #!/bin/sh

  2. while [ 1 ]

  3. do

  4. curl http://121.40.43.194/get_ip/ip.php

  5. done

测试脚本是杭州的服务器,有时比较慢,可以自己写一个在同地区的服务来查看ip地址;

8)在自己的服务器上安装tinyproxy软件

1. 安装 TinyProxy

yum -y install tinyproxy

2. 配置 TinyProxy

vim /etc/tinyproxy/tinyproxy.conf

修改 Port 端口,默认为 8888

Port 8888

注释掉 Allow,表示允许所有人访问代理

#Allow 127.0.0.1

隐藏掉Via请求头部,去掉下面的注释

DisableViaHeader Yes

更多配置项,下面是列举一些配置文件默认的,不需要配置:

PidFile "/var/run/tinyproxy/tinyproxy.pid"
LogFile "/var/log/tinyproxy/tinyproxy.log"
LogLevel Info
MaxClients 100
MinSpareServers 5
MaxSpareServers 20
StartServers 10

3. 启动 TinyProxy

systemctl start tinyproxy.service 

更多命令如下:

systemctl restart tinyproxy.service 
systemctl stop tinyproxy.service 
systemctl status tinyproxy.service 
systemctl enable tinyproxy.service 

4. 关闭防火墙或开放端口访问

方式1:关闭防火墙

systemctl  stop   iptables

方式2:开放端口访问

iptables -A INPUT -p tcp --dport 8888 -j ACCEPT

重启防火墙

systemctl  restart   iptables

注意:若采用的阿里云、腾讯云、AWS等云服务器,记得要在安全策略里开放端口号

5. 验证生效

1)命令行测试验证

curl 和 wget 测试使用代理,请参考米扑代理的使用示例,总结的非常全面!强烈推荐!

这里,直接使用米扑代理的最简单示例:

curl -m 30 --retry 3 -x http://58.87.90.149:8888 http://proxy.mimvp.com/exist.php | grep 'color="red"'
                                <font color="red">58.87.90.149</font>
curl -m 30 --retry 3 -x http://58.87.90.149:8888 -k https://proxy.mimvp.com/exist.php | grep 'color="red"'
                                <font color="red">58.87.90.149</font>

tinyproxy 支持 http 和 https 两种协议,经米扑代理测试,成功!

2)Firefox 插件测试

首先,安装 Proxy Switcher

其次,配置代理,如下图:

然后,访问米扑代理网站,验证代理

检测收录 - 米扑代理

上图里,http_via 带有参数,要隐藏需要修改配置文件

vim /etc/tinyproxy/tinyproxy.conf

隐藏掉Via请求头部,去掉下面的注释

DisableViaHeader Yes

重启 tinyproxy

systemctl restart tinyproxy.service


  1. 以centos7.2为例

  2. centos7服务器主网卡绑定多ip实践演示:

  3. https://cloud.tencent.com/developer/article/1360461

  4. centos7服务器添加辅助网卡绑定多ip实践演示:

  5. https://cloud.tencent.com/developer/article/1360462

  6. Windows服务器主网卡绑定多ip实践演示:

  7. https://cloud.tencent.com/developer/article/1360445

  8. Windows服务器添加辅助网卡及绑定多ip实践演示:

  9. https://cloud.tencent.com/developer/article/1360457

参考文章:

CentOS 7 安装 TinyProxy 代理服务器 - 阳光岛主 - 博客园

https://cloud.tencent.com/developer/article/1360462

如有不会,直接加博主qq:1350296289

云服务器搭载业务,选择合适的平台最重要!

从目前国内云计算市场的格局来看,国内云计算前三强分别是阿里云、腾讯云和华为云,阿里云、腾讯云作为背靠互联网平台的企业,更偏向于B端用户;华为与作为传统的通信巨头,更偏向于G端。

当然如何选择服务器机型,这里有篇文档汇总的比较详细,文档地址:

云服务器哪家好!2021年阿里云、腾讯云、华为云的服务器配置及价格对比?​

如果是高并发,高IO业务场景,需要确定服务器规格,可让业务应用性能发挥到最佳,参考官方文档:

阿里云服务器规格:规格实例族 - 云服务器 ECS

腾讯云服务器规格:规格实例族 - 云服务器CVM

标签:00,ip,代理服务器,网卡,全过程,tinyproxy,172.18,服务器,搭建
来源: https://blog.csdn.net/m0_64093008/article/details/121336461

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有