pymro 发布的文章

1)使用ngx.location.capture

返回一个包含四个元素的 Lua 表 (res.status, res.header, res.body, 和 res.truncated)。
因为 Nginx 内核限制,子请求不允许类似 @foo 命名 location。请使用标准 location,并设置 internal 指令,仅服务内部请求。
有以下参数:
method, body, args, ctx, vars, copy_all_vars, share_all_vars, always_forward_body。

location /product {
    internal;
    echo "商品请求";
}

location /order {
    content_by_lua_block {
        ngx.req.read_body()
        local args, err = ngx.req.get_post_args(100)
        -- 返回 res.status, res.header, res.body, res.truncated
        local res = ngx.location.capture("/product", {
            method = ngx.HTTP_GET,
            args = {a = args.a, b = args.b}
        })
        ngx.say(res.status)
        ngx.say(res.body)
    }
}

2)使用ngx.location.capture_multi

local res1, res2 = ngx.location.capture_multi({
    {"/sum", {args={a=3, b=4}}},
    {"/sub", {args={a=3, b=4}}}
})
ngx.say(res1.status, res1.body)
ngx.say(res2.status, res2.body)


res1, res2, res3 = ngx.location.capture_multi{
    { "/foo", { args = "a=3&b=4" } },
    { "/bar" },
    { "/baz", { method = ngx.HTTP_POST, body = "hello" } },
}

if res1.status == ngx.HTTP_OK then
end

if res2.body == "BLAH" then
end


local reqs = {}
table.insert(reqs, { "/mysql" })
table.insert(reqs, { "/postgres" })
table.insert(reqs, { "/redis" })
table.insert(reqs, { "/memcached" })
local resps = { ngx.location.capture_multi(reqs) }
for i, resp in ipairs(resps) do
    -- process the response table "resp"
end

1)安装lua-resty-http
opm get agentzh/lua-resty-http

2)编辑nginx.conf,在http块增加以下配置。
resolver 114.114.114.114 8.8.8.8;
lua_ssl_verify_depth 2;
lua_ssl_trusted_certificate '/etc/ssl/certs/ca-certificates.crt';

备注:如果/etc/ssl/certs/ca-certificates.crt不存在,则安装ca-certificates(例:apt-get install ca-certificates)。

3)代码示例

local http = require "resty.http"
local json = require "cjson"

local httpc = http:new()
local res, err = httpc:request_uri("http://127.0.0.1:80/", {
    method = "POST/GET",
    query = "a=1&b=2",
    body = "c=3&d=4",
    path = "/",
    headers = {
        ["Content-Type"] = "application/json",
        -- ["Content-Type"] = "application/x-www-form-urlencoded",
        ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
    },
    ssl_verify = false,
})

if err ~= nil then
    ngx.log(ngx.ERR, "http request err:", err)
    return ngx.exit(0)
end

if 200 ~= res.status then
    ngx.exit(res.status)
end

local jsondata = json.decode(res.body)["data"]

httpc:close()
-- httpc:set_keepalive()

1)生成SSH密钥对

ssh-keygen -t rsa

2)将公钥添加到服务器的.ssh/authorized_keys文件中

3)修改SSH配置文件

编辑/etc/ssh/sshd_config文件,找到PasswordAuthentication yes这一行,并将其修改为PasswordAuthentication no,以禁用密码登录。

4)重启SSH服务

systemctl restart sshd

1)High disk watermark exceeded even when there is not much data in my index

# 解决方法一
curl -XPUT "http://localhost:9200/_cluster/settings" \
 -H 'Content-Type: application/json' -d'
{
  "persistent": {
    "cluster": {
      "routing": {
        "allocation.disk.threshold_enabled": false
      }
    }
  }
}'
 
# 解决方法二
curl -X PUT "localhost:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{
  "transient": {
    "cluster.routing.allocation.disk.watermark.low": "2gb",
    "cluster.routing.allocation.disk.watermark.high": "1gb",
    "cluster.routing.allocation.disk.watermark.flood_stage": "500mb",
    "cluster.info.update.interval": "1m"
  }
}

yum update -y
yum install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 \
    lrzsz lsof net-tools bind-utils iputils traceroute telnet curl wget vim \
    gzip tar zip unzip git htop perf gcc gcc-c++ openssl openssl-devel patch tree \
    tcpdump iftop iotop sysstat nethogs

修改/etc/resolv.conf

chattr -i /etc/resolv.conf
sed -i '1i nameserver 8.8.8.8' /etc/resolv.conf
chattr +i /etc/resolv.conf

修改/etc/security/limits.conf

cat >>/etc/security/limits.conf<<EOF

root soft nofile 100001
root hard nofile 100002
* soft nofile 100001
* hard nofile 100002
* soft memlock unlimited
* hard memlock unlimited
EOF

修改/etc/sysctl.conf

sysctl -p