原因: 主机商因安全问题禁用了UDP 123端口,让NTP时间同步服务不可用,没办法的情况下找到了htpdate这个基于HTTP的时间同步工具,htpdate的精度为 -+0.5 秒,对于时间要求不是非常高的场景可以使用。

ubuntu 22安装
一、安装 htpdate

sudo apt update
sudo apt install htpdate
# 配置时间同步域名
sudo sed -i 's/^HTP_SERVERS=.*/HTP_SERVERS="www.baidu.com www.qq.com www.jd.com www.tencent.com www.aliyun.com www.bing.com"/' /etc/default/htpdate

sudo systemctl restart htpdate
sudo systemctl status htpdate
sudo systemctl enable htpdate

二、禁用 systemd-timesyncd 服务

sudo timedatectl set-ntp false
sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd

写好的程序放到linux服务器,隔几天上服务器一看,内存直接爆了。

本地buid程序测试,内存也是一下子升到几个G,开发的时候一直用的是goland,没发现这个问题。

1、把time.After改成time.NewTimer,发现没效果

2、 用 net/http/pprof 分析,刚开始觉得是太多http请求引起的 http client 内存泄漏,网上研究了好多资料,对 http client 参数也是做各种修改,搞了一天,无果。

3、 golang项目中的issues搜索 "http client memory leak",无意间看到 https://github.com/golang/go/issues/63276, 把 go build -race 中的 -race 删除,内存不飙升了,问题解决。

4、再去搜索 "go build -race" 就看到 https://go.dev/doc/articles/race_detector 这篇文章,最后面有说生产环境使用 go build -race 构建可能会让内存无限增长。

1、 通过 "cat /proc/sys/fs/nr_open" 查看系统限制,ulimit设置不能超过这个限制,通过"ulimit -n"查看当前限制
cat /proc/sys/fs/nr_open
ulimit -n
2、 通过 "ulimit -n 1000000"修改为100万
ulimit -n 1000000
3、 永久生效
echo 'root soft nofile 1000000' >> /etc/security/limits.conf
echo 'root hard nofile 1000000' >> /etc/security/limits.conf
echo '* soft nofile 1000000' >> /etc/security/limits.conf
echo '* hard nofile 1000000' >> /etc/security/limits.conf

第 1 步:yarn镜像配置

yarn config set registry https://registry.npmmirror.com -g
yarn config set disturl https://npmmirror.com/dist -g
yarn config set electron_mirror https://npmmirror.com/mirrors/electron/ -g
yarn config set sass_binary_site https://npmmirror.com/mirrors/node-sass/ -g
yarn config set phantomjs_cdnurl https://npmmirror.com/mirrors/phantomjs/ -g
yarn config set chromedriver_cdnurl https://cdn.npmmirror.com/dist/chromedriver -g
yarn config set operadriver_cdnurl https://cdn.npmmirror.com/dist/operadriver -g
yarn config set fse_binary_host_mirror https://npmmirror.com/mirrors/fsevents -g

第 2 步:创建新应用程序

yarn create electron-app projectname --template=vite

- 阅读剩余部分 -

使用 update-alternatives 进行版本切换

一、 创建 phpv.sh 文件

#!/bin/bash

VERSION=$1

if [ -z "$VERSION" ];then
  echo "请输入要切换的PHP版本"
  echo "可用版本列表: $(dir /etc/php)"
  echo "当前版本信息:"
  php -v
  exit
fi

sudo update-alternatives --set php /usr/bin/php${VERSION}

php -v

二、 添加执行权限

chmod+x phpv.sh

三、 创建别名, .profile 增加如下代码

alias phpv='/home/用户目录/script/phpv.sh'