Avatar

Organizations

  • 1、准备环境

    建议使用纯linux系统进行编译,如 Ubuntu 20.04 LTS,这样环境比较简单,兼容问题也少。

    用WSL环境编译,可参考

    为提高编译的成功率,采用国内大神Lean的版本。

    官方版本因编译过程中,下载、兼容等等太多问题,建议不要使用。

    sudo apt-get update
    sudo apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync
    

    2、下载代码

    国内用户请准备好梯子

    git clone https://github.com/coolsnowwolf/lede
    cd lede
    ./scripts/feeds update -a
    ./scripts/feeds install -a
    

    3、配置组件

    make menuconfig
    

    Hyper-V平台配置,可参考

    make OpenWRT Created Tue, 08 Feb 2022 10:05:20 +0800
  • 1. 升级系统软件包

    $ apt-get update
    $ apt-get dist-upgrade
    

    2. 安装 ifupdown2

    使用 ifupdown2 网络管理软件包,还可以实时重新加载网络配置,而无需重新启动。

    $ apt install ifupdown2
    

    3. 配置物理网卡

    使用 PVE 的 WEB 管理界面,设置物理网卡的配置。

    注意:一定要分配一个静态的IP地址,否则无法正常登录 PVE

    节点 > 系统 > 网络:

    • address:192.168.10.66/24
    • gateway:192.168.10.1

    保存后应用配置

    4. 配置虚拟网卡

    4.1 修改虚拟网卡配置

    使用 PVE 提供管理界面进行配置。 删除 vmbr0 设备的所有配置内容。

    编辑 /etc/network/interfaces

    $ nano /etc/network/interfaces
    

    加入

    source /etc/network/interfaces.d/*
    
    # network interface settings; autogenerated
    # Please do NOT modify this file directly, unless you know what
    # you're doing.
    #
    # If you want to manage parts of the network configuration manually,
    # please utilize the 'source' or 'source-directory' directives to do
    # so.
    # PVE will preserve these directives, but will NOT read its network
    # configuration from sourced files, so do not attempt to move any of
    # the PVE managed interfaces into external files!
    
    source /etc/network/interfaces.d/*
    
    auto lo
    iface lo inet loopback
    
    auto enp1s0
    iface enp1s0 inet static
            address 192.168.10.66/24
            gateway 192.168.10.1
    
    iface vmbr0 inet manual
            bridge-ports none
            bridge-stp off
            brideg-fd
    

    4.2 新建虚拟网卡配置

    创建新的虚拟网卡配置

    NAT proxmoxve Created Mon, 07 Feb 2022 14:07:32 +0800
  • 本文记录OpenWrt设置透明代理的步骤及原理。

    1. 系统环境

    • 硬件环境:Windows 10 Hyper-V虚拟机,单核处理器,256M内存
    • 固件版本:OpenWrt 19.07.6 r11278-8055e38794 / LuCI openwrt-19.07 branch git-21.101.59933-c56d9f2
    • shadowsocks-libev:3.3.5
    • luci-app-shadowsocks:2.0.2
    • v2ray-plugin:4.37.3-20210413
    • ChinaDNS:1.3.3
    • luci-app-chinadns:1.6.2
    • https-dns-proxy:2021-01-17-5
    • luci-app-https-dns-proxy:git-21.062.76689-a607f9c-1
    • luci-i18n-https-dns-proxy-zh-cn:git-21.062.76689-a607f9c-1

    2. 运行流程

    透明代理的运行原理主要由DNS访问流程IP访问流程两部分组成组成

    2.1 DNS访问流程

    flowchart LR
        lh((localhost));
        dm(Dnsmasq);
        cd(ChinaDNS);
        hdp(https-dns-proxy);
        ss(Shadowsocks);
        fd(国外DNS);
        dd(国内DNS);
    
        lh -- 1 udp:53 --> dm;
        dm -- 2 udp:5555 --> cd;
        cd -- 3.1 udp:5353--> hdp;
        cd -- 3.2 udp --> dd;
        hdp -- 4 tcp --> ss;
        ss -- 5 tcp --> fd;
    
        fd -. 6 .-> ss;
        ss -. 7 .-> hdp;
        hdp -. 8.1 .-> cd;
        dd -. 8.2 .-> cd;
        cd -. 9 缓存 .-> dm;
        dm -. 10 IP地址 .-> lh;
    

    2.2 IP访问流程

    flowchart LR
        fs(国外服务器);
        ds(国内服务器);
        lh((localhost));
        route{chinadns_chnroute.txt};
        ss(Shadowsocks);
    
        lh -- 1 --> route;
        route -- 2.1 国内IP --> ds;
        route -- 2.2 国外IP --> ss;
        ss -- 3 加密访问 --> fs;
    
        fs -. 4 返回加密数据 .-> ss;
        ds -. 5.1 返回数据 .-> lh;
        ss -. 5.2 返回解密数据 .-> lh;
    

    3. 配置

    3.1 Shadowsocks-libev + v2ray-plugin

    • 服务器管理-编辑服务器-插件参数:一定要加上"loglevel=none",如果不加v2ray-plugin插件几分钟就会被系统杀死
    • 访问控制-被忽略IP列表:/etc/chinadns_chnroute.txt

    3.2 https-dns-proxy

    由于使用了v2ray-plugin 插件,导致Shadowsocks不再支持UDP包,所以使用TCP的方式查询DNS

    v2ray proxy ShadowSocks OpenWRT Created Mon, 07 Feb 2022 13:37:19 +0800
  • 1. 使用自定义域名访问WEB管理界面

    • 网络-DHCP/DNS-常规设置-DNS转发:/openwrt.lan/192.168.xxx.xxx
    • 网络-DHCP/DNS-常规设置-重绑定保护:不勾选
    • /etc/config/uhttpd-option redirect_https:‘1’ 不强制跳转https
    DNS OpenWRT Created Mon, 07 Feb 2022 13:17:39 +0800
  • 1. 安装软件包

    # opkg install kmod-nf-nathelper-extra
    # opkg install kmod-nf-ipvs-ftp
    

    2. 添加配置

    # nano /etc/sysctl.d/11-nf-conntrack.conf
    

    增加"net.netfilter.nf_conntrack_helper=1"

    在使用FTP的主动模式时,要注意关闭网关上的ALG功能(如Windows ALG服务),同时使用可能引起失败

    参考文档

    FTP ALG OpenWRT Created Mon, 07 Feb 2022 10:08:02 +0800
  • 1. 复制

    2. 导入

    2.1 使用 LOAD DATA

    3. 删除

    mysql Created Tue, 18 Jan 2022 14:50:28 +0800
  • urllib.parse.urlencode(query, doseq=False, safe=’’, encoding=None, errors=None, quote_via=quote_plus) urllib.parse.urlencode 将对象或两元素序列转换为百分比编码的ASCII文本字符串,字符串是由’&‘字符分隔的一系列 key=value 对,其中 key 和 value 都使用 quote_via 函数引用。

    GET 请求

    import urllib
    params = urllib.parse.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
    url = "http://www.musi-cal.com/cgi-bin/query?%s" % params
    with urllib.request.urlopen(url) as f:
        print(f.read().decode('utf-8'))
    

    POST 请求

    import urllib.request
    import urllib.parse
    data = urllib.parse.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
    data = data.encode('ascii')
    with urllib.request.urlopen("http://requestb.in/xrbl82xr", data) as f:
        print(f.read().decode('utf-8'))
    

    如果结果字符串要用作具有 urlopen() 函数的POST操作的 data,则它应该被编码为字节,否则将导致 TypeError。

    默认情况下 urlencode 函数使用 quote_plus() 函数进行编码,也可以选用 quote() 函数进行编码,两者最大的不同在于对特定字符的处理。

    urllib.parse.quote_plus(string, safe=’’, encoding=None, errors=None) 默认情况下使用 quote_plus() 函数,它将空格被编码为 ‘+’ 字符,而“/”字符被编码为 %2F,它遵循GET请求(application/x-www-form-urlencoded)的标准。 urllib.parse.quote(string, safe=’/’, encoding=None, errors=None) 可以作为备用的函数是 quote(),它将空格编码为 %20,字母,数字和 ‘_.-‘字符不被编码,而“/”字符被默认为安全字符不被编码。

    url编码 Python Created Mon, 17 Jan 2022 15:24:58 +0800
  • 基于Centos 7

    查看设备信息

    # 简单接口状态
    $ nmcli dev status
    # 详细的接口信息
    $ nmcli dev show
    # 接口的详细信息
    $ nmcli dev show <interface-name>
    

    查看连接(connection)的信息

    # 简单信息
    $ nmcli conn show
    # 详细的连接信息
    $ nmcli conn show
    # 某个连接的详细信息
    $ nmcli conn show <conn-name>
    

    创建连接

    nmcli conn add type <ethernet> con-name <conn-name> ifname <dev-name> ip4 <192.168.100.100/24> [gw4 <192.168.100.1>]
    

    修改配置

    静态IP改动态IP

    nmcli conn mod <conn-name> /
        ipv4.method auto /
        ipv4.address "" /
        ipv4.gateway "" /
        ipv4.dns ""
    

    修改DNS

    $ nmcli conn mod <conn-name> ipv4.dns "1.2.4.8"
    

    设置自动连接

    # 查询和显示所有网络连接的自动连接属性的当前值
    $ nmcli -f name,autoconnect connection
    # 更改网络连接的属性值
    $ nmcli conn mod <conn-name> connection.autoconnect yes
    

    配置生效

    nmcli conn up <conn-name>
    

    激活连接

    $ nmcli conn up <conn-name>
    $ nmcli conn down <conn-name>
    
    $ nmcli dev connect <dev-name>
    $ nmcli dev disconnect <dev-name>
    

    建议使用 nmcli dev disconnect interface-name 命令,而不是 nmcli con down connection-name 命令,因为连接断开可将该接口放到“手动”模式,这样做用户让 NetworkManager 启动某个连接前,或发生外部事件(比如载波变化、休眠或睡眠)前,不会启动任何自动连接。

    CLI nmcli network Linux Created Mon, 17 Jan 2022 15:17:58 +0800
  • sed [OPTION] [expression] file
    
    [OPTION]
      -n 屏蔽输出
      -i 替换模式
      -i.bak 替换前先备份文件
      -E 使用扩展正则表达式,语法更接近现代正则表达式(如 Perl、Python、JavaScript),代码更清晰易读(去掉了很多反斜杠),减少转义错误
      -e 使用表达式,可使用多个表达式
    
    [expression]
      s/regular/replace/ 替换命令
      
      0,/regular/s//replace/ 仅替换从文件开头(第 0 行)首次匹配regular成功的内容,只用GNU版本的sed
      
      /regular/replace/g 匹配整行,默认只匹配一次
      /regular/replace/d 删除行
      /regular/replace/p 打印匹配的行
    

    读取指定行

    sed -n '1,2p' file
    

    删除行

    # 删除空行
    sed -i '/^\s*$/d' merge1.log
    sed -i '/^$/d' filename.txt  # `^$` 匹配空行
    # 按行号删除
    sed -i '5d' filename.txt  # 删除第5行
    # 删除最后一行
    sed -i '$d' filename.txt  # `$` 表示最后一行
    # 删除连续行
    sed -i '10,20d' filename.txt  # 删除第10到20行
    # 删除不连续的行
    sed -i '5d;10d;15d' filename.txt  # 删除第5、10、15行
    # 删除包含特定文本的行
    sed -i '/pattern/d' filename.txt  # 删除含"pattern"的行
    # 删除不匹配的行(保留匹配行)
    sed -i '/pattern/!d' filename.txt  # `!` 表示取反
    # 删除以某文本开头/结尾的行
    sed -i '/^prefix/d' filename.txt  # 删除以"prefix"开头的行
    sed -i '/suffix$/d' filename.txt  # 删除以"suffix"结尾的行
    

    删除冗余信息

    sed -i 's/.*a2p_replyclient_log.*[infoerror].[0-9].log.gz://' merge.log \
    && sed -i 's/org.springframework.amqp.rabbit.RabbitListenerEndpointContainer.* - //' merge.log \
    && sed -i '/.*send 1 time for the url is .*/d' merge.log \
    && sed -i '/.*redis key:[0-9]*,value:.*/d' merge.log
    
    sed -i '/>>>>.* retry:2/d' 2021.8.log
    sed -i 's/the content of the url:.*receiveStatusReportResultChinaMobile.shtml //' 2021.8.log
    

    删除毫秒

    sed -i 's/\.[0-9]\{0,3\}\( \[\)/\1/' merge.log
    

    删除时间

    sed -i 's/.*\(\[INFO\]\)/\1/' 2021.8.log
    sed -i 's/.*\(\[ERROR\]\)/\1/' 2021.8.log
    sed -i 's/time:.*,\(is_china_mobile\)/\1/' 2021.8.log
    

    删除冗余字符

    sed -i 's/error for the url//' merge.log
    sed -i 's/can not read content from the url//' merge.log
    

    统计

    sed -n '/ status:DELIVRD,/p' result.log | wc -l
    sed -n '/"originalStatus":"DELIVRD"/p' merge.log | wc -l
    

    去重复

    awk '!x[$0]++' merge.log
    sort -n merge.log | uniq
    

    修改Ubuntu源地址

    sudo sed -i 's/\(archive\|security\).ubuntu/mirrors.aliyun/' /etc/apt/sources.list
    

    SSH连接不自动断开

    sed -i 's/^#\(ClientAliveInterval\) 0$/\1 60/g' /etc/ssh/sshd_config
    sed -i 's/^#\(ClientAliveCountMax\) 3$/\1 5/g' /etc/ssh/sshd_config
    systemctl restart sshd
    

    /etc/hosts

    # sed 参考 http://man.linuxde.net/sed
            #  https://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html
    sed ......
    

    参考文档

    sed CLI Linux Created Mon, 17 Jan 2022 11:18:47 +0800
  • 初始化配置

    # 配置时区
    timedatectl set-timezone Asia/Shanghai
    
    # 关闭邮件服务
    systemctl stop [email protected] \
    ; systemctl disable [email protected]
    
    # 配置Shell提示符
    echo "PS1='\[\e[36;40m\][\D{%Y-%m-%d} \A] \[\e[0m\] \[\e[35;40m\]\w\[\e[0m\]\n\[\e[33;40m\][\u@\H]\[\e[0m\] \\$ '" >> ~/.bashrc
    # 打开自定义命令
    sed -E -i.bak \
        -e '/(export|eval|alias (ls|ll|l|rm|cp|mv))/s/^# //' ~/.bashrc \
        && . ~/.bashrc
    
    # 配置 sshd
    # 允许root密码登录
    # 允许密码登录
    # 解决SSH自动断开问题
    sed -E -i.bak \
        -e 's/#(Port 22)/\1/' \
        -e 's/#(PermitRootLogin) prohibit-password/\1 yes/' \
        -e 's/#(PubkeyAuthentication yes)/\1/' \
        -e 's/#(PasswordAuthentication yes)/\1/' \
        -e 's/#(AllowTcpForwarding yes)/\1/' \
        -e 's/(X11Forwarding yes)/#\1/' \
        -e 's/#(Compression delayed)/\1/' \
        -e 's/#(ClientAliveInterval) 0/\1 60/' \
        -e 's/#(ClientAliveCountMax) 3/\1 3/' \
        /etc/ssh/sshd_config \
        && systemctl restart sshd.service
    

    软件更新

    软件库管理

    CLI bash ssh top linux Created Mon, 17 Jan 2022 11:07:07 +0800