代理服务器学习日志(一)

最近接到一个任务-研究代理服务器tinyproxy,研究tinyproxy源码,实现可以缓存一部分网页,当用户浏览网页信息时,不需再连接主服务器,只需从代理服务器中读取就行,同时还需要设计好代理服务器上的网页如何保持和服务器上的网页一致(即代理服务器上的网页都是最新的网页)。任务来的有些突然,一直在windows环境下编程,现在需要在linux环境下进行开发,原来一直对服务器代理不是很理解,现在任务在手,需要自己将其读透了,现在为自己的学习过程做个记录。

1.什么是HTTP代理

代理服务器(Proxy Server)是网上提供转接功能的服务器,在一般情况下,我们使用网络浏览器直接去连接其他Internet站点取得网络信息时,是直接联系到目的站点服务器,然后由目的站点服务器把信息传送回来。代理服务器是介于客户端和Web服务器之间的另一台服务器,有了它之后,浏览器不是直接到Web服务器去取回网页而是向代理服务器发出请求,信号会先送到代理服务器,由代理服务器来取回浏览器所需要的信息并传送给你的浏览器。

比如你想访问的目的网站是A,由于某种原因你不能访问到网站A或者你不想直接访问网站A(这样通过代理服务器网站A,对网站A而已可以隐藏你自己的身份,也就是不知道是谁访问的网站,而认为是代理服务器访问的),此时你就可以使用代理服务器,在实际访问网站的时候,你在浏览器的地址栏内和你以前一样输入你要访问的网站,浏览器会自动先访问代理服务器,然后代理服务器会自动给你转接到你的目标网站。

2.代理服务器的作用

提高访问速度:通常代理服务器都设置一个较大的缓冲区,当有外界的信息通过时,同时也将其保存到缓冲区中,当其他用户再访问相同的信息时,则直接由缓冲区中取出信息,传给用户,以提高访问速度。

3.代理服务器的客户端设置

IE浏览器--》Internate选项--》局域网设置--》选中下面的代理服务器填写好地址和端口号即可

代理服务器学习日志(一)_第1张图片

4.tinyproxy的安装

1)因为使用的是centos系统,其实在redhat系列的系统中,可以直接使用yum install tinyproxy来安装。

启动tinyproxy: service tinyproxy start

停止tinyproxy: service tinyproxy stop   也可以使用killall tinyproxy来停止

2)由于我们可能需要修改tinyproxy的源码,所以下面的方法为编译tinyproxy的源码并安装在centos中。

a.tinyproxy官网:https://banu.com/tinyproxy/

b.tinyproxy-1.8.3下载地址:https://files.banu.com/tinyproxy/1.8/tinyproxy-1.8.3.tar.bz2

c.阅读解压之后的tinyproxy文件夹下的readme,里面告诉我们可以通过下面三个步骤来编译安装tinyproxy

./configure  (生成makefile)

make (根据Makefile文件编译源代码、连接、生成目标文件、可执行文件)      

make install (将编译成功的可执行文件安装到系统目录中,一般为/usr/local/bin目录)

make clean 
清除上次的make命令所产生的object文件(后缀为“.o”的文件)及可执行文件。 

(

其他make组合命令:

make dist 
产生发布软件包文件(即distribution package)。这个命令将会将可执行文件及相关文件打包成一个tar.gz压缩的文件用来作为发布软件的软件包。 
它会在当前目录下生成一个名字类似“PACKAGE-VERSION.tar.gz”的文件。PACKAGE和VERSION,是我们在configure.in中定义的AM_INIT_AUTOMAKE(PACKAGE, VERSION)。

make distcheck 
生成发布软件包并对其进行测试检查,以确定发布包的正确性。这个操作将自动把压缩包文件解开,然后执行configure命令,并且执行make,来确认编译不出现错误,最后提示你软件包已经准备好,可以发布了。

make distclean 
类似make clean,但同时也将configure生成的文件全部删除掉,包括Makefile文件

5.自动生成makefile文件流程图

代理服务器学习日志(一)_第2张图片

自动生成makefile需要如下的步骤:

1) 运行autoscan命令(会生成configure.scan文件)

2) 将configure.scan 文件重命名为configure.in,并修改configure.in文件

3) 在tinyproxy目录下新建Makefile.am文件,并相关的目录下面也新建makefile.am文件

4) 在tinyproxy目录下新建NEWS、 README、 ChangeLog 、AUTHORS文件

5) 将/usr/share/automake-1.X/目录下的depcomp和complie文件拷贝到本目录下

6) 运行aclocal命令

7) 运行autoconf命令

8) 运行automake -a命令

9) 运行./confiugre脚本

下图是从官网上下载的tinyproxy根目录的图片:

(注:configure.ac (sometimes also named: configure.in) is an input file for autoconf. It contains tests that check for conditions that are likely to differ on different platforms. The tests are made by actually invoke autoconf macros.)

代理服务器学习日志(一)_第3张图片


6.生成tinyproxy安装文件及安装过程

[root@localhost tinyproxy-1.8.3]  ./configure

configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating data/Makefile
config.status: creating data/templates/Makefile
config.status: creating etc/Makefile
config.status: creating docs/Makefile
config.status: creating docs/man5/Makefile
config.status: creating docs/man5/tinyproxy.conf.txt
config.status: creating docs/man8/Makefile
config.status: creating docs/man8/tinyproxy.txt
config.status: creating m4macros/Makefile
config.status: creating tests/Makefile
config.status: creating tests/scripts/Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@localhost tinyproxy-1.8.3]# make
make  all-recursive
make[1]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3'
Making all in src
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/src'
  CC     acl.o
  CC     anonymous.o
  CC     buffer.o
  CC     child.o
  CC     conf.o
  CC     conns.o
  CC     daemon.o
  CC     hashmap.o
  CC     heap.o
  CC     html-error.o
  CC     http-message.o
  CC     log.o
  CC     network.o
  CC     reqs.o
  CC     sock.o
  CC     stats.o
  CC     text.o
  CC     main.o
  CC     utils.o
  CC     vector.o
  CC     upstream.o
  CC     connect-ports.o
  CC     filter.o
  CCLD   tinyproxy
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/src'
Making all in data
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
Making all in templates
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data/templates'
make[3]: Nothing to be done for `all'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data/templates'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
Making all in etc
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/etc'
  GEN    tinyproxy.conf
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/etc'
Making all in docs
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
Making all in man5
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man5'
  GEN    tinyproxy.conf.5
Note: Writing tinyproxy.conf.5
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man5'
Making all in man8
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man8'
  GEN    tinyproxy.8
Note: Writing tinyproxy.8
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man8'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
Making all in m4macros
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/m4macros'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/m4macros'
Making all in tests
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
Making all in scripts
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests/scripts'
make[3]: Nothing to be done for `all'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests/scripts'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3'
make[1]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3'
You have new mail in /var/spool/mail/root
[root@localhost tinyproxy-1.8.3]# make install
Making install in src
make[1]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/src'
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/src'
test -z "/usr/local/sbin" || /bin/mkdir -p "/usr/local/sbin"
  /usr/bin/install -c tinyproxy '/usr/local/sbin'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/src'
make[1]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/src'
Making install in data
make[1]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
Making install in templates
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data/templates'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data/templates'
make[3]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/share/tinyproxy" || /bin/mkdir -p "/usr/local/share/tinyproxy"
 /usr/bin/install -c -m 644 debug.html default.html stats.html '/usr/local/share/tinyproxy'
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data/templates'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data/templates'
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
make[1]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/data'
Making install in etc
make[1]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/etc'
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/etc'
test -z "/usr/local/etc" || /bin/mkdir -p "/usr/local/etc"
 /usr/bin/install -c -m 644 tinyproxy.conf '/usr/local/etc'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/etc'
make[1]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/etc'
Making install in docs
make[1]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
Making install in man5
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man5'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man5'
make[3]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/share/man/man5" || /bin/mkdir -p "/usr/local/share/man/man5"
 /usr/bin/install -c -m 644 tinyproxy.conf.5 '/usr/local/share/man/man5'
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man5'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man5'
Making install in man8
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man8'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man8'
make[3]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/share/man/man8" || /bin/mkdir -p "/usr/local/share/man/man8"
 /usr/bin/install -c -m 644 tinyproxy.8 '/usr/local/share/man/man8'
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man8'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs/man8'
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
make[1]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/docs'
Making install in m4macros
make[1]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/m4macros'
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/m4macros'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/m4macros'
make[1]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/m4macros'
Making install in tests
make[1]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
Making install in scripts
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests/scripts'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests/scripts'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests/scripts'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests/scripts'
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
make[3]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
make[1]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3/tests'
make[1]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3'
make[2]: Entering directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3'
make[1]: Leaving directory `/usr/zhl/1.src/tinyproxy/tinyproxy-1.8.3'
注:在我的centos中执行./configure时报如下asciidoc的错误,只需将asciidoc安装到系统中即可

[root@localhost tinyproxy-1.8.3]# yum install asciidoc

AsciiDoc是轻型的标识语言,通过解释工具(编译)可以将文本转换成html文件
Wiki: http://en.wikipedia.org/wiki/AsciiDoc


上面是我今天理解的tinyproxy的一些知识点,包括代理服务器是什么、如何生成makefile文件及如何编译安装文件到linux系统中,其中还涉及到安装asciidoc,以及屏幕截图软件gimp(在系统中执行yum install gimp即可将gimp安装到系统当中,打开gimp后,选择file-》create-》screenshot即可完成屏幕截图)



你可能感兴趣的:(代理服务器,Linux,C++)