Press "Enter" to skip to content

月与灯依旧 Posts

简单解释 ssh 中的 local port forwarding 和 remote port forwarding

1, local port forwarding

ssh client端:
ssh server端: serverIP:80

如果希望在ssh client端访问ssh server端的80端口, 则可以运行

ssh -L 8000:serverIP:80 [email protected]

然后就可以在client端通过访问127.0.0.1:8000达到访问server端80端口的目的

提示:
8000:serverIP:80这里的serverIP不一定要是server自己, 也可以是127.0.0.1, 或者是任何server端能够访问的远程地址.
然后就可以实现在ssh client端访问serverIP:80(即在client端访问127.0.0.1:8000)

下面是一个例子

如上图. 如果执行了

ssh -L 8000:10.10.1.11:80 [email protected]

那么, 访问192.168.56.101:8000则等同于访问了10.10.1.1:80

2, remote port forwarding

ssh client端: clientIP:80
ssh server端:

如果希望在server端访问client端的80端口

ssh -R 8000:localhost:80 [email protected]

然后就可以在ssh server端通过访问serverIP:80达到访问client端8000端口的目的.

提示:
此时server端不止是127.0.0.1:80可访问, serverIP:80也可访问.
任何能访问serverIP:80的用户, 都可以通过访问serverIP:80达到访问client端8000端口的目的.
同样的, localhost:80不一定得是ssh client本身, 也可以是任何一个ssh client可达的地址.

下面是一个例子

Leave a Comment

WordPress block editor shortcuts(WordPress区块编辑器快捷键)

插入(insert)一个区块 (Block)

# 在下方插入一个区块
Ctrl + Alt + Y

# 在上方插入一个区块
Ctrl + Alt + T

移动 (move) 一个区块(Block)

# 将当前区块往上移动(跟上方的区块交换位置)
Ctrl + Alt + Shift + T

# 将当前区块往下移动(跟上方的区块交换位置)
Ctrl + Alt + Shift + Y

辙消操作

# 辙消之前的操作
Ctrl + Z

# 恢复之前辙消的操作
Ctrl + Shift + Z

有了这些快捷键之后, WordPress的区块编辑器就显得好用多了.

Leave a Comment

转载: Ubuntu20.04简单修改IP

在网上搜到的ubuntu改IP都是通过手写interfaces文件,这需要记住语法和格式,很不方便,在Redhat系上,可以使用很方便的NetworkManager的nmtui的Text UI来设置IP,我们只需要填写我们希望的网络信息即可,那么在ubuntu上其实也是有简便的方法;

ubuntu 20使用的netplan来管理,其配置文件使用的YAML,虽然语法格式也简单,但是还是可以有不用记的方式来完成IP的修改;

默认情况下的配置文件在/etc/netplan/00-installer-config.yaml,默认使用DHCP的方式,全部内容为

# This is the network config written by 'subiquity'
network:
  ethernets:
    eth0:
      dhcp4: true
  version: 2

Linux上,大部分软件都包含了自己的文档,常规的包含README,Example之类的,目录在/usr/share/doc/netplan下,有个examples目录,当中包含了很多网络的配置文件模板,如

$ ls /usr/share/doc/netplan/examples/
bonding_router.yaml   direct_connect_gateway_ipv6.yaml  route_metric.yaml                           windows_dhcp_server.yaml
bonding.yaml          direct_connect_gateway.yaml       source_routing.yaml                         wireless.yaml
bridge_vlan.yaml      ipv6_tunnel.yaml                  static_multiaddress.yaml                    wpa_enterprise.yaml
bridge.yaml           loopback_interface.yaml           static_singlenic_multiip_multigateway.yaml
dhcp_wired8021x.yaml  modem.yaml                        static.yaml
dhcp.yaml             network_manager.yaml              vlan.yaml

找到static.yaml就是我们想要的静态IP配置文件模板,现成的格式和内容;拷贝到/etc/netplan下即可;

# 先备份源文件
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
# 拷贝静态IP配置文件
sudo cp /usr/share/doc/netplan/examples/static.yaml /etc/netplan/

# 简单修改一下;它的默认是这样的
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      addresses:
        - 10.10.10.2/24
      nameservers:
        search: [mydomain, otherdomain]
        addresses: [10.10.10.1, 1.1.1.1]
      routes: 
        - to: default
          via: 10.10.10.1

修改完成后,应用即可

sudo netplan apply

本文转载自八宝叠云峰.

Leave a Comment

解决youtube-dl下载时遇到的ERROR: Stream #1:0 -> #0:1 (copy)问题

今天使用youtube-dl下载视频时, 遇到了ERROR: Stream #1:0 -> #0:1 (copy)的错误. 上网查了一下原因, 是youtube-dl和ffmpeg不兼容所致. 于是把youtube-dl和ffmpeg都升级到最新版, 发现问题依旧. 经过一番Google, 也算是找到了解决办法:

之前一直使用的下载方式

sudo youtube-dl --merge-output-format mp4 -f bestvideo+bestaudio https://www.youtube.com/watch?v=L2I67vUK4fY

如果遇到了ERROR: Stream #1:0 -> #0:1 (copy)的错误, 可以使用下面的办法

# 先把视频和音频都下载回来
sudo youtube-dl -f bestvideo[ext=webm]+bestaudio[ext=m4a] https://www.youtube.com/watch?v=L2I67vUK4fY
# 然后再手动merge
sudo ffmpeg -i 1.webm -i 1.m4a -c copy 1.mkv

Leave a Comment

MPC-HC部署MPC VideoRender滤镜

1, 准备工作

MPC-HC的下载地址
MPC VideoRender的下载地址

2, 安装MPC VideoRender滤镜

将下载回来的MPC VideoRender滤镜解压至 C:\Program Files\mpcVR 目录下
右键”以管理员身份运行” Install_MPCVR_64.cmd
则会看到下方提示

Installation succeeded.
Please do not delete the MpcVideoRenderer64.ax file.
The installer has not copied the files anywhere.

3, 在MPC-HC中启用MPC VideoRender滤镜

打开MPC-HC, 找到”选项”, 进行如下设定

参考文档:
https://ngabbs.com/read.php?tid=25033883&rand=660

1 Comment

CentOS 7解决arp欺骗

某天发现一台CentOS机器网络一切正常, 但是却无法正常上网. 后经查询, 发现该机器的网关mac地址与实际网关的mac地址不符.  下面是查看和解决办法.

查看arp

$ cat /proc/net/arp 
IP address       HW type     Flags       HW address            Mask     Device
192.168.43.62    0x1         0x2         24:6e:96:93:c9:7d     *        eth0
192.168.43.61    0x1         0x2         24:6e:96:8c:e0:65     *        eth0
192.168.43.154   0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.43.153   0x1         0x2         52:54:00:fa:bb:fc     *        eth0
192.168.43.60    0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.43.59    0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.43.151   0x1         0x2         52:54:00:aa:73:e2     *        eth0
192.168.43.11    0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.43.31    0x1         0x2         00:be:75:c7:47:ea     *        eth0
192.168.43.111   0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.43.27    0x1         0x2         52:54:00:b4:3f:a3     *        eth0
192.168.43.224   0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.43.26    0x1         0x2         52:54:00:33:50:7e     *        eth0
192.168.43.223   0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.43.25    0x1         0x2         52:54:00:b4:3f:a3     *        eth0
192.168.43.1     0x1         0x2         3c:f5:cc:91:79:87     *        eth0
192.168.43.163   0x1         0x2         52:54:00:78:13:7d     *        eth0
192.168.43.162   0x1         0x2         52:54:00:7f:83:a4     *        eth0
192.168.43.104   0x1         0x2         52:54:00:34:0c:fc     *        eth0
192.168.43.21    0x1         0x0         00:00:00:00:00:00     *        eth0
192.168.43.44    0x1         0x2         24:6e:96:93:a3:c4     *        eth0
192.168.43.43    0x1         0x2         24:6e:96:8c:df:64     *        eth0
192.168.43.158   0x1         0x2         52:54:00:9a:ff:9f     *        eth0
192.168.43.122   0x1         0x2         52:54:00:99:e5:5e     *        eth0


$ arp -a
? (192.168.43.62) at 24:6e:96:93:c9:7d [ether] on eth0
? (192.168.43.61) at 24:6e:96:8c:e0:65 [ether] on eth0
? (192.168.43.154) at <incomplete> on eth0
? (192.168.43.153) at 52:54:00:fa:bb:fc [ether] on eth0
? (192.168.43.60) at <incomplete> on eth0
? (192.168.43.59) at <incomplete> on eth0
? (192.168.43.151) at 52:54:00:aa:73:e2 [ether] on eth0
? (192.168.43.11) at <incomplete> on eth0
? (192.168.43.31) at 00:be:75:c7:47:ea [ether] on eth0
? (192.168.43.111) at <incomplete> on eth0
? (192.168.43.27) at 52:54:00:b4:3f:a3 [ether] on eth0
? (192.168.43.224) at <incomplete> on eth0
? (192.168.43.26) at 52:54:00:33:50:7e [ether] on eth0
? (192.168.43.223) at <incomplete> on eth0
? (192.168.43.25) at 52:54:00:b4:3f:a3 [ether] on eth0
gateway (192.168.43.1) at 3c:f5:cc:91:79:87 [ether] on eth0
? (192.168.43.163) at 52:54:00:78:13:7d [ether] on eth0
? (192.168.43.162) at 52:54:00:7f:83:a4 [ether] on eth0
? (192.168.43.104) at 52:54:00:34:0c:fc [ether] on eth0
? (192.168.43.21) at <incomplete> on eth0
? (192.168.43.44) at 24:6e:96:93:a3:c4 [ether] on eth0
? (192.168.43.43) at 24:6e:96:8c:df:64 [ether] on eth0
? (192.168.43.158) at 52:54:00:9a:ff:9f [ether] on eth0

绑定arp

绑定arp的过程在某些国外网站称之为Create a Static ARP Table. 下面演示手动绑定网关192.168.43.1的mac地址为74:ea:c8:2d:9f:f6

arp -s 192.168.43.1 74:ea:c8:2d:9f:f6

 

Leave a Comment

remove a node from ElasticSearch cluster

1, stop shard allocation for this node

$ curl -XGET "127.0.0.1:9200/_cat/allocation?v"
shards disk.indices disk.used disk.avail disk.total disk.percent host         ip           node
   412      960.3gb     1.8tb     15.6tb     17.4tb           10 172.29.4.156 172.29.4.156 es_node_156_2
   411      478.9gb     1.5tb     15.9tb     17.4tb            8 172.29.4.158 172.29.4.158 es_node_158_2
   411      557.5gb   558.7gb     16.9tb     17.4tb            3 172.29.4.157 172.29.4.157 es_node_157
   411      743.5gb     1.5tb     15.9tb     17.4tb            8 172.29.4.158 172.29.4.158 es_node_158
   411          1tb       1tb      9.9tb     10.9tb            9 172.29.4.177 172.29.4.177 es_node_177
   411      840.6gb     1.8tb     15.6tb     17.4tb           10 172.29.4.156 172.29.4.156 es_node_156
   248        9.3tb     9.3tb      1.5tb     10.9tb           85 172.29.4.178 172.29.4.178 es_node_178

假设我们希望下掉es_node_158_2这个节点, 则下面3条命令任选其一

curl -XPUT 127.0.0.1:9200/_cluster/settings -H 'Content-Type: application/json' -d '{
  "transient" :{
    "cluster.routing.allocation.exclude._ip": "<node_ip_address>"
  }
}'


curl -XPUT 127.0.0.1:9200/_cluster/settings -H 'Content-Type: application/json' -d '{
  "transient" :{
    "cluster.routing.allocation.exclude._name": "es_node_158_2"
  }
}'


curl -XPUT 127.0.0.1:9200/_cluster/settings -H 'Content-Type: application/json' -d '{
  "transient" :{
    "cluster.routing.allocation.exclude._id": "<node_id>"
  }
}'

确认上面的命令执行成功

curl -XGET "127.0.0.1:9200/_cluster/settings?pretty=true"
{
  "persistent" : {
    "cluster" : {
      "max_shards_per_node" : "30000"
    },
    "indices" : {
      "breaker" : {
        "fielddata" : {
          "limit" : "20%"
        }
      }
    },
    "search" : {
      "max_buckets" : "87000"
    },
    "xpack" : {
      "monitoring" : {
        "collection" : {
          "enabled" : "true"
        }
      }
    }
  },
  "transient" : {
    "cluster" : {
      "routing" : {
        "allocation" : {
          "enable" : "all",
          "exclude" : {
            "_name" : "es_node_158_2"
          }
        }
      }
    }
  }
}

然后Elasticsearch会将es_node_158_2节点上的shards分配给其余节点. 再次查看shards allocation情况会发现es_node_158_2上面的shards数量在明显减少.

$ curl -XGET "127.0.0.1:9200/_cat/allocation?v"
shards disk.indices disk.used disk.avail disk.total disk.percent host         ip           node
   248        9.3tb     9.3tb      1.5tb     10.9tb           85 172.29.4.178 172.29.4.178 es_node_178
   438          1tb       1tb      9.9tb     10.9tb            9 172.29.4.177 172.29.4.177 es_node_177
   417      559.9gb   561.1gb     16.9tb     17.4tb            3 172.29.4.157 172.29.4.157 es_node_157
   441      963.1gb     1.8tb     15.6tb     17.4tb           10 172.29.4.156 172.29.4.156 es_node_156_2
   443      842.5gb     1.8tb     15.6tb     17.4tb           10 172.29.4.156 172.29.4.156 es_node_156
   443      747.1gb     1.5tb     15.9tb     17.4tb            8 172.29.4.158 172.29.4.158 es_node_158
   285      472.7gb     1.5tb     15.9tb     17.4tb            8 172.29.4.158 172.29.4.158 es_node_158_2  # shards开始减少

2, stop node and afterwork

等es_node_158_2上面的shards数量变为0的时候, 就可以登陆es_node_158_2并shutdown elasticsearch service了.

在es_node_158_2上面执行

$ systemctl stop elasticsearch
$ systemctl disable elasticsearch

在其它node上面执行

$ curl -XPUT 127.0.0.1:9200/_cluster/settings -H 'Content-Type: application/json' -d '{
  "transient" :{
    "cluster.routing.allocation.exclude._name": null
  }
}'

参考文档: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-cluster.html#cluster-shard-allocation-filtering

Leave a Comment