学习Haproxy (八)
Unix套接字命令(Unix Socket commands)
socat是一个多功能的网络工具,名字来由是“Socket CAT”,可以看作是netcat的N倍加强版,socat的官方网站:http://www.dest-unreach.org/socat/ 。
socat是一个两个独立数据通道之间的双向数据传输的继电器。
这些数据通道包含文件、管道、设备(终端或调制解调器等)、插座(Unix,IP4,IP6 - raw,UDP,TCP)、SSL、SOCKS4客户端或代理CONNECT。
socat支持广播和多播、抽象Unix sockets、Linux tun/tap、GNU readline和PTY。
它提供了分叉、记录和进程间通信的不同模式。多个选项可用于调整socat和其渠道,Socat可以作为TCP中继(一次性或守护进程),作为一个守护进程基于socksifier,
作为一个shell Unix套接字接口,作为IP6的继电器,或面向TCP的程序重定向到一个串行线。
socat的主要特点就是在两个数据流之间建立通道;且支持众多协议和链接方式:ip, tcp, udp, ipv6, pipe,exec,system,open,proxy,openssl,socket等。
使用socat可以查看和设置HAProxy状态,首先得让HAProxy产生出一个sock出来(hatop ,socat都是基于这个的,没这个什么都做不了)。
设置配置文件开启unix socket
在global 下面 加一行:
stats socket /usr/local/haproxy/stats #路径和名字随意
然后重启服务就可以了。
配置文件加入socket这行
权限600,级别admin
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
[root@linux-node1 ~]# cat /etc/haproxy/haproxy.cfg global chroot /var/lib/haproxy daemon group haproxy user haproxy log 127.0.0.1:514 local3 info stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin stats timeout 2mdefaults log global mode http option httplog option dontlognull timeout client 50000 timeout server 50000 timeout connect 5000frontend http_front mode http bind *:80 stats uri /haproxy?stats default_backend http_backbackend http_back option forwardfor header X-REAL-IP #option httpchk GET /index.html balance roundrobin server linux-node1 10.0.1.105:8080 # check inter 2000 rise 3 fall 3 weight 1 server linux-node2 10.0.1.106:8080 # check inter 2000 rise 3 fall 3 weight 1[root@linux-node1 ~]# |
重启服务
|
1
2
3
4
5
6
7
8
|
[root@linux-node1 ~]# /etc/init.d/haproxy restartRestarting haproxy (via systemctl): [ 确定 ][root@linux-node1 ~]# [root@linux-node1 ~]# [root@linux-node1 ~]# lsof -i:80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhaproxy 28420 haproxy 5u IPv4 216721 0t0 TCP *:http (LISTEN)[root@linux-node1 ~]# |
查看有没有生成socket
|
1
2
3
|
[root@linux-node1 ~]# ls /var/lib/haproxy/haproxy.sock[root@linux-node1 ~]# |
|
1
2
3
|
[root@linux-node1 ~]# yum list | grep socatsocat.x86_64 1.7.2.2-5.el7 base [root@linux-node1 ~]# yum install -y socat |
利用管道查看帮助命令
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
[root@linux-node1 ~]# echo "help" | socat stdio /var/lib/haproxy/haproxy.sock Unknown command. Please enter one of the following commands only : clear counters : clear max statistics counters (add 'all' for all counters) clear table : remove an entry from a table help : this message prompt : toggle interactive mode with prompt quit : disconnect show backend : list backends in the current running config show info : report information about the running process show pools : report information about the memory pools usage show stat : report counters for each proxy and server show errors : report last request and response errors for each proxy show sess [id] : report the list of current sessions or dump this session show table [id]: report table usage stats or dump this table's contents show servers state [id]: dump volatile server information (for backend <id>) get weight : report a server's current weight set weight : change a server's weight set server : change a server's state, weight or address set table [id] : update or create a table entry's data set timeout : change a timeout setting set maxconn : change a maxconn setting set rate-limit : change a rate limiting value disable : put a server or frontend in maintenance mode enable : re-enable a server or frontend which is in maintenance mode shutdown : kill a session or a frontend (eg:to release listening ports) show acl [id] : report avalaible acls or dump an acl's contents get acl : reports the patterns matching a sample for an ACL add acl : add acl entry del acl : delete acl entry clear acl <id> : clear the content of this acl show map [id] : report avalaible maps or dump a map's contents get map : reports the keys and values matching a sample for a map set map : modify map entry add map : add map entry del map : delete map entry clear map <id> : clear the content of this map set ssl <stmt> : set statement for ssl[root@linux-node1 ~]# |
上面把支持的命令都显示出来了
下面就把页面监控上的东西都列出来了
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
[root@linux-node1 ~]# echo "show info" | socat stdio /var/lib/haproxy/haproxy.sock Name: HAProxyVersion: 1.6.3Release_date: 2015/12/25Nbproc: 1Process_num: 1Pid: 28420Uptime: 0d 0h09m43sUptime_sec: 583Memmax_MB: 0Ulimit-n: 4031Maxsock: 4031Maxconn: 2000Hard_maxconn: 2000CurrConns: 0CumConns: 2CumReq: 2Maxpipes: 0PipesUsed: 0PipesFree: 0ConnRate: 0ConnRateLimit: 0MaxConnRate: 0SessRate: 0SessRateLimit: 0MaxSessRate: 0CompressBpsIn: 0CompressBpsOut: 0CompressBpsRateLim: 0Tasks: 5Run_queue: 1Idle_pct: 100node: linux-node1.example.comdescription: [root@linux-node1 ~]# |
通过disable或者enable可以关闭或者启动某台主机
准备把linux-node2关闭了

这里的主机名和页面显示的以及配置文件配置的一致
|
1
2
|
[root@linux-node1 ~]# echo "disable server linux-node2" | socat stdio /var/lib/haproxy/haproxy.sock Require 'backend/server'. |
|
1
2
3
|
[root@linux-node1 ~]# echo "disable server http_back/linux-node2" | socat stdio /var/lib/haproxy/haproxy.sock [root@linux-node1 ~]# |

|
1
|
[root@linux-node1 ~]# echo "enable server http_back/linux-node2" | socat stdio /var/lib/haproxy/haproxy.sock |

haproxy调优的地方
|
1
2
3
|
1、不设置进程,默认就是1,单进程2、网卡可能跑慢,换成万兆网卡,或者拆业务,拆成不同集群3、haproxy的端口可能被用光,因为linux提供端口最多65535。 |
|
1
2
3
|
[root@linux-node1 ~]# cat /proc/sys/net/ipv4/ip_local_port_range 32768 60999[root@linux-node1 ~]# |
|
1
2
3
|
[root@linux-node1 ~]# cat /proc/sys/net/ipv4/tcp_tw_reuse 0[root@linux-node1 ~]# |
|
1
2
3
|
[root@linux-node1 ~]# cat /proc/sys/net/ipv4/tcp_fin_timeout 60[root@linux-node1 ~]# |
学习Haproxy (八)的更多相关文章
- MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合(转载)
孤傲苍狼 只为成功找方法,不为失败找借口! MyBatis学习总结(八)--Mybatis3.x与Spring4.x整合 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: m ...
- Java IO流学习总结八:Commons IO 2.5-IOUtils
Java IO流学习总结八:Commons IO 2.5-IOUtils 转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/550519 ...
- Learning ROS forRobotics Programming Second Edition学习笔记(八)indigo rviz gazebo
中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS forRobotics Pro ...
- python学习第八讲,python中的数据类型,列表,元祖,字典,之字典使用与介绍
目录 python学习第八讲,python中的数据类型,列表,元祖,字典,之字典使用与介绍.md 一丶字典 1.字典的定义 2.字典的使用. 3.字典的常用方法. python学习第八讲,python ...
- 从零学习Fluter(八):Flutter的四种运行模式--Debug、Release、Profile和test以及命名规范
从零学习Fluter(八):Flutter的四种运行模式--Debug.Release.Profile和test以及命名规范 好几天没有跟新我的这个系列文章,一是因为这两天我又在之前的基础上,重新认识 ...
- 【转载】 强化学习(八)价值函数的近似表示与Deep Q-Learning
原文地址: https://www.cnblogs.com/pinard/p/9714655.html ------------------------------------------------ ...
- (转)Maven学习总结(八)——使用Maven构建多模块项目
孤傲苍狼只为成功找方法,不为失败找借口! Maven学习总结(八)——使用Maven构建多模块项目 在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为doma ...
- python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑
python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑 许多人在安装Python第三方库的时候, 经常会为一个问题困扰:到底应该下载什么格式的文件?当我们点开下载页时, 一般 ...
- Go语言学习笔记八: 数组
Go语言学习笔记八: 数组 数组地球人都知道.所以只说说Go语言的特殊(奇葩)写法. 我一直在想一个人参与了两种语言的设计,但是最后两种语言的语法差异这么大.这是自己否定自己么,为什么不与之前统一一下 ...
- Git 学习(八)其他
Git 学习(八)其他 通过以上七章Git的学习,基本操作已差不多了,本章介绍一点落网之鱼: 包括如何忽略文件.配置别名.以及使用GitHub等. 当然,Git的强大远不是七章内容可概括的,之后可结 ...
随机推荐
- 为什么用Python,高级的Python是一种高级编程语言
Python特性 如果有人问我Python最大的特点是什么,我会毫不犹豫地告诉他:它简单易学,功能强大.作为一个纯自由软件,Python有许多优点: 很简单.基于"优雅".&quo ...
- mac上Navicat新建数据库3680错误解决办法
mac上Navicat新建数据库3680错误解决办法 1.在设置里关闭mysql,若不能关闭,在终端输入: sudo /usr/local/mysql/support-files/mysql.serv ...
- C#爬虫(04):HtmlAgilityPack解析html文档
原文链接 https://www.cnblogs.com/springsnow/p/13278283.html 目录 一.爬虫概述 1.使用浏览器获取页面源码 2.HTML解析组件 二.HtmlAgi ...
- linux设置 自定义脚本开机启动
本文原创,转载请标明出处 https://blog.csdn.net/qq2531246791/article/details/89036084 一. 赋予可执行权限 chmod +x /etc/rc ...
- WPS备份的位置
C:\Users\Administrator\AppData\Roaming\kingsoft\office6\backup 也可以从左上图标->工具->备份管理->查看其它备份,直 ...
- 进程&线程(一)——multiprocessing,threading
本节内容为①进程线程的基础知识:②在Python的实现方法: 学习总结自: 一文看懂Python多进程与多线程编程(工作学习面试必读) - 知乎 multiprocessing 官方文档 1.进程线程 ...
- Django的orm(一)
Django的orm一 1.创建表 1.1 创建普通表 class UserType(models.Model): ''' 用户类型 ''' title=models.CharField(max_le ...
- 修饰符-final
Java是由C/C++泛生的,其也保留了C/C++的部分特性,如关键字.在C/C++中,关键字有着特殊的含义. final修饰符 在编程中,一般会存在一些变量或方法,程序员不让其数据"发生改 ...
- vm虚拟机安装CentOS8.2服务器系统
前言 开发服务器应用,需要使用到CentOS8.2,安装到虚拟机上方便快捷. 提前准备 Vmware 16虚拟机软件 下载VM16版本及以上的vmware虚拟机版本,否则没有CentOs8选 ...
- C/C++ 大型工程工具链搭建
一.配置环境要求 C/C++ 编译器 此项有系统区别,如果是 Windows 平台,那么可以下载 VS2022 社区版,它自带 MSVC 编译器.如果嫌它太笨重,也可以直接下载 MSVC 再发行组件. ...