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

[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 2m
defaults
log global
mode http
option httplog
option dontlognull
timeout client 50000
timeout server 50000
timeout connect 5000 frontend http_front
mode http
bind *:80
stats uri /haproxy?stats
default_backend http_back
backend 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 ~]#

  

重启服务

[root@linux-node1 ~]# /etc/init.d/haproxy restart
Restarting haproxy (via systemctl): [ 确定 ]
[root@linux-node1 ~]#
[root@linux-node1 ~]#
[root@linux-node1 ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
haproxy 28420 haproxy 5u IPv4 216721 0t0 TCP *:http (LISTEN)
[root@linux-node1 ~]#

  

查看有没有生成socket

[root@linux-node1 ~]# ls /var/lib/haproxy/
haproxy.sock
[root@linux-node1 ~]#
 
通过socat和socket通信,它是cocket cat的缩写,安装
[root@linux-node1 ~]# yum list | grep socat
socat.x86_64 1.7.2.2-5.el7 base
[root@linux-node1 ~]# yum install -y socat

  

利用管道查看帮助命令

[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 ~]#

上面把支持的命令都显示出来了
下面就把页面监控上的东西都列出来了

[root@linux-node1 ~]# echo "show info" | socat stdio /var/lib/haproxy/haproxy.sock
Name: HAProxy
Version: 1.6.3
Release_date: 2015/12/25
Nbproc: 1
Process_num: 1
Pid: 28420
Uptime: 0d 0h09m43s
Uptime_sec: 583
Memmax_MB: 0
Ulimit-n: 4031
Maxsock: 4031
Maxconn: 2000
Hard_maxconn: 2000
CurrConns: 0
CumConns: 2
CumReq: 2
Maxpipes: 0
PipesUsed: 0
PipesFree: 0
ConnRate: 0
ConnRateLimit: 0
MaxConnRate: 0
SessRate: 0
SessRateLimit: 0
MaxSessRate: 0
CompressBpsIn: 0
CompressBpsOut: 0
CompressBpsRateLim: 0
Tasks: 5
Run_queue: 1
Idle_pct: 100
node: linux-node1.example.com
description: [root@linux-node1 ~]#

通过disable或者enable可以关闭或者启动某台主机
准备把linux-node2关闭了

这里的主机名和页面显示的以及配置文件配置的一致

[root@linux-node1 ~]# echo "disable server linux-node2" | socat stdio /var/lib/haproxy/haproxy.sock
Require 'backend/server'.

  

格式如下。 backend/server
[root@linux-node1 ~]# echo "disable server http_back/linux-node2" | socat stdio /var/lib/haproxy/haproxy.sock 

[root@linux-node1 ~]#

  

再次刷新页面就变成维护状态了

启动之后,恢复正常
[root@linux-node1 ~]# echo "enable server http_back/linux-node2" | socat stdio /var/lib/haproxy/haproxy.sock

目前还无法通过命令新增节点

  

haproxy调优的地方

1、不设置进程,默认就是1,单进程
2、网卡可能跑慢,换成万兆网卡,或者拆业务,拆成不同集群
3、haproxy的端口可能被用光,因为linux提供端口最多65535。
(1)改local的端口范围。
[root@linux-node1 ~]# cat /proc/sys/net/ipv4/ip_local_port_range
32768 60999
[root@linux-node1 ~]#
(2)改tcp的tw端口的复用,启用reuse,禁用recycle,改成1 
[root@linux-node1 ~]# cat /proc/sys/net/ipv4/tcp_tw_reuse
0
[root@linux-node1 ~]#
(3)可以缩短tw的时间,默认是60秒。
[root@linux-node1 ~]# cat /proc/sys/net/ipv4/tcp_fin_timeout
60
[root@linux-node1 ~]#
(4)使用多个IP

 

 

socat管理haproxy以及haproxy调优的更多相关文章

  1. HBase管理与监控——内存调优

    HMaster 没有处理过重的负载,并且实际的数据服务不经过 HMaster,它的主要任务有2个:一.管理Hbase Table的 DDL操作, 二.region的分配工作,任务不是很艰巨. 但是如果 ...

  2. spark调优篇-Spark ON Yarn 内存管理(汇总)

    本文旨在解析 spark on Yarn 的内存管理,使得 spark 调优思路更加清晰 内存相关参数 spark 是基于内存的计算,spark 调优大部分是针对内存的,了解 spark 内存参数有也 ...

  3. 素小暖讲JVM:Eclipse运行速度调优

    本系列是用来记录<深入理解Java虚拟机>这本书的读书笔记.方便自己查看,也方便大家查阅. 欲速则不达,欲达则欲速! 这两天看了JVM的内存优化,决定尝试一下,对Eclipse进行内存调优 ...

  4. HAProxy压测及参数调优

    背景 小米容器云平台,在构建云厂商集群时,需要通过HAProxy将云厂商LB流量从宿主机转到容器中,但对于HAProxy的性能没有把握.参考网上的一篇HAProxy压测文章,文章中提到HAProxy ...

  5. socat管理haproxy配置 ssh-keygen -N '' -t rsa -q -b 2048

    socat管理haproxy配置   haproxy是可以通过socat命令管理haproxy.cfg文件的:1.安装socat yum install socat -y 2.配置haproxy.cf ...

  6. MySQL基础普及《MySQL管理之道:性能调优、高可用与监控》

    最近工作的内容涉及MySQL运维内容,陆陆续续读了几本相关的书,其中一本是<MySQL管理之道:性能调优.高可用与监控>. 内容涵盖性能调优(包括sql优化等).备份.高可用,以及读写分离 ...

  7. MySQL管理之道,性能调优,高可用与监控(第二版)pdf下载

    MySQL管理之道,性能调优,高可用与监控(第二版) 书中内容以实战为导向,所有内容均来自于笔者多年实践经验的总结和新知识的拓展,同时也针对运维人员.DBA等相关工作者会遇到的有代表性的疑难问题给出了 ...

  8. MySQL 调优基础(二) Linux内存管理

    进程的运行,必须使用内存.下图是Linux中进程中的内存的分布图: 其中最重要的 heap segment 和 stack segment.其它内存段基本是大小固定的.注意stack是向低地址增长的, ...

  9. MySQL管理之道:性能调优、高可用与监控内置脚本

    MySQL管理之道:性能调优.高可用与监控内置脚本 随书附送脚本 keepalive配置文件和脚本开源工具pssh批量管理服务器(python) 下载地址 http://files.cnblogs.c ...

随机推荐

  1. 初始FreeMake

    此文章是观看视频学习的,只是一点点基础还不太深 视频地址:http://www.icoolxue.com/play/5773 源码:码云:https://gitee.com/wmjGood/FreeM ...

  2. 力扣(LeetCode)561. 数组拆分 I

    给定长度为 2n 的数组, 你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), ..., (an, bn) ,使得从1 到 n 的 min(ai, bi) 总和最大. 示例 ...

  3. 版本控制——Version Control

    版本控制是指对软件开发过程中各种程序代码.配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一. 版本控制最主要的功能就是追踪文件的变更.它将什么时候.什么人更改了文件的什么内容等信息忠实 ...

  4. javascript里文字选中/选中文字

    一.获取/清除选中的文字 //获取选中的文字 document.getElementById("get").onclick = function () { var txt = wi ...

  5. 【log4j】使用注意事项

    实际过程中,使用log4j遇到的一些问题,进行总结: 1.log4j.properties文件的放置路径: 必须放在src的根目录下,这样就不需要额外的加载了 2.申明一个log对象 Logger l ...

  6. jquery promise (Deferred)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. java截取字符串,第4位以后的字符串用*代替

    public class F { public static void main(String[] args) { /**截取字符串,第4位以后的字符串用*代替*/ String s = " ...

  8. shell中下载最新版本或指定版本的办法(Dockerfile 中通用)

    VER=$(curl -s https://api.github.com/repos/v2ray/v2ray-core/releases/latest | grep tag_name | cut -d ...

  9. jsp九大内置对象 ,三大指令,四大作用域,七大动作

    九大内置对象: application:应用程序对象 对整个web工程都有效 request:对当前请求的封装 pageConfig:只对当前页面有效,里面封装了基本request和session的对 ...

  10. Python文件读写(open(),close(),with open() as f...)

    Python内置了读写文件的函数,用法和C是兼容的.本节介绍内容大致有:文件的打开/关闭.文件对象.文件的读写等. 本章节仅示例介绍 TXT 类型文档的读写,也就是最基础的文件读写,也需要注意编码问题 ...