• ifconfig
  • 本机ip

  • hostname -i
  • 本机ip

  • curl ifconfig.io
  • 本机外网ip

  • ss
  • (https://www.cnblogs.com/yychuyu/p/11459575.html)
    Socket Statistics 的缩写,用来统计 socket 连接的相关信息,它跟 netstat 差不多,但有着比 netstat 更强大的统计功能,能够显示更多更详细的连接信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ss -s  #分类统计socket链接情况
    ss -a | wc -l 统计所有socket链接数目
    ss -ta #所有 TCP socket
    ss -ua #所有 UDP socket
    ss -wa #所有 RAW socket
    ss -xa #所有 UNIX socket
    ss -4a #所有 IPV4 socket
    ss -6a #所有 IPV6 socket
    ss -t  #要查看刚建立的 TCP 连接
    ss -lt #要仅显示监听 socket ,尝试
  • netstat
  • (https://www.cnblogs.com/ftl1012/p/netstat.html)
    netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告

    1
    netstat -nlp #数字(不解析主机端口)显示正在监听的进程pid
  • tcpdump
  • 功能强大

    1
    tcpdump  -XvvennSs 0 -i eth0 tcp[20:2]=0x4745 or tcp[20:2]=0x4854   #抓取http
  • lsof
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    lsof -i:80 #查看打开80端口的所有进程
    lsof -i [46] [protocol][@hostname|hostaddr][:service|port]
    46 --> IPv4 or IPv6
    protocol --> TCP or UDP
    hostname --> Internet host name
    hostaddr --> IPv4地址
    service --> /etc/service中的 service name (可以不只一个)
    port --> 端口号 (可以不只一个)
    例如:
    lsof -i tcp@127.0.0.1  #tcp监控本地
    lsof -i 4 #显示ipv4
  • iftop
  • https://www.vpser.net/manage/iftop.html

    位运算( 位运算baike

  • 奇偶判断
  • 1
    2
    3
    if(a&1 == 1){
    //偶数
    }
  • 两数交换
  • 1
    2
    3
    4
    5
    6
    7
    8
    //常规
    x = x^y
    y = x^y
    x = x^y
    //简写
    x ^= y
    y ^= x
    x ^= y
  • 数组里面就一个数出现一次 其他都是两次 求出这个数
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    int find(int[] arr)
    {
        int tmp = arr[0];
        for(int i=1;i<arr.length;i++)
        {
             tmp ^= arr[i];
        }
        return tmp;
    }
  • 不用加减运算符求两数只和
  • https://leetcode-cn.com/problems/sum-of-two-integers
    这个地方要了解加法器是如何运行的
    另外一个重点是负数在内存里面存储是补码 (https://blog.csdn.net/zl10086111/article/details/80907428)

    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
    40
    41
    42
    int getSum(int a, int b) {
        while (b != 0) {
            unsigned x = a ^ b;
            unsigned y = (unsigned)(a & b) << 1;
            a = x;
            b = y;
        }
        return a;
    }
    /*
            整数按照加法器来搞
             5 + 3
             0101
             0011

             x= 5^3 = 0110
             y= 5&3 = 0001

             x^ (y<<1) =
                    0110
                    0010 = 0100
             x& (y<<1)
                    0110
                    0010 = 0010

             x = 0100
             y = 0010


             x^ (y<<1) =
                    0100
                    0100 = 0000
             x& (y<<1)
                    0100
                    0100 = 0100

             x = 0000
             y = 0100

             x = 0000 ^ 1000 = 1000
             y = 0000 & 1000 = 0
    */

    其他请参考:位运算装逼指南 https://blog.csdn.net/Mrchai521/article/details/90318128

    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
    1.进制转换
        echo "obase=16;89"|bc

    2.时间戳转换

        2.1
            date -d '2013-2-22 22:14' +%s
            1361542440
        2.2
            date -d @1361542596
            Fri Feb 22 22:16:36 CST 2013
        2.3
            date -d @1361542596 +"%Y-%m-%d %H:%M:%S"
            2013-02-22 22:16:36

    3.json 格式化

        echo '{"aa":"good"}' | jq
        {
          "aa": "good"
        }

    4.其他:
        计算器:bc
        md5工具:md5sum

    vim curl-time.txt 添加以下内容

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    \n
             remote_ip: %{remote_ip}\n
           remote_port: %{remote_port}\n
              local_ip: %{local_ip}\n
            local_port: %{local_port}\n
                  http: %{http_code}\n
                   dns: %{time_namelookup}s\n
              redirect: %{time_redirect}s\n
          time_connect: %{time_connect}s\n
       time_appconnect: %{time_appconnect}s\n
      time_pretransfer: %{time_pretransfer}s\n
    time_starttransfer: %{time_starttransfer}s\n
         size_download: %{size_download}bytes\n
        speed_download: %{speed_download}B/s\n
                      ----------\n
            time_total: %{time_total}s\n
    \n

    试一试:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    curl  -w "@/Users/mac/Desktop/curl-time.txt" www.baidu.com
    <!DOCTYPE html>
    <!--STATUS OK--><html>*******</html>

             remote_ip: 180.101.49.12 #服务器ip
           remote_port: 80            #服务器端口
              local_ip: 30.208.75.45  #本地ip
            local_port: 49200         #本地端口
                  http: 200           #http状态码
                   dns: 0.030925s     #从开始到域名解析完成的时间
              redirect: 0.000000s     #所有重定向步骤(包括名称查找、连接、预传输和传输)所用的时间(秒)。显示多个重定向的完整执行时间。
          time_connect: 0.069830s     #从开始到tcp协议建立完成的时间
       time_appconnect: 0.000000s     #从开始到SSL/SSH/etc connect/handshake协议完成的时间
      time_pretransfer: 0.070846s     #从开始到文件传输即将开始
    time_starttransfer: 0.114130s     #从开始到第一个字节即将传输(time_starttransfer-time_pretransfer可以代表服务器处理的时间)
         size_download: 2381bytes     #总下载量
        speed_download: 20788.000B/s  #下载平均速度
                      ----------
            time_total: 0.114534s

    也可以直接输出,不用格式化文件方式。例如:
    curl  -w "time_total:%{time_total}" www.baidu.com

    如果这些环节还不够怎么办
    man curl
    找到:
    -w, –write-out 看看哪些变量是需要的可以再添加以下。

    云服务中只有一台可以访问外网,另外几台都没有外网ip。如何让其他机器能够访问外网

    1. 代理机器:可以访问外网的机器

    利用goproxy 安装配置非常简单https://github.com/snail007/goproxy/blob/master/README_ZH.md#%E8%87%AA%E5%8A%A8%E5%AE%89%E8%A3%85

    1
    2
    3
    4
    #安装
    curl -L https://raw.githubusercontent.com/snail007/goproxy/master/install_auto.sh | bash
    #启动
    proxy http -t tcp -p "0.0.0.0:38080" --daemon

    2. 需要访问外网的机器

    vim /etc/profile 添加

    1
    [work@xyz ~]$vim /etc/profile

    #内网机器不能上网需要配置个代理
    http_proxy=172.18.142.251:38080
    https_proxy=$http_proxy
    ftp_proxy=$http_proxy
    no_proxy=172.18.142.*,*.local,localhost,127.0.0.1
    export http_proxy https_proxy ftp_proxy no_proxy

    [work@xyz ~]$ source /etc/profile #即可

    git配置代理:

    1
    2
    3
    4
    5
    6
    [work@xyz ~]$ cat /home/work/.ssh/config
    Host gitee.com
    HostName gitee.com
    User git
    Port 22
    ProxyCommand nc --proxy 172.18.142.251:38080 %h %p

    [work@xyz ~]$chmod 600 /home/work/.ssh/config

    此处参考https://www.jianshu.com/p/05e3a2959efe

    但是goproxy 有个问题
    非注册版本自动版本检查退出

    https://github.com/snail007/goproxy/wiki/%E6%8F%90%E7%A4%BA%E8%AE%BF%E9%97%AE%E6%9B%B4%E6%96%B0%E5%A4%B1%E8%B4%A5%EF%BC%9F

    建议换成tinyproxy
    https://blog.csdn.net/shorile/article/details/79020927
    tinyproxy nc 支持有问题,所以git的代理走https的 tinyproxy没问题

    1. 集群配置+proxy 不支持事务,不支持 script load 的情况下, 一种实现事务的方法。

    eval 执行是具有原子性的(https://redis.io/commands/eval#atomicity-of-scripts) 但是 得注意 cluster的环境下
    用eval 执行多语句,遇到多个key的情况
    (error) CROSSSLOT Keys in request don’t hash to the same slot
    一个可以用的方案: https://redis.io/topics/cluster-spec#keys-hash-tags

    eval(script) 组装一个脚本,但是多个key必须用 keys hash tags的方法到一个slot里面,代理只会按照第一个key的hash来。

    2. redis 大厂解决方案
    https://www.cnblogs.com/me115/p/9043420.html
    很有必要参考,这个大厂确实是这么做的。开发过程中坑位很多。

    实现语言
    名称
    简介
    相关链接
    python
    gensim
    Gensim is a FREE Python library Scalable statistical semantics Analyze plain-text documents for semantic structure Retrieve semantically similar documents
    开源python库:灵活的语意统计 检索相似文档 可用来构建自己的文本模型(word tag)进行相识度检索
    python
    whoosh
    Whoosh is a fast, featureful full-text indexing and searching library implemented in pure Python. Programmers can use it to easily add search functionality to their applications and websites. Every part of how Whoosh works can be extended or replaced to meet your needs exactly. Some of Whoosh’s features include:
    ● Pythonic API.
    ● Pure-Python. No compilation or binary packages needed, no mysterious crashes.
    ● Fielded indexing and search.
    ● Fast indexing and retrieval — faster than any other pure-Python search solution I know of. See Benchmarks.
    ● Pluggable scoring algorithm (including BM25F), text analysis, storage, posting format, etc.
    ● Powerful query language.
    ● Production-quality pure Python spell-checker (as far as I know, the only one). Whoosh might be useful in the following circumstances:
    ● Anywhere a pure-Python solution is desirable to avoid having to build/compile native libraries (or force users to build/compile them).
    ● As a research platform (at least for programmers that find Python easier to read and work with than Java 😉
    ● When an easy-to-use Pythonic interface is more important to you than raw speed.
    ●If your application can make good use of one deeply integrated search/lookup solution you can rely on just being there rather than having two different search solutions (a simple/slow/homegrown one integrated, an indexed/fast/external binary dependency one as an option). Whoosh was created and is maintained by Matt Chaput. It was originally created for use in the online help system of Side Effects Software’s 3D animation software Houdini. Side Effects Software Inc. graciously agreed to open-source the code.
    whoosh 是一个python实现的快速且功能丰富的全文索引和搜索库。程序员可以轻而易举的给自己的应用或网站添加搜索功能。根据具体的场景,whoosh实现的每个部分都可以二次开发和替换。 个人开发者Matt Chaput 在公司上班的时候开发的。
    官方文档:
    python、java、c++等
    jieba
    “结巴”中文分词:做最好的 Python 中文分词组件。 功能:中文分词、词性标注、关键词抽取 目前已有各种语言的实现。和whoosh结合轻松实现中文检索。
    官方:
    rust
    sonic
    Sonic is a fast, lightweight and schema-less search backend. It ingests search texts and identifier tuples that can then be queried against in a microsecond’s time. Sonic can be used as a simple alternative to super-heavy and full-featured search backends such as Elasticsearch in some use-cases. It is capable of normalizing natural language search queries, auto-completing a search query and providing the most relevant results for a query. Sonic is an identifier index, rather than a document index; when queried, it returns IDs that can then be used to refer to the matched documents in an external database. A strong attention to performance and code cleanliness has been given when designing Sonic. It aims at being crash-free, super-fast and puts minimum strain on server resources (our measurements have shown that Sonic – when under load – responds to search queries in the μs range, eats ~30MB RAM and has a low CPU footprint; see our benchmarks).
    sonic 是个快速、轻量级、非结构化的搜索后端。专注文本和标记对的毫秒级查询。 sonic在某些场景下可以对重量级的全功能搜索引擎进行替代,比如elasticsearch。它能实现统一的自然语言查询,检索词自动补全,输出相关性结果。sonic是一个标记索引系统而不是文档索引系统:sonic的查询结果不是相关文档,而是外部数据库的ID标识。 设计sonic的时候就对性能和代码的整洁度非常关注。无故障、超快、轻度资源依赖就是sonic的目标。 起源于Crisp公司,背景就是简单+轻量资源。
    官方:
    (详细描述了关键特性)
    java
    Elasticsearch
    java
    Solr
    Solr is the popular, blazing-fast, open source enterprise search platform built on Apache Lucene™.
    Apache Lucence 项目的一个子项目。 Solr是一个流行、超快、开源的企业级的搜索平台。
    官方:
    java
    Lucene
    Apache Lucene is a high-performance, full-featured text search engine library written entirely in Java. It is a technology suitable for nearly any application that requires full-text search, especially cross-platform.
    Apache Lucence 项目的一个子项目。 Apache Lucence是一个java写的高性能的全文搜索引擎库。对于需要全文检索的应用比较好的技术解决方案,特别是跨平台的应用。
    官方 :
    c++
    sphinx
    Sphinx is an open source full text search server, designed from the ground up with performance, relevance (aka search quality), and integration simplicity in mind. It’s written in C++ and works on Linux (RedHat, Ubuntu, etc), Windows, MacOS, Solaris, FreeBSD, and a few other systems. Sphinx lets you either batch index and search data stored in an SQL database, NoSQL storage, or just files quickly and easily — or index and search data on the fly, working with Sphinx pretty much as with a database server. A variety of text processing features enable fine-tuning Sphinx for your particular application requirements, and a number of relevance functions ensures you can tweak search quality as well. Searching via SphinxAPI is as simple as 3 lines of code, and querying via SphinxQL is even simpler, with search queries expressed in good old SQL. Sphinx clusters scale up to tens of billions of documents and hundreds of millions search queries per day, powering top websites such as CraigslistLiving SocialMetaCafe and Groupon… to view a complete list of known users please visit our Powered-by page. And last but not least, it’s licensed under GPLv2.
    官方:
    关键特性:
    c++
    faiss
    Faiss is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also contains supporting code for evaluation and parameter tuning. Faiss is written in C++ with complete wrappers for Python/numpy. Some of the most useful algorithms are implemented on the GPU. It is developed by Facebook AI Research.
    相似向量搜索和密集向量聚类
    官方:
    c++
    SPTAG
    A distributed approximate nearest neighborhood search (ANN) library which provides a high quality vector index build, search and distributed online serving toolkits for large scale vector search scenario.
    官方:

     

    20款开源搜索引擎介绍与比较
    https://my.oschina.net/u/2274056/blog/1592809

    Solr vs. Elasticsearch谁是开源搜索引擎王者(中英文)
    https://www.cnblogs.com/xiaoqi/p/solr-vs-elasticsearch.html
    https://logz.io/blog/solr-vs-elasticsearch/

    开源搜索引擎Lucene、Solr、Sphinx等优劣势比较
    https://blog.csdn.net/belalds/article/details/82667692

    微软开源了 Bing 搜索背后的关键算法
    https://www.oschina.net/news/106730/microsoft-open-sources-sptag?nocache=1558414049690

    数据抓取工具:

      客户端模拟工具

    seleniumhq https://www.seleniumhq.org/
    phantomanjs
    appuim

      爬虫框架

    http://nutch.apache.org/
    pyspider 个人用过对小型项目很友好,功能简单易用。

    数据可视化如果做到以下几点就属于比较好的可视化平台了
    1)过程简单、生产效率要高(无论是研发、运营、产品都快可以快速的创建想要的图表)。
    2)自定义程度高:展现形式多样可选、交互自定义程度高(各种筛选过滤)。
    3)便于分享:数据的分享是数据价值体现的一个环节。
    4)数据的评论和备注:备注能够记录异常和原因,评论利于保存讨论和分析过程(一个相对完善的系统而言这个功能方便实际使用)。
    5)权限控制:自由总是相对的,相对分享就是控制,张弛有度必是这个系统长存的基石
    实现上述的可视化系统并非易事,里面涉及到很多的环节。
    但可视化做的比较好的tableau却给我们创建了一个比较好的典范。它在数据的分享、效率方面做得无可挑剔。
    实际环境中却不一定能直接使用一些成熟的解决方案,还需要自己搭建。

    继续阅读

    反向代理

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    package main

    import (
        "net/http"
        "net/http/httputil"
        "net/url"
    )

    func main() {
        //【[one line code] 一行代码http反向代理】
        //127.0.0.1:8900 转发到 10.0.12.110:6335
        //测试: curl http://127.0.0.1:8900

        u, _ := url.Parse("http://10.0.12.110:6335") //反向代理的目的地址
        http.ListenAndServe(":8900", httputil.NewSingleHostReverseProxy(u))

    }

    静态服务

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    package main

    import (
        "net/http"
    )

    func main() {

        //【[one line code] 一行代码静态web服务】
        //测试: curl http://127.0.0.1:8901/a.txt

        // 静态web服务:
        http.ListenAndServe(":8901", http.FileServer(http.Dir("/tmp")))

        //【[one line code] 一行代码静态web服务带路径转发】
        // curl 127.0.0.1:8902/tmpfiles/a.txt
        // url路径/tmpfile 映射到/tmp
        /*
            http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
            http.ListenAndServe(":8902", nil)
        */


    }

    当前比较好的sql格式化工具

    以下在网上搜集了一些比较好的sql格式化工具,各有利弊。但对hive sql 来说目前还没有比较好的工具可以直接拿过来用。
    1. ApexSQL Refactor SQL formatter
    2. SQL Pretty Printer
             Instant SQL Formatter (在线免费版本 ) http://www.dpriver.com/pp/sqlformat.htm
             SQL Pretty Printer (桌面应用收费版本) http://www.dpriver.com/products/sqlpp/desktop_index.php
    3. druid
             https://github.com/alibaba/druid 开源免费

    sql格式化之druid

          druid(alibaba)实现了sql语法的分析(和antlr生成的parse非常像),目前已经支持大部分常用的sql语法。查看其代码发现Terence Parr(antlr的作者)说的挺对的,词法和语法分析十分的枯燥,而且容易出现错误。可维护性特别差。
          druid内部实现了一个format方法并支持很多种sql语法,虽然druid的主要方向并不在此,有些大柴小用但是如果可用也是极好的。目前看druid在hive的语法实现上不完全,有些语法还未支持(比如定义个es的外表)。但是要实现具体的语法,门槛还是有的,相较antlr还是有点复杂、而且学习该技能通用型较差。实地勘探发现druid在sql格式化方法中的两个问题,当然在格式化这个问题上这个还存在另外一个更大的问题就是注释(这个它并没有关注,只是保留了两个listener):

    继续阅读