海运的博客

linux/windows下检测mtu大小是否合适

发布时间:December 23, 2020 // 分类: // No Comments

指定ping数据大小,实际测试mtu为数据大小+IP头部20字节+icmp头部8字节,强制不分片如果大于实际mtu则返回错误。
linux下,pppoe mtu为1492,发送mtu 1500则返回错误并显示实际mtu:

 ping -s 1472 -M do 114.114.114.114
PING 114.114.114.114 (114.114.114.114) 1472(1500) bytes of data.
From 192.168.168.1 icmp_seq=1 Frag needed and DF set (mtu = 1492)
ping: local error: message too long, mtu=1492

windows下返回错误:

>ping -l 1472 -f 114.114.114.114

正在 Ping 114.114.114.114 具有 1472 字节的数据:
来自 192.168.1.1 的回复: 需要拆分数据包但是设置 DF。
需要拆分数据包但是设置 DF。

typecho配置nginx使用fastcgi cache缓存加速

发布时间:December 16, 2020 // 分类:Nginx // No Comments

安装nginx依赖扩展,当typecho更新时调用http-cache-purge删除缓存,当命中缓存时调用lua清除set-cookie head,防止缓存的设置cookie header发送给所有人。

apt install libnginx-mod-http-cache-purge libnginx-mod-http-lua

http内添加:

    fastcgi_cache_path /dev/shm/fastcgi_cache_dir levels=1:2 keys_zone=phpcache:100m inactive=30d max_size=200M;
    fastcgi_temp_path /dev/shm/fastcgi_cache_dir/temp;
    fastcgi_cache_use_stale error timeout invalid_header http_500;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

修改server段:

  set $skip_cache 0;
  #跳过缓存,post请求
  if ($request_method = POST) {
    set $skip_cache 1;
  }
  #url包含参数
  if ($query_string != "") {
    set $skip_cache 1;
  }
  #指定url
  if ($request_uri ~* ^(/admin/|/action/|/search/|/feed/)) {
    set $skip_cache 1;
  }
  #登录用户
  if ($http_cookie ~* "typecho_authCode") {
    set $skip_cache 1;
  }
  #$uri经过重写后会改变,通过lua提前复制到$permalink
  set_by_lua_block $permalink {
    return ngx.var.uri
  }
  location ~ .*\.php$
  {
    try_files $uri =404;
    astcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi.conf;

    fastcgi_cache_key $scheme$request_method$host$permalink;
    add_header Cache-State $upstream_cache_status;
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    fastcgi_cache phpcache;
    fastcgi_cache_valid 200 301 302 30d;

    log_by_lua_file "/etc/nginx/ngx_lua_reqstatus/hook.lua";
    header_filter_by_lua_block {
      --if ngx.status == ngx.HTTP_OK then
        --ngx.header['Cache-State'] = ngx.var.upstream_cache_status
      --end
      if ngx.var.upstream_cache_status == "HIT" then
        ngx.header['Set-Cookie'] = nil
      end
    }
  }

  location ~ /xxx/_clean_cache(/.*) {
      fastcgi_cache_purge phpcache "$scheme$request_method$host$1";
  }

typecho清除缓存插件:
https://github.com/typecho-fans/plugins/tree/master/Ncache
typecho默认在用户评论后会在cookie内设置用户名和邮箱信息,并在服务端读取cookie在html内写入相关信息,这样用户信息被缓存所有人都可以看到,可参考下面方法修改模板用js读取cookie内用户信息。
https://cuojue.org/read/typecho_comments_author_javascript.html

ubuntu 20.04下nginx不支持tls1.0/tls1.1解决

发布时间:December 16, 2020 // 分类:Nginx // No Comments

在ubuntu 20.04下配置nginx ssl时怎么不支持tls1.0/1.1,确认配置文件无误怀疑是openssl的问题,原来是ubuntu 20.04/openssl 1.1.1默认禁用了不安全的tls协议,可以修改openssl配置文件开启。
patch:

--- openssl.cnf 2020-12-26 10:54:59.000000000 +0800
+++ /etc/ssl/openssl.cnf        2020-12-26 11:28:20.406439168 +0800
@@ -11,6 +11,8 @@
 # defined.
 HOME                   = .
 
+openssl_conf = default_conf
+
 # Extra OBJECT IDENTIFIER info:
 #oid_file              = $ENV::HOME/.oid
 oid_section            = new_oids
@@ -348,3 +350,13 @@
                                # (optional, default: no)
 ess_cert_id_alg                = sha1  # algorithm to compute certificate
                                # identifier (optional, default: sha1)
+
+[default_conf]
+ssl_conf = ssl_sect
+
+[ssl_sect]
+system_default = system_default_sect
+
+[system_default_sect]
+MinProtocol = TLSv1
+CipherString = DEFAULT:@SECLEVEL=1

或直接修改配置文件,openssl.cnf首部添加:

sed -i '1i openssl_conf = default_conf' /etc/ssl/openssl.cnf

尾部添加:

cat >> /etc/ssl/openssl.cnf << EOF
[default_conf]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT:@SECLEVEL=1
EOF

使用openssl测试是否支持tls1.0和1.1:

openssl s_client -connect www.haiyun.me:443 -tls1_1
openssl s_client -connect www.haiyun.me:443 -tls1

参考:
https://askubuntu.com/questions/1233186/ubuntu-20-04-how-to-set-lower-ssl-security-level

sftpgo使用及占用内存较大解决

发布时间:December 9, 2020 // 分类: // No Comments

编译windows下版本,数据库使用bolt,禁用sql。

git clone https://github.com/drakkan/sftpgo.git
cd sftpgo
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags nogcs,nos3,noazblob,nomysql,nosqlite,nopgsql,noportable,novaultkms,noawskms,nogcpkms -ldflags "-s -w"
go build -tags nogcs,nos3,noazblob,nomysql,nobolt,nopgsql,noportable,novaultkms,noawskms,nogcpkms -trimpath -ldflags "-s -w -X github.com/drakkan/sftpgo/v2/version.commit=`git describe --always --dirty` -X github.com/drakkan/sftpgo/v2/version.date=`date -Is`" -o sftpgo

使用vbs脚本启动隐藏cmd窗口并重定向日志到nul:

set ws=createobject("wscript.shell")
ws.CurrentDirectory="d:\Program Files\sftpgo\"
ws.run """d:\Program Files\sftpgo\sftpgo.exe"" serve -v=0 -l """" 2> nul",0
wscript.quit

sftpgo默认认证用户密码使用argon2id,当连接数较多时会占用大量内存,通过web新建用户时密码可直接输入sha512crypt密码密文,后续认证时则使用sha512crypt认证,大幅减小内存占用,密码生成:

echo 123456|openssl passwd -6 -in -

sftpgo默认为根目录和子目录添加.和..,添加后会有一些莫名其妙的问题,不添加客户端也可处理与上级目录的关系:

--- ftpd/handler.go     2022-03-11 15:24:52.147555506 +0800
+++ ftpd/handler.go.bak 2022-03-11 15:17:43.300412122 +0800
@@ -14,7 +14,7 @@
        "github.com/drakkan/sftpgo/v2/common"
        "github.com/drakkan/sftpgo/v2/dataprovider"
        "github.com/drakkan/sftpgo/v2/logger"
-       //"github.com/drakkan/sftpgo/v2/util"
+       "github.com/drakkan/sftpgo/v2/util"
        "github.com/drakkan/sftpgo/v2/vfs"
 )
 
@@ -288,10 +288,10 @@
        if err != nil {
                return files, err
        }
-       //if name != "/" {
-       //      files = util.PrependFileInfo(files, vfs.NewFileInfo("..", true, 0, time.Now(), false))
-       //}
-       //files = util.PrependFileInfo(files, vfs.NewFileInfo(".", true, 0, time.Now(), false))
+       if name != "/" {
+               files = util.PrependFileInfo(files, vfs.NewFileInfo("..", true, 0, time.Now(), false))
+       }
+       files = util.PrependFileInfo(files, vfs.NewFileInfo(".", true, 0, time.Now(), false))
        return files, nil
 }

注意:当sftpgo以普通用户运行时db所在目录sftpgo运行用户要有写入权限,否则就算db文件可写sftpgo也提示db只读。
参考:
https://github.com/drakkan/sftpgo/blob/master/docs/account.md

使用ipset导入国家ip数据库替换geoip

发布时间:December 3, 2020 // 分类: // No Comments

使用firehol生成的各个国家ip段数据库,包含geolite2、ipip.net、ip2location,geolite2貌似不再更新。

wget https://raw.githubusercontent.com/firehol/blocklist-ipsets/master/ipip_country/ipip_country_cn.netset
echo 'create cn hash:net -exist' > ipset_cn.rule
while read line; do  if [[ $line =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} ]];then echo "add cn $line";fi;done < ipip_country_cn.netset >> ipset_cn.rule
ipset restore --file ipset_cn.rule

iptables使用:

iptables -A INPUT -m state --state NEW -p tcp --dport 80 -m set --match-set cn src -j ACCEPT

自己生成ipip各个国家ip数据库:

wget https://cdn.ipip.net/17mon/country.zip
unzip country.zip country.txt
mkdir ip
for cy in `awk '{print $2}' country.txt|sort -u`;do awk '{if ($2 == "'$cy'") print $1}' country.txt > ip/$cy.txt;done

生成geoliste2的中国ip数据:

echo 'create cn6 hash:net family inet6 -exist' > ipset_cn6.rule
awk -F',' '{if ($2 == 1814991) print ("add cn6",$1)}' GeoLite2-Country-Blocks-IPv6.csv >> ipset_cn6.rule
echo 'create cn hash:net -exist' > ipset_cn4.rule
awk -F',' '{if ($2 == 1814991) print ("add cn4",$1)}' GeoLite2-Country-Blocks-IPv4.csv >> ipset_cn4.rule

这个网址可在线生成:https://www.ip2location.com/free/visitor-blocker
也可使用此工具自己生成MaxMind geolite2和dbip国家ip数据:
https://github.com/chr0mag/geoipsets

分类
最新文章
最近回复
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
归档