冰澜

  • 首页

  • 标签

  • 归档

  • 搜索

run nsq by docker

发表于 2018-09-23 | 更新于 2018-10-05 | | 阅读次数:

components

nsqd

nsqd is the daemon that receives, queues, and delivers messages to clients.
two tcp ports: one for clients and one for HTTP API

nsqlookupd

the daemon that manages topology information.
Clients query nsqlookupd to discover nsqd producers for a specific topic and nsqd nodes broadcasts topic and channel information.
two interfaces: A TCP interface which is used by nsqd for broadcasts and an HTTP interface for clients to perform discovery and administrative actions.

nsqadmin

Web UI to view aggregated cluster stats in realtime and perform various administrative tasks

阅读全文 »

Linux 编码理解

发表于 2018-09-23 | 更新于 2018-10-05 | | 阅读次数:

系统的编码方式

在我所使用的 centos6 中使用 echo $LANG 查看编码
系统的编码方式决定了在终端中录入的内容的编码方式

编辑器所使用的文件编码方式

在 vim 中,set fileencoding 查看当前编码方式
编辑器的编码方式决定了在代码中录入内容的编码方式,如 a[‘key’] = value,此时的 ‘key’ 字段按照 fileencoding 的方式编码

代码中使用的编码方式

例如 if a == b : pass,此内容的编码方式

从文件中读取的内容的编码方式

例如:

1
2
redis_cli>>
set “marco:domains” “basic.b0.upaiyun.com” “basic"

此写入redis的内容,根据终端的编码方式决定, 我的系统默认是utf-8 ,所以此处也是utf-8内容

阅读全文 »

netcat skills

发表于 2018-09-23 | 更新于 2018-10-05 | | 阅读次数:

Linux netcat 命令实例:

端口扫描

端口扫描经常被系统管理员和黑客用来发现在一些机器上开放的端口,帮助他们识别系统中的漏洞。

$nc -z -v -n 172.31.100.7 21-25

可以运行在TCP或者UDP模式,默认是TCP,-u参数调整为udp.

z 参数告诉netcat使用0 IO,连接成功后立即关闭连接, 不进行数据交换

v 参数指使用冗余选项

n 参数告诉netcat 不要使用DNS反向查询IP地址的域名

这个命令会打印21到25 所有开放的端口。Banner是一个文本,Banner是一个你连接的服务发送给你的文本信息。当你试图鉴别漏洞或者服务的类型和版本的时候,Banner信息是非常有用的。但是,并不是所有的服务都会发送banner。

一旦你发现开放的端口,你可以容易的使用netcat 连接服务抓取他们的banner。

$ nc -v 172.31.100.7 21

netcat 命令会连接开放端口21并且打印运行在这个端口上服务的banner信息。

阅读全文 »

build bind with edns support

发表于 2018-09-23 | | 阅读次数:

download and extract BIND.

1
2
3
$ wget ftp://ftp.isc.org/isc/bind9/9.9.3/bind-9.9.3.tar.gz
$ tar xf bind-9.9.3.tar.gz
$ cd bind-9.9.3

Download the patch from Wilmer van der Gaast.

1
$ wget http://wilmer.gaa.st/edns-client-subnet/bind-9.9.3-dig-edns-client-subnet-iana.diff

Patch the code, configure (without OpenSSL because we only want dig) and compile.

1
2
3
$ patch -p0 < bind-9.9.3-dig-edns-client-subnet-iana.diff
$ ./configure --without-openssl
$ make

Now you will have dig placed in bin/dig. You can try it this way:

1
$ ./bin/dig/dig @ns1.google.com www.google.es +client=157.88.0.0/16

Note the CLIENT-SUBNET line in the answer OPT PSEUDOSECTION.>

Unix 环境变量加载顺序

发表于 2018-09-23 | | 阅读次数:

OSX

Mac系统的环境变量加载顺序为

1
/etc/profile -> /etc/paths -> ~/.bash_profile -> ~/.bash_login ->  ~/.profile -> ~/.bashrc

特别注意 /etc/paths 中的内容

1
2
3
4
5
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

Homebrew 安装的软件,其二进制执行文件都放在/usr/local/bin中,
bin 在使用时的查找不是覆盖原则,而是优先查找,所以例如 mac 已经自带了sqlite3,如果 brew 安装后,最新版的 sqlite3 是不会被调用的,因此可以将顺序修改一下以达到目的。

Linux

Mac系统的环境变量加载顺序为

1
/etc/profile -> (~/.bash_profile | ~/.bash_login | ~/.profile) -> ~/.bashrc -> /etc/bashrc -> ~/.bash_logout

/usr/bin:usr/sbin 在 /etc/profile 文件中

Nginx 基于权重的平滑轮询算法

发表于 2018-03-19 | 更新于 2018-10-05 | | 阅读次数:

Nginx 基于权重的轮询算法

Nginx基于权重的轮询算法的实现可以参考它的一次代码提交 Upstream: smooth weighted round-robin balancing

它不但实现了基于权重的轮询算法,而且还实现了平滑的算法。所谓平滑,就是在一段时间内,不仅服务器被选择的次数的分布和它们的权重一致,而且调度算法还比较均匀的选择服务器,而不会集中一段时间之内只选择某一个权重比较高的服务器。如果使用随机算法选择或者普通的基于权重的轮询算法,就比较容易造成某个服务集中被调用压力过大。

举个例子,比如权重为 {a:5, b:1, c:1} 的一组服务器,Nginx 的平滑的轮询算法选择的序列为{ a, a, b, a, c, a, a },这显然要比{ c, b, a, a, a, a, a } 序列更平滑,更合理,不会造成对a服务器的集中访问。

Lua 实现

每次需要遍历所有的 servers 列表,返回 best server

阅读全文 »

Unix tcpdump 使用技巧

发表于 2018-03-18 | 更新于 2018-10-05 | | 阅读次数:

常用 tcpdump 参数解析

  • -i 指定网卡,一般不清楚网卡设置直接使用 “any” 表示抓取所有网卡
  • -A 使用 ASCII 码打印收到的每个包
  • -X 同时以十六进制和 ASCII 打印包

常用抓包实例

1
2
3
4
5
6
7
8
9
10
11
# host 和 port 过滤
tcpdump -i any -Ans 0 "src host 1.1.1.1 && dst host 2.2.2.2 && dst port 3100"

# GET
tcpdump -i eth1 'tcp[(tcp[12]>>2):4] = 0x47455420'

# POST
tcpdump -i eth1 'tcp[(tcp[12]>>2):4] = 0x504f5354'

# TCP 标志位
tcpdump -i any -Ans 0 'host 183.214.154.4 && tcp[tcpflags]=tcp-syn'
阅读全文 »

使用 pprof 和 Flame-Graph 调试 Golang 应用

发表于 2018-01-21 | 更新于 2018-10-05 | | 阅读次数:

前言

最近用 Golang 实现了一个日志搜集上报程序(内部称 logger 项目),线上灰度测试过程发现 logger 占用 CPU 非常高(80% - 100%)。而此项目之前就在线上使用,用于消费 NSQ 任务, CPU 占用一直在 1%,最近的修改只是添加了基于磁盘队列的生产者消费者服务,生产者使用 go-gin 实现了一个 httpserver,接收数据后写入磁盘队列;消费者为单个 goroutine 循环 POST 数据。而 httpserver 压力不大(小于 100 QPS),不至于占用如此高的 CPU,大致 review 代码后未发现异常,借助 pprof 和 flame-graph 来分析定位问题。

pprof

pprof 我理解是 program profile(即程序性能剖析之意),Golang 提供的两个官方包
runtime/pprof,
net/http/pprof
能方便的采集程序运行的堆栈、goroutine、内存分配和占用、io 等信息的 .prof 文件,然后可以使用 go tool pprof 分析 .prof 文件。两个包的作用是一样的,只是使用方式的差异。

阅读全文 »

Linux 使用 grep 找回误删文件

发表于 2016-09-26 | 更新于 2018-09-23 | | 阅读次数:

在操作 linux 过程中,经常由于错误的操作误删除文件,则可以使用 grep 操作找回

命令

1
$ grep -a -B 10 -A 100 'vpsee.com' /dev/sda1 > tmp.txt
  • -a表示将磁盘 /dev/sda1 当做二进制文件来读
  • -B 10 -A 100 表示如果匹配到 vpsee.com,则打印前 10 行和后 100 行
  • 匹配结果重定向到 tmp.txt

note

  1. 在发现误删除文件后,尽量减少其他的文件操作避免已删除的文件被覆盖。
  2. grep 操作耗费会占用大量的内存空间,如果发现 grep 失败(虚拟机中),可多分配内存重试。
  3. 可能删除的文件不在 /dev/sda1 磁盘上,可使用 df 来查看是否有其他磁盘。

lua and 和 or 踩坑

发表于 2016-09-25 | 更新于 2018-10-05 | | 阅读次数:

lua and or 操作

  • a and b
    如果a为false,则返回 a;否则返回 b

  • a or b
    如果 a 为 true,则返回 a;否则返回 b

C语言中的语句:x = a? b : c,在Lua中可以写成:x = a and b or c

存在的问题

1
2
debug = 0(or 1)
step = debug and 0 or 80
阅读全文 »
123
anyfeel

anyfeel

我就是我,是颜色不一样的烟花

22 日志
7 标签
© 2015 – 2019 anyfeel
由 Hexo 强力驱动 v3.7.1
|
主题 – NexT.Pisces v6.4.2