胖牛头 发布的文章

VB.NET

Private ReadOnly PMod As New Process()

PMod.StartInfo.FileName = "x.exe"
PMod.StartInfo.UseShellExecute = False
PMod.StartInfo.RedirectStandardOutput = True
PMod.StartInfo.CreateNoWindow = True

PMod.Start()
If PMod.WaitForExit(60000) Then
    Dim message = PMod.StandardOutput.ReadToEnd().Split(New Char() {vbCrLf}, StringSplitOptions.RemoveEmptyEntries).ToList()
    If message.Count > 0 Then
        Debur.Print(String.Join("-", message))
    End If    
End If
VB.Net

CSharp

using ImageProcessor;
using System;
using System.Drawing;

internal class WebpClass
{
    public static (bool successful, Image image, string error) LoadPicture(string fileName)
    {
        try
        {
            using (ImageFactory pif = new ImageFactory())
            {
                var result = pif.Load(fileName);
                if (result.Image != null)
                {
                    return (true, new Bitmap(pif.Load(fileName).Image), null);
                }
                else
                {
                    return (false, null, "读取失败!");
                }
            }
        }
        catch (Exception ex)
        {
            return (false, null, ex.Message);
        }
    }

    public static (bool successful, string error) SaveWebp(string fileName, Image img, int quality = 100)
    {
        try
        {
            using (ImageFactory pif = new ImageFactory())
            {
                pif.Load(img);
                pif.PreserveExifData = true;
                pif.Format(new ImageProcessor.Plugins.WebP.Imaging.Formats.WebPFormat() { Quality = quality <= 50 ? 50 : quality });
                pif.Save(fileName);

                return (true, null);
            }
        }
        catch (Exception ex)
        {

            return (false, ex.Message);
        }
    }
}
C#

VB.NET

Imports ImageProcessor

Public Class webp

    ''' <summary>
    ''' 将输入的图像保存为webp图像。
    ''' </summary>
    ''' <param name="fn"></param>
    ''' <param name="img"></param>
    ''' <param name="quality"></param>
    ''' <returns></returns>
    Shared Function SaveWebp(fn As String, img As Image, Optional quality As Integer = 100) As Boolean
        Try
            Using ipf As New ImageFactory

                ipf.Load(img)
                ipf.PreserveExifData = False
                ipf.Format(New Plugins.WebP.Imaging.Formats.WebPFormat() With {.Quality = If(quality <= 50, 50, quality)})
                ipf.Save(fn)

                Return True

            End Using
        Catch ex As Exception
            'MessageBox.Show($"保存webp失败!{ex.Message}", "webp", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return False
        End Try
    End Function

    ''' <summary>
    ''' 读取指定文件名的文件,返回图像。
    ''' </summary>
    ''' <param name="fn"></param>
    ''' <returns></returns>
    Shared Function Load(fn As String) As Image
        Try
            Using pif As New ImageFactory
                Return New Bitmap(pif.Load(fn).Image)
            End Using
        Catch ex As Exception
            'MessageBox.Show($"保存webp失败!{ex.Message}", "webp", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return Nothing
        End Try
    End Function

End Class
VB.Net

更新系统

apt update && apt upgrade -y
Bash

安装防火墙

#新安装的debian默认是没有安装ufw的
apt install ufw

#设置默认规则
ufw default deny incoming
ufw default allow outgoing

#允许自定义端口ssh
ufw allow 60885

#允许http和https
ufw allow http
ufw allow https

#启用防火墙,一定要确认已经加入了ssh端口,要不然就惨了
ufw enable
Bash

系统设置

自动更新

# 检查系统是否已安装(没有安装则无信息返回)
dpkg -l | grep unattended-upgrades

# 从包管理器获取安装
apt install unattended-upgrades

# 启动配置向导
dpkg-reconfigure -plow unattended-upgrades

# 系统更新
vim /etc/apt/apt.conf.d/50unattended-upgrades

# 软件包更新
vim /etc/apt/apt.conf.d/20auto-upgrades
Bash

加入ll命令

vim ~/.bashrc
source ~/.bashrc
Bash

设置本地时间

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Bash

修改SSH配置文件

vim /etc/ssh/sshd_config

Port 60885 #ssh自定义端口
LoginGraceTime 2m #登录认证的时间
PermitRootLogin no #不允许root用户登录
PubkeyAuthentication yes #使用公钥认证
PermitEmptyPasswords no #不允许空密码用户登录
PasswordAuthentication no #不允许使用密码方式登录
Bash

建立公钥文件

进入用户主目录

cd ~
mkdir .ssh
cd .ssh
vim authorized_keys
Bash

vim进入粘贴模式

:set paste
Bash

设置密钥文件相关权限

chmod 600 authorized_keys
chmod 700 .ssh
Bash

BBR加速

原版BBR

新版本
# 发现Debian10/11已经自带了BBR加速,但是默认没有启用,需要自行开启。

# 修改系统变量
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf

# 保存生效
sysctl -p

# 查看内核是否已开启BBR
sysctl net.ipv4.tcp_available_congestion_control

# 显示如下即正常
net.ipv4.tcp_available_congestion_control = reno cubic bbr

# 查看BBR是否启动
lsmod | grep bbr

# 显示返回值即启动成功
tcp_bbr                20480
Bash
旧版本
# 安装
wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh && chmod +x bbr.sh && ./bbr.sh

# 校验
sysctl net.ipv4.tcp_congestion_control

# 显示如下即正常
net.ipv4.tcp_congestion_control = bbr
Bash

安装curl

# 新安装的debian9,没有curl命令,自行安装
apt install curl
Bash

打开crontab日志

# debian的crontab日志是默认关闭的,可以从日志记录配置文件中打开
vim /etc/rsyslog.conf
# 取消下面这行前面的注释
cron.* /var/log/cron.log
# 再重启一下日志服务就可以了
/etc/init.d/rsyslog restart
Bash