海运的博客

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

小内存vps使用luks/cryptsetup全盘加密遇到的问题

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

有一512M内存vps,在使用pressed安装ubuntu luks加密时一直卡在分区那里,查看日志由于占用内存较高cryptsetup被kill,然后在本机制作一个ubuntu系统img模板dd到目标vps,启动后输入加密密码时提示密码错误,查看日志同样cryptsetup被kill,查找资料原来luks默认为版本2,PBKDF为argon2i,而argon2i比较占用内存。
解决方法:在preseed分区之前修改分区脚本添加参数使用pbkdf2或luks1:

d-i partman/early_command string sed -i 's/luksFormat/--pbkdf pbkdf2 luksFormat/' /lib/partman/lib/crypto-base.sh;
#d-i partman/early_command string sed -i 's/luksFormat/--type luks1 luksFormat/' /lib/partman/lib/crypto-base.sh;

也可指定argon2i最大使用内存,单位KB:

--pbkdf-memory 25600

对已存在的加密分区可转换:

cryptsetup -v luksDump /dev/sda5
cryptsetup -v --pbkdf pbkdf2 luksConvertKey /dev/sda5
cryptsetup -v convert /dev/sda5 --type luks1

20210208更新:
当前ubuntu20.04.2已添加以下参数可直接选择使用pbkdf2或luks1:

d-i partman-crypto/luksformat_options string --type luks1
d-i partman-crypto/luksformat_options string --pbkdf-memory 65535
d-i partman-crypto/luksformat_options string --pbkdf pbkdf2

也可在安装前自动判断内存小于小于多少设置使用pbkdf2:

d-i partman/early_command string if [ `free|grep Mem|tr -s ' ' ' '|cut -d ' ' -f 2` -lt 819200 ];\
    then debconf-set partman-crypto/luksformat_options "--pbkdf pbkdf2";fi

其实小内存主要是安装时luks默认占用内存过高导致安装失败,而dd的系统原虚拟机内存高,luks在设置密码时根据系统内存自动设置--pbkdf-memory,导致pbkdf-memory参数比vps内存都相差不大,所以dd的系统也不能正常启动,vps在安装前通过--pbkdf-memory设置小内存,后续再添加密码使用自动设置的内存参数就可以了。
参考:
https://lists.debian.org/debian-boot/2020/10/msg00000.html
https://gitlab.com/cryptsetup/cryptsetup/-/issues/372

dnsmasq dhcp ipxe网络安装系统

发布时间:December 2, 2020 // 分类: // 1 Comment

dnsmasq配置dhcp和tftp:

#dhcp-vendorclass=bios,PXEClient:Arch:00000
dhcp-match=set:bios,option:client-arch,0
dhcp-match=set:ipxe,175
dhcp-boot=tag:!ipxe,tag:bios,undionly.kpxe
dhcp-boot=tag:!ipxe,tag:!bios,ipxe.efi
dhcp-boot=tag:ipxe,boot.ipxe
#dhcp-boot=tag:ipxe,http://boot.netboot.xyz
enable-tftp
tftp-root=/srv/tftp/

下载pxe启动要加载的ipxe启动文件,也可自己编译ipxe开启相应的功能。

cd /srv/tftp/
wget https://boot.ipxe.org/undionly.kpxe
wget https://boot.ipxe.org/ipxe.efi

ipxe启动脚本boot.ipxe,更多见使用preseed和kickstart自动安装ubuntu和centos系统

#!ipxe
:start
menu PXE Boot Options
item shell iPXE shell
item ubuntu Ubuntu installation
item exit  Exit to BIOS
choose --default ubuntu --timeout 10000 option && goto ${option}
:shell
shell
:ubuntu
#chain --autofree http://boot.netboot.xyz
set mirror http://mirrors.aliyun.com/
set release focal
set arch amd64
set base-url ${mirror}/ubuntu/dists/${release}/main/installer-${arch}/current/legacy-images/netboot/ubuntu-installer/${arch}
kernel ${base-url}/linux auto=true url=https://www.haiyun.me/ubuntu.cfg keymap=us domain= hostname=ubuntu-server interface=auto netcfg/do_not_use_netplan=true
initrd ${base-url}/initrd.gz
boot
:exit
exit

使用其它机器上tftp服务器,地址:192.168.1.6

#dhcp-vendorclass=bios,PXEClient:Arch:00000
dhcp-match=set:bios,option:client-arch,0
dhcp-match=set:ipxe,175
dhcp-boot=tag:!ipxe,tag:bios,undionly.kpxe,,192.168.1.6
dhcp-boot=tag:!ipxe,tag:!bios,ipxe.efi,,192.168.1.6
dhcp-boot=tag:ipxe,boot.ipxe,,192.168.1.6

ubuntu安装tftp服务器:

apt install tftpd-hpa

参考:
https://wiki.archlinux.org/index.php/dnsmasq#PXE_server
https://dev.to/arachan/ipxe-chainloading-to-use-dnsmasq-and-proxydhcp-4he
https://yangfeiffei.github.io/public/2019/08/12/net-install-centos7-with-ipxe.html

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • 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进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...