haproxy七层代理

一.负载均衡

1.什么是负载均衡

负载均衡:Load Balance,简称LB,是一种服务或基于硬件设备等实现的高可用反向代理技术,负载均 衡将特定的业务(web服务、网络流量等)分担给指定的一个或多个后端特定的服务器或设备,从而提高了 公司业务的并发处理能力、保证了业务的高可用性、方便了业务后期的水平动态扩展

2.为什么用负载均衡

Web服务器的动态水平扩展-->对用户无感知 增加业务并发访问及处理能力-->解决单服务器瓶颈问题 节约公网IP地址-->降低IT支出成本 隐藏内部服务器IP-->提高内部服务器安全性 配置简单-->固定格式的配置文件 功能丰富-->支持四层和七层,支持动态下线主机 性能较强-->并发数万甚至数十万

3.负载均衡类型

1.3.1硬件:

F5 美国F5网络公司 https://f5.com/zh

Netscaler 美国思杰公司 https://www.citrix.com.cn/products/citrix-adc/、

Array 华耀 https://www.arraynetworks.com.cn/

AD-1000 深信服 http://www.sangfor.com.cn/

 二.haproxy简介

HAProxy是法国开发者 威利塔罗(Willy Tarreau) 在2000年使用C语言开发的一个开源软件 是一款具备高并发(万级以上)、高性能的TCP和HTTP负载均衡器 支持基于cookie的持久性,自动故障切换,支持正则表达式及web状态统计

1.haproxy-haproxy的基本部署方法及负载均衡的实现

查看版本

查看版本:
[root@haproxy ~]# dnf list haproxy-2.4.22-1.el9.x86_64 roxy
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

上次元数据过期检查:1:49:26 前,执行于 2024年08月09日 星期五 10时00分11秒。
已安装的软件包
haproxy.x86_64                                          2.4.22-1.el9  

第一步:准备三台主机

haproxy :首先先玩成在这上面的调度,成功以后

下载软件
[root@haproxy ~]# dnf install haproxy -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份

本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。

上次元数据过期检查:1 day, 1:06:04 前,执行于 2024年08月07日 星期三 15时10分47秒。
软件包 haproxy-2.4.22-1.el9.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
[root@haproxy ~]#  ls
公共  模板  视频  图片  文档  下载  音乐  桌面  anaconda-ks.cfg  mnt
[root@haproxy ~]# rpm -qc haproxy
/etc/haproxy/haproxy.cfg
/etc/logrotate.d/haproxy
/etc/sysconfig/haproxy

修改haproxy的配置文件:
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg 
 修改对齐参数:
[root@haproxy ~]# vim ~/.vimrc  
启动haproxy服务:
[root@haproxy ~]# systemctl enable haproxy.service
Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service → /usr/lib/systemd/system/haproxy.service.

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl start haproxy.service

webserver1
安装nginx软件:
[root@webserver ~]# dnf install nginx -y

导入:
[root@webserver ~]# echo webserver1 - 172.25.254.10 > /usr/share/nginx/html/index.html

[root@webserver ~]# systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
webserver2
[root@webserver ~]# dnf install nginx -y
[root@webserver2 ~]# echo webserver2 - 172.25.254.20 > /usr/share/nginx/html/index.html
[root@webserver2 ~]#  systemctl enable --now nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
两台web上完成配置以后,在haproxy测试调度:
[root@haproxy ~]# curl 172.25.254.10
webserver1 - 172.25.254.10
[root@haproxy ~]# curl 172.25.254.20
webserver2 - 172.25.254.20

 第二步:上述haproxy主机中的配置完成以后另开一个界面测试

2.haproxy-haproxy的全局配置参数及日志分离

global:全局配置段

     进程及安全配置相关的参数

     性能调整相关参数

     Debug参数

proxies:代理配置段

      defaults:为frontend, backend, listen提供默认配置

      frontend:前端,相当于nginx中的server {}

      backend:后端,相当于nginx中的upstream {}

      listen:同时拥有前端和后端配置,配置简单,生产推荐使用

global配置

 多进程和socket文件配置如下:

haproxy ~]# vim /etc/haproxy/haproxy.cfg ...上面内容省略...

log         127.0.0.1 local2  

      chroot     /var/lib/haproxy  

      pidfile     /var/run/haproxy.pid  

      maxconn     100000  

      user       haproxy  

      group       haproxy  

     daemon  

    # turn on stats unix socket  

    stats socket /var/lib/haproxy/haproxy.sock1 mode 600 level admin process 1 #

启用多个sock文件

    stats socket /var/lib/haproxy/haproxy.sock2 mode 600 level admin process 2

查看多进程信息

启用多线程 多线程对比

  nbproc 2 #启用多进程

  cpu-map 1 0 #进程和cpu核心绑定防止cpu抖动从而减少系统资源消耗

  cpu-map 2 1 #2 表示第二个进程,1表示第二个cpu核心

    ...下面内容省略 ...

通过树来查看haproxy进程,默认是一个:
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(12467)---haproxy(12469)
           
haproxy的配置文件:
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(23376)-+-haproxy(23378)
           |                `-haproxy(23379)
更改下图的参数以后就会增加一个进程

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(26352)-+-haproxy(26354)
           |                `-haproxy(26355)

代表上述线程只有一个子进程:
[root@haproxy ~]# cat /proc/26355/status | grep -i thread
Threads:        1

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy
[root@haproxy ~]# pstree -p | grep haproxy
           |-haproxy(30206)---haproxy(30208)---{haproxy}(30209)
[root@haproxy ~]# cat /proc/30208/status | grep -i thread
Threads:        2
注意:多线程和单线程不能同时打开

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg

[root@haproxy ~]# vim /etc/rsyslog.conf

3.haproxy的代理参数

[root@haproxy ~]# yum install httpd -y
[root@haproxy ~]# vim /etc/httpd/conf/httpd.conf
[root@haproxy ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

[root@haproxy ~]# systemctl restart httpd

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service
[root@haproxy ~]# echo sorry 下班了 > /var/www/html/index.html

bakcup不参与调度
当把两台webserver停止以后,就只有bakcup可以上线:
[root@webserver1 ~]# systemctl stop nginx
[root@webserver2 ~]# systemctl stop nginx

[root@webserver ~]# systemctl start nginx

 

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy

disabled 表示下线 删除以后就可以继续访问

4.haproxy的热处理 Socat工具

单个进程的处理

[root@haproxy ~]# dnf install socat -y
[root@haproxy ~]# echo "show servers state" | socat stdio /var/lib/haproxy/stats
1
# be_id be_name srv_id srv_name srv_addr srv_op_state srv_admin_state srv_uweight srv_iweight srv_time_since_last_change srv_check_status srv_check_result srv_check_health srv_check_state srv_agent_state bk_f_forced_id srv_f_forced_id srv_fqdn srv_port srvrecord srv_use_ssl srv_check_port srv_check_addr srv_agent_addr srv_agent_port
2 webcluster 1 web1 172.25.254.10 2 0 2 2 745 6 3 7 6 0 0 0 - 80 - 0 0 - - 0
2 webcluster 2 web2 172.25.254.20 2 0 1 1 630 6 0 7 7 0 0 0 - 80 - 0 0 - - 0
2 webcluster 3 web_sorry 172.25.254.100 2 0 1 1 1054 1 0 2 0 0 0 0 - 8080 - 0 0 - - 0
3 static 1 static 127.0.0.1 0 0 1 1 1053 8 2 0 6 0 0 0 - 4331 - 0 0 - - 0
4 app 1 app1 127.0.0.1 0 0 1 1 1053 8 2 0 6 0 0 0 - 5001 - 0 0 - - 0
4 app 2 app2 127.0.0.1 0 0 1 1 1052 8 2 0 6 0 0 0 - 5002 - 0 0 - - 0
4 app 3 app3 127.0.0.1 0 0 1 1 1052 8 2 0 6 0 0 0 - 5003 - 0 0 - - 0
4 app 4 app4 127.0.0.1 0 0 1 1 1052 8 2 0 6 0 0 0 - 5004 - 0 0 - - 0

查看权重:
[root@haproxy ~]# echo get weight webcluster/web1 | socat stdio /var/lib/haproxy/stats
2 (initial 2)  当前权重为2 默认也为2

更改权重为1:
[root@haproxy ~]# echo set "weight webcluster/web1 1" | socat stdio /var/lib/
[root@haproxy ~]# echo get weight webcluster/web1 | socat stdio /var/lib/haproxy/stats
1 (initial 2)   当前权重为1 默认为2

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy

[root@haproxy ~]# systemctl restart haproxy
[root@haproxy ~]# echo get weight webcluster/web1 | socat stdio /var/lib/haproxy/stats
1 (initial 1)

[root@haproxy ~]# echo set "weight webcluster/web1 2" | socat stdio /var/lib/haproxy/stats

[root@haproxy ~]# echo get weight webcluster/web1 | socat stdio /var/lib/haproxy/stats
2 (initial 1)

让webserver1下线:
[root@haproxy ~]# echo "disable server webcluster/web1 " | socat stdio /var/lib/haproxy/stats

webserver1启动:
[root@haproxy ~]# echo "enable server webcluster/web1 " | socat stdio /var/lib/haproxy/stats

多个进程处理  一个一个处理

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy
[root@haproxy ~]# ll /var/lib/haproxy/
总用量 0
srw-------. 1 root root 0  8月  9 20:37 stats
srw-------. 1 root root 0  8月  9 20:39 stats1
srw-------. 1 root root 0  8月  9 20:39 stats2

5.haproxy的算法

 HAProxy通过固定参数 balance 指明对后端服务器的调度算法

balance参数可以配置在listen或backend选项中。

HAProxy的调度算法分为静态和动态调度算法 有些算法可以根据参数在静态和动态算法中相互转换。

静态算法

静态算法:按照事先定义好的规则轮询公平调度,不关心后端服务器的当前负载、连接数和响应速度 等,且无法实时修改权重(只能为0和1,不支持其它值),只能靠重启HAProxy生效。

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy

不能修改权重:
[root@haproxy ~]# echo set "weight webcluster/web1 1" | socat stdio /var/lib/haproxy/stats
Backend is using a static LB algorithm and only accepts weights '0%' and '100%'.

static-rr:基于权重的轮询调度

不支持运行时利用socat进行权重的动态调整(只支持0和1,不支持其它值)

不支持端服务器慢启动 其后端主机数量没有限制,相当于LVS中的 wrr

Note

慢启动是指在服务器刚刚启动上不会把他所应该承担的访问压力全部给它,而是先给一部分,当没 问题后在给一部分 示例:

first

根据服务器在列表中的位置,自上而下进行调度 其只会当第一台服务器的连接数达到上限,新请求才会分配给下一台服务 其会忽略服务器的权重设置 不支持用socat进行动态修改权重,可以设置0和1,可以设置其它值但无效 

动态算法

基于后端服务器状态进行调度适当调整, 新请求将优先调度至当前负载较低的服务器 权重可以在haproxy运行时动态调整无需重启

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg ...上面内容省略... 
listen webserver_80  
      bind 172.25.254.100:80  
      mode http  
      balance static-rr  
      server webserver1 192.168.0.101:80 weight 2 check inter 3s fall 3 rise 5  
      server webserver2 192.168.0.102:80 weight 1 check inter 3s fall 3 rise 5 ...上面内容省略... 
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg ...上面内容省略... 
listen webserver_80  
       bind 172.25.254.100:80  
       mode http  
       balance first           
       server webserver1 192.168.0.101:80 maxconn 3 check inter 3s fall 3 rise 5  
       server webserver2 192.168.0.102:80 check inter 3s fall 3 rise 5 ...上面内容省略... #在两台主机上分别执行此循环,可以观察是否102被调度到

 while true;do curl 172.25.254.100 ; sleep 0.1;done

roundrobin

1. 基于权重的轮询动态调度算法,

2. 支持权重的运行时调整,不同于lvs中的rr轮训模式,

3. HAProxy中的roundrobin支持慢启动(新加的服务器会逐渐增加转发数),

4. 其每个后端backend中最多支持4095个real server,

5. 支持对real server权重动态调整,

6. roundrobin为默认调度算法,此算法使用广泛 示例: 动态调整权重

leastconn

leastconn加权的最少连接的动态 支持权重的运行时调整和慢启动,即:根据当前连接最少的后端服务器而非权重进行优先调度(新客户 端连接),比较适合长连接的场景使用,比如:MySQL等场景。 示例:

其他算法

其它算法即可作为静态算法,又可以通过选项成为动态算法

source

源地址hash,基于用户源地址hash并将请求转发到后端服务器,后续同一个源地址请求将被转发至同一 个后端web服务器。此方式当后端服务器数据量发生变化时,会导致很多用户的请求转发至新的后端服 务器,默认为静态方式,但是可以通过hash-type支持的选项更改这个算法一般是在不插入Cookie的TCP模式下使用,也可给拒绝会话cookie的客户提供最好的会话粘性,适用于session会话保持但不支持cookie和缓存的场景源地址有两种转发客户端请求到后端服务器的服务器选取计算方式,分别是取模法 和一致性hash  示例: 测试:Note

如果访问客户端时一个家庭,那么所有的家庭的访问流量都会被定向到一台服务器,这时source算 法的缺陷

6.介绍HAProxy高级配置及实用案例基于cookie的会话保持

cookie value:为当前server指定cookie值,实现基于cookie的会话黏性,相对于基于 source 地址hash ,调度算法对客户端的粒度更精准,但同时也加大了haproxy负载,目前此模式使用较少,已经被session共享服务器代替

配置选项

cookie name [ rewrite | insert | prefix ][ indirect ] [ nocache ][ postonly ] [  preserve ][ httponly ] [ secure ][ domain ]* [ maxidle  ][ maxlife ] 

name:     #cookie 的 key名称,用于实现持久连接
insert:   #插入新的cookie,默认不插入cookie indirect: #如果客户端已经有cookie,则不会再发送cookie信息

nocache:  #当client和hapoxy之间有缓存服务器(如:CDN)时,不允许中间缓存器缓存cookie,   #因为这会导致很多经过同一个CDN的请求都发送到同一台后端服务器

配置示例

haproxy ~]# vim /etc/haproxy/haproxy.cfg ...上面内容省略... 
listen webserver_80  
      bind 172.25.254.100:80  
      option forwardfor  
      mode http 
      balance roundrobin  
      cookie WEBCOOKIE insert nocache indirect  
      server webserver1 192.168.0.101:80 cookie web1 weight 1 check inter 3s fall  3 rise 5  
      server webserver2 192.168.0.102:80 cookie web2 weight 1 check inter 3s fall  3 rise 5 ...上面内容省略...

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service

7.IP透传 (七层)

web服务器中需要记录客户端的真实IP地址,用于做访问统计、安全防护、行为分析、区域排行等场景。

#修改haproxy
haproxy ~]# vim /etc/haproxy/haproxy.cfg
...上面内容省略...
listen webserver_80
   option forwardfor
   bind 172.25.254.100:80
   mode http
   balance roundrobin                 
   server webserver1 192.168.0.101:80 send-proxy weight 1 check inter 3s fall 3 
rise 5
   server webserver1 192.168.0.102:80 weight 1 check inter 3s fall 3 rise 5



[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service

 

将webserver1设置为apache:

[root@webserver ~]# systemctl disable nginx
Removed "/etc/systemd/system/multi-user.target.wants/nginx.service".
[root@webserver ~]# systemctl stop nginx
[root@webserver ~]# dnf install httpd -y
[root@webserver ~]# echo webserver1 - 172.25.254.10 > /var/www/html/index.html
[root@webserver ~]# systemctl start httpd

[root@webserver ~]# vim /etc/httpd/conf/httpd.conf
[root@webserver ~]# systemctl start httpd

将webserver2设置为nginx:

[root@webserver2 ~]# vim /etc/nginx/nginx.conf
[root@webserver2 ~]# systemctl restart nginx

查看日志
[root@webserver2 ~]#  tail -n 3 /var/log/nginx/access.log
172.25.254.100 - - [10/Aug/2024:10:50:20 +0800] "GET / HTTP/1.1" "172.25.254.1"200 27 "-" "curl/8.4.0" "172.25.254.1"
172.25.254.100 - - [10/Aug/2024:10:51:23 +0800] "GET / HTTP/1.1" "172.25.254.1"200 27 "-" "curl/8.4.0" "172.25.254.1"
172.25.254.100 - - [10/Aug/2024:10:52:55 +0800] "GET / HTTP/1.1" "172.25.254.1"200 27 "-" "curl/8.4.0" "172.25.254.1"

 

 

8.ACL 常用参数

访问控制列表ACL,Access Control Lists) 是一种基于包过滤的访问控制技术

它可以根据设定的条件对经过服务器传输的数据包进行过滤(条件匹配)即对接收到的报文进行匹配和过 滤,基于请求报文头部中的源地址、源端口、目标地址、目标端口、请求方法、URL、文件后缀等信息内 容进行匹配并执行进一步操作,比如允许其通过或丢弃。

#示例

frontend test_acl  
     bind *:80  
     mode http  #
     acl bad_browers hdr_beg(User-Agent) -i curl  
     #http-request deny if bad_browers  
     #acl test hdr_dom(host) -i www.timinglee.org  
     #acl test hdr_end(host) -i .org  
     #acl test base_sub -m sub org  
     #acl test path_sub -m sub /a  
     #acl test path_end -m sub /a  
     #acl test path_reg -i ^/t  
      acl test url_sub -m sub lee 
      acl test path_dir -m sub a  
      use_backend test_web if test  
      default_backend default_webserver 
backend default_webserver  
     mode http 
     server web1 172.25.254.20:80 check inter 3 fall 3 rise 5 
backend test_web  
     mode http  
     server web2 172.25.254.30:80 check inter 3 fall 3 rise 5

9.ACL实例

基于域名的访问:

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service

 

基于ip网段的访问:

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service

拒绝网段访问

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service

匹配浏览器类型

[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg
[root@haproxy ~]# systemctl restart haproxy.service

基于动静分离访问

[root@webserver ~]# dnf install php -y
[root@webserver ~]# systemctl restart httpd
[root@webserver ~]# vim /var/www/html/index.php
[root@webserver ~]# cat /var/www/html/index.php
<?php
    phpinfo()
?>

匹配访问路径实现动静分离

[root@webserver2 ~]# mkdir /usr/share/nginx/html/static
[root@webserver2 ~]# echo static - 172.25.254.20 > /usr/share/nginx/html/static/index.html


[root@webserver1 ~]# mkdir -p /var/www/html/php
[root@webserver1 ~]# cp /var/www/html/index.php  /var/www/html/php/

自定义错误页面

[root@haproxy ~]# rpm -ql haproxy  | grep http
/usr/share/doc/haproxy/design-thoughts/http2.txt
/usr/share/doc/haproxy/design-thoughts/http_load_time.url
/usr/share/doc/haproxy/internals/http-cookies.txt
/usr/share/doc/haproxy/internals/http-docs.txt
/usr/share/doc/haproxy/internals/http-parsing.txt
/usr/share/doc/haproxy/option-http_proxy.cfg
/usr/share/haproxy/400.http
/usr/share/haproxy/403.http
/usr/share/haproxy/408.http
/usr/share/haproxy/500.http
/usr/share/haproxy/502.http
/usr/share/haproxy/503.http
/usr/share/haproxy/504.http

[root@haproxy ~]# mkdir /etc/haproxy/errorpage/
[root@haproxy ~]# cp  -p /usr/share/haproxy/503.http  /etc/haproxy/errorpage/
[root@haproxy ~]# cd  /etc/haproxy/errorpage/
[root@haproxy errorpage]# ll
总用量 4
-rw-r--r-- 1 root root 213  2月 14  2023 503.http
[root@haproxy errorpage]# vim  /etc/haproxy/errorpage/503.http

 

[root@haproxy errorpage]# vim /etc/haproxy/haproxy.cfg
[root@haproxy errorpage]# systemctl restart haproxy.service

对 MySQL 服务实现四层负载

[root@webserver ~]#  dnf install mariadb-server -y
[root@webserver ~]#  vim /etc/my.cnf.d/mariadb-server.cnf
[root@webserver ~]# systemctl start mariadb

[root@webserver ~]# mysql -uroot -p

更改账号和密码:
MariaDB [(none)]> CREATE USER lee@'%' identified by 'lee';  
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> GRANT ALL ON *.* TO lee@'%';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> quit
Bye
[root@webserver ~]# mysql -ulee -plee
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.5.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT @@server_id
    -> ;
+-------------+
| @@server_id |
+-------------+
|           1 |
+-------------+
1 row in set (0.000 sec)

测试结果:ID由2变为1

[root@webserver2 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT @@server_id
    -> ;
+-------------+
| @@server_id |
+-------------+
|           2 |
+-------------+
1 row in set (0.000 sec)

haproxy的https

[root@haproxy errorpage]# mkdir -p /etc/haproxy/certs
[root@haproxy errorpage]# openssl req -newkey rsa:2048 -nodes -sha256 -keyout /etc/haproxy/certs/timinglee.org.key -x509 -days 365 -out /etc/h
haproxy/   host.conf  hostname   hosts      hp/        httpd/
[root@haproxy errorpage]# openssl req -newkey rsa:2048 -nodes -sha256 -keyout /etc/haproxy/certs/timinglee.org.key -x509 -days 365 -out /etc/haproxy/certs/timinglee.org.crt
.......+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*....+...+......+...........+.+.....+.........+...+.+..+...+.+.........+......+...+...+........+.......+..+.......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+......+.......+..+....+....................+.+......+...............+...+.....................+........+...+....+...+..+....+.....+................+........+......+....+........+....+...+......+............+..+.+...........+...............+.+...+...........+.+..+.+.........+..+...................+...........+....+....................+.........................+..+...+....+......+.................+.......+...+..+......+....+......+.....+.+.........+..+.......+...+..+...+....+.....+....+..+.........+...+.+..+....+...............+...........+.........+.+...+.....+..........+.....+......+.+...............+...+.....+.......+..+...+....+.....+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

..+...+.........+...+...+.......+...+.....+...+....+.....+.+...........+.........+....+..+................+...+.....+....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+.....................+......+..+.......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*......+..+.........+.+..+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,

If you enter '.', the field will be left blank.
-----

Country Name (2 letter code) [XX]:

Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:SHANXI
Locality Name (eg, city) [Default City]:XIAN
Organization Name (eg, company) [Default Company Ltd]:timinglee
Organizational Unit Name (eg, section) []:webserver
Common Name (eg, your name or your server's hostname) []:www.timinglee.org
Email Address []:admin@timinglee.org

[root@haproxy errorpage]# ls /etc/haproxy/certs/
timinglee.org.crt  timinglee.org.key
[root@haproxy errorpage]# cat /etc/haproxy/certs/timinglee.org.key  /etc/haproxy/certs/timinglee.org.crt  > /etc/haproxy/certs/timinglee.pem
[root@haproxy errorpage]# cat  /etc/haproxy/certs/timinglee.pem
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDvaCRzBNWAxCsn
------------------------------------------------------省略
alSdGAP6zLQdl6XbGh1ev68MTe+3JMQ3w6mffGM1ihd8N/t0xKxf5OE3PEo2yD1I
FKK0nDcifV2ynRsB8PYy44c5
-----END PRIVATE KEY-----


[root@haproxy errorpage]# vim /etc/haproxy/haproxy.cfg
[root@haproxy errorpage]# systemctl restart haproxy.service

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值