转载自:Proxmox VE 的 LXC 容器安装 NTP 时间同步 — 董仁文的博客 (dongrenwen.github.io)

CentOS 系统修改 NTP 时间同步

修改时区

1
2
# 修改时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

安装客户端

1
2
# 安装 ntp 客户端
yum install ntp ntpdate -y

修改配置文件 /etc/ntp.conf 中和 NTP 服务相关部分

1
2
3
4
5
6
7
8
9
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

# Use Aliyun's ntp server as a fallback.
server ntp.aliyun.com

将 NTP 服务设置成为开机自启

1
2
# 将 ntp 服务设置成为开机自启
systemctl enable ntpd
阅读全文 »

Json.Marshal对特殊字符转义

背景: 使用golang做网关进行转发请求时候,发现转发的java响应中的json中的url参数&被进行转义

  • 转发前原始数据: {"url":"http://abcd.com?param=1&a=2"}
  • 转发后: {"url":"http://abcd.com?param=1\u0026a=2"}

查看源码

1
2
3
4
5
6
7
8
// String values encode as JSON strings coerced to valid UTF-8,  
// replacing invalid bytes with the Unicode replacement rune.
// So that the JSON will be safe to embed inside HTML <script> tags,
// the string is encoded using HTMLEscape,
// which replaces "<", ">", "&", U+2028, and U+2029 are escaped
// to "\u003c","\u003e", "\u0026", "\u2028", and "\u2029".
// This replacement can be disabled when using an Encoder,
// by calling SetEscapeHTML(false).

含义说:

1
2
3
4
5
字符串值编码为强制转换为有效UTF-8的JSON字符串,用Unicode替换符文替换无效字节。
这样就可以安全地将JSON嵌入HTML <script>标记中,并使用HTMLEscape对字符串进行编码,
HTMLEscape会将“ <”,““>”,“&”,U + 2028和U + 2029
替换为“ \” u003c”,“ \ u003e”,“ \ u0026”,“ \ u2028”和“ \ u2029”。
使用编码器时可以禁用此替换,通过调用SetEscapeHTML(false)。

测试

测试代码:

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

import (
"bytes"
"encoding/json"
"fmt"
)

func main() {
text := "http://abcd.com?param=1&a=2"
marshal, _ := json.Marshal(text)
fmt.Println(string(marshal))

bf := bytes.NewBuffer([]byte{})
jsonEncoder := json.NewEncoder(bf)
jsonEncoder.SetEscapeHTML(false)
jsonEncoder.Encode(text)
fmt.Println(bf.String())
}
阅读全文 »

设置

  1. 生成ssh密钥: ssh-keygen -t rsa
  2. 拷贝公钥私钥: ssh-copy-id -i ./生成的.pub username@host
  3. 配置用户.ssh目录下config
1
2
3
4
Host 192.168.0.18
HostName 192.168.0.18
User baiyz
IdentityFile ~/.ssh/llm_server
阅读全文 »