Debian10 x64 build make install Haproxy v2.2.0-在Debian10 64位系统编译安装最新版 Haproxy v2.2.0版本 Linux

haproxy是一个由C语言编写主要应用于高可用性和负载均衡的应用层代理软件。

Haproxy.png 

今天需要用到haproxy,但是无奈通过系统 Debian10 自带的软件源安装的版本太低了 apt install -y haproxy ;故自行前往官网:http://www.haproxy.org/ 

查看最新版的haproxy,目前最新版本是 2.2.0 .

那么使用 wget 先下载到本地:wget http://www.haproxy.org/download/2.2/src/haproxy-2.2.0.tar.gz

解压:

tar zxf haproxy-2.2.0.tar.gz

进入解压后的目录:

cd haproxy-2.2.0/


执行 make 准备进行编译,但是出错:

Due to too many reports of suboptimized setups, building without
specifying the target is no longer supported. Please specify the
target OS in the TARGET variable, in the following form:

   make TARGET=xxx

Please choose the target among the following supported list :

   linux-glibc, linux-glibc-legacy, linux-musl, solaris, freebsd, openbsd,
   netbsd, cygwin, haiku, aix51, aix52, aix72-gcc, osx, generic, custom

Use "generic" if you don't want any optimization, "custom" if you
want to precisely tweak every option, or choose the target which
matches your OS the most in order to gain the maximum performance
out of it. Please check the Makefile in case of doubts.

Makefile:761: recipe for target 'all' failed
make: *** [all] Error 1



根据提示,需要设置编译的 target 。

我们可以修改目录下的 Makefile 里面的 TARGET 或者是在 make 命令后加上:make TARGET=linux-glibc 即可:

[root@vmware haproxy-2.2.0]# make TARGET=linux-glibc
  CC      src/ev_poll.o
  CC      src/ev_epoll.o
  CC      src/namespace.o
  CC      src/mux_fcgi.o
  CC      src/mux_h1.o
  CC      src/mux_h2.o
  CC      src/backend.o
  CC      src/cfgparse.o
  CC      src/cli.o
  CC      src/cfgparse-listen.o
  CC      src/stats.o
  CC      src/http_ana.o
  CC      src/stream.o
  CC      src/check.o
  CC      src/sample.o
  CC      src/tools.o
  CC      src/server.o
  CC      src/listener.o
  CC      src/tcpcheck.o
  CC      src/pattern.o
  CC      src/log.o
  CC      src/stick_table.o
  CC      src/flt_spoe.o
  CC      src/stream_interface.o
  CC      src/filters.o
  CC      src/http_fetch.o
  CC      src/map.o
  CC      src/session.o
  CC      src/sink.o
  CC      src/flt_http_comp.o
  CC      src/debug.o
  CC      src/tcp_rules.o
  CC      src/haproxy.o
  CC      src/peers.o
  CC      src/flt_trace.o
  CC      src/queue.o
  CC      src/proxy.o
  CC      src/http_htx.o
  CC      src/dns.o
  CC      src/raw_sock.o
  CC      src/pool.o
  CC      src/http_act.o
  CC      src/http_rules.o
  CC      src/compression.o
  CC      src/cfgparse-global.o
  CC      src/payload.o
  CC      src/signal.o
  CC      src/activity.o
  CC      src/mworker.o
  CC      src/cache.o
  CC      src/proto_uxst.o
  CC      src/lb_chash.o
  CC      src/connection.o
  CC      src/proto_tcp.o
  CC      src/http_conv.o
  CC      src/arg.o
  CC      src/lb_fas.o
  CC      src/xprt_handshake.o
  CC      src/fcgi-app.o
  CC      src/applet.o
  CC      src/acl.o
  CC      src/task.o
  CC      src/ring.o
  CC      src/vars.o
  CC      src/trace.o
  CC      src/mux_pt.o
  CC      src/xxhash.o
  CC      src/mworker-prog.o
  CC      src/h1_htx.o
  CC      src/frontend.o
  CC      src/extcheck.o
  CC      src/channel.o
  CC      src/action.o
  CC      src/mailers.o
  CC      src/proto_sockpair.o
  CC      src/ebmbtree.o
  CC      src/thread.o
  CC      src/lb_fwrr.o
  CC      src/time.o
  CC      src/regex.o
  CC      src/lb_fwlc.o
  CC      src/htx.o
  CC      src/h2.o
  CC      src/hpack-tbl.o
  CC      src/lru.o
  CC      src/wdt.o
  CC      src/lb_map.o
  CC      src/eb32sctree.o
  CC      src/ebistree.o
  CC      src/h1.o
  CC      src/sha1.o
  CC      src/http.o
  CC      src/fd.o
  CC      src/ev_select.o
  CC      src/chunk.o
  CC      src/hash.o
  CC      src/hpack-dec.o
  CC      src/freq_ctr.o
  CC      src/http_acl.o
  CC      src/dynbuf.o
  CC      src/uri_auth.o
  CC      src/protocol.o
  CC      src/auth.o
  CC      src/ebsttree.o
  CC      src/pipe.o
  CC      src/hpack-enc.o
  CC      src/fcgi.o
  CC      src/eb64tree.o
  CC      src/dict.o
  CC      src/shctx.o
  CC      src/ebimtree.o
  CC      src/eb32tree.o
  CC      src/ebtree.o
  CC      src/dgram.o
  CC      src/hpack-huff.o
  CC      src/base64.o
  CC      src/version.o
  LD      haproxy



注:如果失败,请注意查看机器是否安装 lua 环境,命令行执行 lua -v 如果有显示版本就是有安装,没用就自行安装,这里以本机为例:apt install -y lua5.3 

编译成功后,直接执行 make install 即可安装好 haproxy :

[root@vmware haproxy-2.2.0]# make install
'haproxy' -> '/usr/local/sbin/haproxy'
'doc/haproxy.1' -> '/usr/local/share/man/man1/haproxy.1'
install: creating directory '/usr/local/doc'
install: creating directory '/usr/local/doc/haproxy'
'doc/configuration.txt' -> '/usr/local/doc/haproxy/configuration.txt'
'doc/management.txt' -> '/usr/local/doc/haproxy/management.txt'
'doc/proxy-protocol.txt' -> '/usr/local/doc/haproxy/proxy-protocol.txt'
'doc/seamless_reload.txt' -> '/usr/local/doc/haproxy/seamless_reload.txt'
'doc/architecture.txt' -> '/usr/local/doc/haproxy/architecture.txt'
'doc/peers-v2.0.txt' -> '/usr/local/doc/haproxy/peers-v2.0.txt'
'doc/regression-testing.txt' -> '/usr/local/doc/haproxy/regression-testing.txt'
'doc/cookie-options.txt' -> '/usr/local/doc/haproxy/cookie-options.txt'
'doc/lua.txt' -> '/usr/local/doc/haproxy/lua.txt'
'doc/WURFL-device-detection.txt' -> '/usr/local/doc/haproxy/WURFL-device-detection.txt'
'doc/linux-syn-cookies.txt' -> '/usr/local/doc/haproxy/linux-syn-cookies.txt'
'doc/SOCKS4.protocol.txt' -> '/usr/local/doc/haproxy/SOCKS4.protocol.txt'
'doc/network-namespaces.txt' -> '/usr/local/doc/haproxy/network-namespaces.txt'
'doc/DeviceAtlas-device-detection.txt' -> '/usr/local/doc/haproxy/DeviceAtlas-device-detection.txt'
'doc/51Degrees-device-detection.txt' -> '/usr/local/doc/haproxy/51Degrees-device-detection.txt'
'doc/netscaler-client-ip-insertion-protocol.txt' -> '/usr/local/doc/haproxy/netscaler-client-ip-insertion-protocol.txt'
'doc/peers.txt' -> '/usr/local/doc/haproxy/peers.txt'
'doc/close-options.txt' -> '/usr/local/doc/haproxy/close-options.txt'
'doc/SPOE.txt' -> '/usr/local/doc/haproxy/SPOE.txt'
'doc/intro.txt' -> '/usr/local/doc/haproxy/intro.txt'
[root@vmware haproxy-2.2.0]# haproxy -v
HA-Proxy version 2.2.0 2020/07/07 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2025.
Known bugs: http://www.haproxy.org/bugs/bugs-2.2.0.html
Running on: Linux 4.18.0-80.7.1.el8_0.x86_64 #1 SMP Sat Aug 3 15:14:00 UTC 2019 x86_64
[root@vmware haproxy-2.2.0]#

执行 haproxy -v 可以正确显示 版本号 2.2.0 即表明安装成功。

至于其 haproxy 的配置,根据业务需要,自行配置。Google上一大把。




admin 发布于  2020-7-16 16:16 

两种方式反代Google(镜像)--nginx反代和nginx扩展 Linux

写这篇文章的缘由是看见了我的博友Secret他写了一篇文章:

造轮子之谷歌镜像站 让我想起了 之前自己折腾过的nginx扩展镜像Google,效率比这个高,而且支持高级的配置,多级配合组成类似集群的功能,今天又折腾了一下,所以写一下过程,以方便后来需要的人.

声明:请在法律允许范围内合理使用搜索引擎,本文只作为技术笔记,不负任何责任.


  1. 更新库
  2. apt-get update
  3.  
  4. # 安装 gcc & git
  5. apt-get install build-essential git gcc g++ make -y
  6.  
  7. # nginx 官网: http://nginx.org/en/download.html
  8. wget "http://nginx.org/download/nginx-1.8.1.tar.gz"
  9.  
  10. # pcre 官网:http://www.pcre.org/
  11. wget "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz"
  12.  
  13. # opessl 官网:https://www.openssl.org/
  14. wget "https://www.openssl.org/source/openssl-1.0.1t.tar.gz"
  15.  
  16. # zlib 官网:http://www.zlib.net/
  17. wget "http://zlib.net/zlib-1.2.8.tar.gz"
  18.  
  19. # 下载本扩展
  20. git clone https://github.com/cuber/ngx_http_google_filter_module
  21.  
  22. # 下载 substitutions 扩展
  23. git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
  24.  
  25. # 解压缩
  26. tar xzvf nginx-1.8.1.tar.gz && tar xzvf pcre-8.39.tar.gz && tar xzvf openssl-1.0.1t.tar.gz && tar xzvf zlib-1.2.8.tar.gz
  27.  
  28. # 进入 nginx 源码目录
  29. cd nginx-1.8.1
  30.  
  31. # 创建 nginx 安装目录
  32. mkdir /usr/local/nginx-1.8.1

编译nginx及其扩展

  1. # 设置编译选项
  2. ./configure \
  3. --prefix=/usr/local/nginx-1.8.1 \
  4. --with-pcre=../pcre-8.39 \
  5. --with-openssl=../openssl-1.0.1t \
  6. --with-zlib=../zlib-1.2.8 \
  7. --with-http_ssl_module \
  8. --add-module=../ngx_http_google_filter_module \
  9. --add-module=../ngx_http_substitutions_filter_module
  10.  
  11. # 编译, 安装
  12. # 如果扩展有报错, 请发 issue 到
  13. # https://github.com/cuber/ngx_http_google_filter_module/issues
  14. make
  15. make install

 最后启动nginx,访问你的服务器IP或者是解析到上面的域名,即可看到nginx是否安装好.

ngx_http_google_filter_module项目github地址(他那里也有说明,不过是英文的,能看懂的可以直接去看原文):

https://github.com/cuber/ngx_http_google_filter_module


下面说一下nginx的配置:

  1. 简单的单机配置https,已经不支持http反代了
  1. server {
  2. server_name <你的域名>;
  3. listen 443;
  4.  
  5. ssl on;
  6. ssl_certificate <你的证书>;
  7. ssl_certificate_key <你的私钥>;
  8.  
  9. resolver 8.8.8.8;
  10. location / {
  11. google on;
  12. }
  13. }
  1. 进阶配置:配置多个服务器来缓解并发和出现验证码的频率

google_scholar 依赖于 google, 所以 google_scholar 无法独立使用. 由于谷歌学术近日升级, 强制使用 https 协议, 并且 ncr 已经支持, 所以不再需要指定谷歌学术的 tld

  1. location / {
  2. google on;
  3. google_scholar on;
  4. # 设置成德文,默认的语言是中文简体
  5. google_language "de";
  6. }

Upstreaming

upstream 减少一次域名解析的开销, 并且通过配置多个网段的 google ip 能够一定程度上减少被 google 机器人识别程序侦测到的几率 (弹验证码). upstream 参数要放在 http{} 中(也就是放在server{}配置外),注意这个参数只有你加了SSL证书是https的时候才会有效,否则会报错! 寻找这个参数的谷歌IP很简单,在你的VPS上面 ping www.google.com ,获得的IP把最后一位数 加1或者减1 就行了。

upstream www.google.com {
  server 173.194.38.1:443;
  server 173.194.38.2:443;
  server 173.194.38.3:443;
  server 173.194.38.4:443;
}

Proxy Protocol--代理保护

默认情况下,代理将使用https与后端服务器通信。您可以使用google_ssl_off强制某些域名回退到http协议。如果要通过没有ssl证书的另一个网关来代理某些域,这是非常有用的。

#
# eg. 
# i want to proxy the domain 'www.google.com' like this
# vps(hk) -> vps(us) -> google
#

#
# configuration of vps(hk)
#
server {
  # ...
  location / {
    google on;
    google_ssl_off "www.google.com";
  }
  # ...
}

upstream www.google.com {
  server < ip of vps(us) >:80;
}

#
# configuration of vps(us)
#
server {
  listen 80;
  server_name www.google.com;
  # ...
  location / {
    proxy_pass https://www.google.com;
  }
  # ...
}

所有的这些配置都是在全新的机器上配置,如果你已经配置好了nginx那么,也很容易,你只需要重新添加扩展动态编译进去就好了,编译完切记不要make install,只需要make编译,然后覆盖就行.

./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
.......
--add-module=/data/software/ngx_http_google_filter_module \
--add-module=/data/software/ngx_http_substitutions_filter_module

注意:你需要在nginx的源码包文件夹下面执行这个./configure命令,使用之前先使用 nginx-V 查看nginx版本下载相同版本的源码包,添加扩展的时候要注意路径,在最好复制的时候先停止nginx,同时以防万一,先拷贝一份nginx在覆盖.参考资料如下:

http://imshusheng.com/linux/173.html

http://www.ttlsa.com/nginx/how-to-install-nginx-third-modules/

http://coolnull.com/4245.html

就到这里了.下次再见:) 最后 欢迎访问我的Google镜像:gg.mrxn.net


admin 发布于  2017-9-24 07:38