linux

ES create index with analyzer

//curl -X PUT "http://192.168.71.52:9200/shirtcity_design_de_v1" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "analysis": {
      "analyzer": {
        "sc_analyzer": {
          "tokenizer": "sc_tokenizer"
        }
      },
      "tokenizer": {
        "sc_tokenizer": {
          "type": "ngram",
          "min_gram": 3,
          "max_gram": 3,
          "token_chars": [
            "letter",
            "digit"
          ]
        }
      }
    }
  },
  "mappings": {
    "designs": {
      "properties": {
        "big_template": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "checkout": {
          "type": "long"
        },
        "design_id": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "group": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "location": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          },
          "analyzer": "sc_analyzer"
        }
      }
    }
  }
}

 


线上僵死进程问题的排查

对于线上僵死进程问题的排查,一般需要如下命令工具:

ps -aux // 得到僵死进程pid

strace -p pid // 查看僵死进程底层的调用信息,获取到 fd

lsof -d FD // 查看fd对应文件信息

gdb --pid=PID // 通过gdb查看代码调用信息

tcpdump // 抓网络包

批量kill进程:for proc in $(lsof -d 94 |grep “xxx.xxx.xxx.xxx” |awk ‘{print $2}’); do kill $proc; done


TCP分包粘包问题

printf("%2c", 355)
  • 固定包头 + 包体协议

固定包头的方法非常通用,在服务器端程序中经常能看到。这种协议的特点是一个数据包总是由包头 + 包体 2 部分组成。包头由一个字段指定了包体或整个包的长度,长度一般是使用 2 字节 /4 字节整数来表示。服务器收到包头后,可以根据长度值来精确控制需要再接收多少数据就是完整的数据包。Swoole 的配置可以很好的支持这种协议,可以灵活地设置 4 项参数应对所有情况。


Solving Error response from daemon OCI runtime create failed container with id exists

I restarted system for the testing my new systemd service. After the restart my some dockers start via command and I get this error.

root@fra ~>docker start bindnat64
Error response from daemon: OCI runtime create failed: container with id exists: 4871484679fsd498sg4hr9t989                                                                      9041a6b77dd7dc64b97e15cbd: unknown
Error: failed to start containers: bindnat64

For the detailed problem solving run docker in debug mode in command line.

root@fra ~> service docker stop
root@fra ~> dockerd --debug
INFO[2020-01-17T23:15:00.799572801Z] Starting up
DEBU[2020-01-17T23:15:00.816102056Z] Listener created for HTTP on unix (/var/run/docker.sock)
DEBU[2020-01-17T23:15:00.820722321Z] Golang's threads limit set to 2970
INFO[2020-01-17T23:15:00.836791146Z] parsed scheme: "unix"                         module=grpc
INFO[2020-01-17T23:15:00.837428925Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2020-01-17T23:15:00.838003954Z] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0  <nil>}] <nil>}  module=grpc
INFO[2020-01-17T23:15:00.838451356Z] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2020-01-17T23:15:00.859419482Z] parsed scheme: "unix"                         module=grpc
INFO[2020-01-17T23:15:00.860449827Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2020-01-17T23:15:00.861054713Z] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock 0  <nil>}] <nil>}  module=grpc
INFO[2020-01-17T23:15:00.861528201Z] ClientConn switching balancer to "pick_first"  module=grpc
DEBU[2020-01-17T23:15:00.871091213Z] Using default logging driver json-file
DEBU[2020-01-17T23:15:00.874882162Z] [graphdriver] priority list: [btrfs zfs overlay2 aufs overlay devicemapper vfs]
DEBU[2020-01-17T23:15:00.908944376Z] processing event stream                       module=libcontainerd namespace=plugins.moby
DEBU[2020-01-17T23:15:01.000878576Z] backingFs=extfs, projectQuotaSupported=false, indexOff="index=off,"  storage-driver=overlay2
INFO[2020-01-17T23:15:01.001615063Z] [graphdriver] using prior storage driver: overlay2
DEBU[2020-01-17T23:15:01.002094888Z] Initialized graph driver overlay2
***
ERRO[2020-01-17T23:15:02.591864507Z] stream copy error: reading from a closed fifo
ERRO[2020-01-17T23:15:02.592325661Z] stream copy error: reading from a closed fifo
***
INFO[2020-01-17T23:15:05.190269583Z] Loading containers: done.
INFO[2020-01-17T23:15:05.259382156Z] Docker daemon                                 commit=633a0ea838 graphdriver(s)=overlay2 version=19.03.5

?

To solve this problem with remove container state folder inside docker folder.

#For example my container name bindnat64 and docker id is 4871484679fsd498sg4hr9t989.
root@fra ~> rm -rf /var/run/docker/runtime-runc/moby/4871484679fsd498sg4hr9t989
root@fra ~>docker start bindnat64
bindnat64

Looks like a problem solved but it`s not solved. When you try to execute program inside docker container you get another Error.

Close dockerd and restart your Server.

Hopely after the restarting system your docker container will be work without error.


Edit

In my case, I see this error again on my system. This time, it is a bit harder to fix then before. Because now it is not based on one container. My chance is all my containers is not important. So I deleted all stat information on a system.

root@fra ~> rm -rf /var/run/docker/runtime-runc/moby/*
root@fra ~> service docker stop
root@fra ~> reboot

I restart my server and delete stat information, I do this process until docker service works without any problem.


ssl证书到期时间查询

  1. 在服务端使用 Openssl 工具进行查看

    由于我服务端是搭建在 Centos 上,所以用 xshell 或者 putty 工具登录后,进入证书目录,使用 openssl 命令进行查看:

    # cd /usr/ssl/cert

    # openssl x509 -in signed.crt -noout -dates

    上面改成你自己证书的所在目录,证书名称也改成你自己服务端上证书的名称。

  2. 使用 php 代码方法进行查看

    如果你有多个可访问的域名,那么使用代码的方法进行查看就会容易很多,省得一个一个手动查看。下面贴上代码:

    /**
     * 获取证书有效期
     */
    public function getValidity(){
      $domain = "sslforfree.com";
      $context = stream_context_create(array("ssl" => array("capture_peer_cert_chain" => true)));
      $socket = stream_socket_client("ssl://$domain:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
      $context = stream_context_get_params($socket);
      foreach ($context["options"]["ssl"]["peer_certificate_chain"] as $value) {
        //使用openssl扩展解析证书,这里使用x509证书验证函数
        $cerInfo = openssl_x509_parse($value);
        if(strpos($cerInfo['name'],$domain)) {
          echo  "start:".date("Y-m-d",$cerInfo['validFrom_time_t'])."<br/>";
          echo "end:".date("Y-m-d",$cerInfo['validTo_time_t']);
        }
      }
    }

     


git还原代码

如果你的仓库是自己在用(不影响别人),那么你可以使用

git reset --hard <target_commit_id>

 

来恢复到指定的提交,再用

git push -f

 

来强制更新远程的分支指针。为了保证万一需要找回历史提交,我们可以先打一个 tag 来备份。

 

如果你的仓库是多人在协作,那么你这么操作会使用别人本地的代码库混乱,所以只能建一个新的提交,这个新的提交中把想取消的提交都 revert 掉,那么具体应该如何做呢?方法如下:

首先,和刚刚一样,用

git reset --hard 23801b2

将代码切换到目标提交的 id。接下来,用

git reset --soft origin/source 命令(source 分支)

,将当前代码切换回最新的提交。

执行完上面两步后,你的仓库还是最新的提交,但是工作区变成了历史的提交内容,这个时候用 git add 和 git commit 即可。

该方法需要保证 reset 的时候没有别人做新的提交,如果有的话,会一并把别人的提交也撤销了。所以还是挺危险的,慎用。


Composer Memory No Limit

$ COMPOSER_MEMORY_LIMIT=-1 php composer.phar [command]

1 Comment more...

Postfix und Courier mit TLS und SSL und Antispam (also STARTTLS, IMAPS, POP3S und DNSBL) unter Debian

nachdem die Default-Installation ja ein wenig mager in Sachen Verschlüsselung ist, habe ich die Freiheit von Froxlor genutzt, um ein paar Anpassungen vorzunehmen.

(continue reading…)


HowTo Install Redmine on Debian 8 with Apache2-Passenger

This HowTo describes installing redmine 3.0.1 on Debain 8 (April 15, few weeks before released as
stable) with Apache and MySQL.

Hint:
Run all commands as normal user. If root privileges required i used sudo (the ‘sudo’ package needs to be properly instaled and configured). (continue reading…)


Debian升级

Debian 6(Squeeze)升级至Debian 7(Wheezy) (7级8同理)
Debian GNU/Linux支持滚动更新,出于安全方面的考虑,当新版Debian发行后,我们一般会将现有版本的Debian升级至最新的稳定版的Debian。升级除了可以提升系统的安全性以外,同时还可以获得由更新版本的应用软件带来的新功能及其它好处。这就是我们为什么要将Debian 6(Squeeze)升级至Debian 7(Wheezy)的原因。
(continue reading…)


Copyright © 1996-2010 Add Lives. All rights reserved.
iDream theme by Templates Next | Powered by WordPress