树莓派之IP转发-无线转有线

备份系统镜像

先全量备份TF卡到网络共享文件夹
sudo apt install dc3dd
sudo mount -t cifs -o username=lius,password=gvVhgff //192.168.88.77/raspberrypi /media/backups
df-h
lsblk
sudo umount /media/backups

sudo dc3dd if=/dev/mmcblk0 of=/media/backups/myimg20211114.img

而后压缩

git clone https://github.com/Drewsif/PiShrink/
chmod +x PiShrink/pishrink.sh
sudo mv PiShrink/pishrink.sh /usr/local/bin

sudo pishrink.sh -z /media/backups/myimg20211114.img

恢复镜像

win32diskimager-1.0.0 选择- 写入

添加图片注释,不超过 140 字(可选)

raspi-config–advance option-expand file system

装个Pi Dashboard

sudo docker run -d --name docker-pi-dashboard -e 'LISTEN=1024' --net=host ecat/docker-pi-dashboard

查看网口信息:

pi@raspberrypi:~$ sudo iwconfig wlan0
wlan0     IEEE 802.11  ESSID:"ziroom401"  
          Mode:Managed  Frequency:5.745 GHz  Access Point: 74:05:A5:86:A5:1A   
          Bit Rate=150 Mb/s   Tx-Power=31 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
          Link Quality=65/70  Signal level=-45 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:6888  Invalid misc:0   Missed beacon:0

~~~~~~~~~~~

pi@raspberrypi:~$ ethtool eth0
Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Supported pause frame use: Symmetric Receive-only
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Advertised pause frame use: Symmetric
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Link partner advertised link modes:  10baseT/Half 10baseT/Full 
                                             100baseT/Half 100baseT/Full 
                                             1000baseT/Full 
        Link partner advertised pause frame use: Symmetric Receive-only
        Link partner advertised auto-negotiation: Yes
        Link partner advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
Cannot get wake-on-lan settings: Operation not permitted
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

~~~~~~~~~~~

pi@raspberrypi:~$ sudo mii-tool eth0
eth0: negotiated 1000baseT-FD flow-control, link ok

树莓派3B+ 1000M网卡实际只能跑300M

查看型号:

cat /proc/cpuinfo
.
.
.
Hardware        : BCM2835
Revision        : a020d3
Serial          : 000000003e3ec125
Model           : Raspberry Pi 3 Model B Plus Rev 1.3
pi@raspberrypi:~$   cat /proc/device-tree/model
Raspberry Pi 3 Model B Plus Rev 1.3pi@raspberrypi:~$ 

查看占用进程和性能测试:

top -bn 1 -i -c


sudo apt-get install sysbench
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=2 run //以四核为例,满载两个线程,整体利用率就是50%

sysbench --test=fileio --file-total-size=2G prepare
sysbench --test=fileio --file-total-size=2G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
sysbench --test=fileio --file-total-size=2G cleanup

sysbench --test=memory run --memory-total-size=2G
sysbench --test=memory run --memory-total-size=2G --memory-oper=read

测速:

sudo apt install iperf3
iperf3 -p 3005 -s

iperf3 -c 192.168.88.1 -p 3005
Connecting to host 192.168.88.1, port 3005
[  4] local 192.168.88.77 port 8494 connected to 192.168.88.1 port 3005
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-1.00   sec  24.0 MBytes   201 Mbits/sec
[  4]   1.00-2.00   sec  39.0 MBytes   327 Mbits/sec
[  4]   2.00-3.00   sec  39.5 MBytes   331 Mbits/sec
[  4]   3.00-4.00   sec  39.2 MBytes   329 Mbits/sec
[  4]   4.00-5.00   sec  39.4 MBytes   330 Mbits/sec
[  4]   5.00-6.00   sec  38.9 MBytes   327 Mbits/sec
[  4]   6.00-7.00   sec  38.2 MBytes   321 Mbits/sec
[  4]   7.00-8.00   sec  39.5 MBytes   331 Mbits/sec
[  4]   8.00-9.00   sec  39.5 MBytes   331 Mbits/sec
[  4]   9.00-10.00  sec  38.9 MBytes   326 Mbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  4]   0.00-10.00  sec   376 MBytes   315 Mbits/sec                  sender
[  4]   0.00-10.00  sec   376 MBytes   315 Mbits/sec                  receiver

iperf Done.

添加U盘:

查看外接存储信息:(默认重启后 不会自动挂载)
sudo fdisk -l | grep '^Disk'
sudo blkid
sudo lsblk

格式化为ext4:
sudo mkfs.ext4 /dev/sda   //sda磁盘名称 需提前确认

建立挂载点:
sudo mkdir /mnt/usb_flash

更改属主和组,可选,用于解决其他用户访问权限问题
sudo chown pi:pi /mnt/usb_flash
ls -l 

挂载和卸载
sudo mount -t ext4 /dev/sda /mnt/usb_flash
sudo umount /mnt/usb_flash

添加portainer 容器管理GUI工具

docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

update portainer:a demo with version 2.9.3

docker stop portainer
docker rm portainer
docker pull cr.portainer.io/portainer/portainer-ce:x.x.x

docker run -d -p 8000:8000 -p 9000:9000 -p 9443:9443 \
    --name=portainer --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v portainer_data:/data \
    cr.portainer.io/portainer/portainer-ce:2.9.3

Install FFmpeg on Raspberry Pi

https://gist.github.com/jamesmacwhite/58aebfe4a82bb8d645a797a1ba975132

sudo apt update
sudo apt install -y ffmpeg

ffmpeg -version
ffmpeg -encoders
ffmpeg -decoders

sudo apt purge --autoremove -y ffmpeg

convent MKV to MP4:(  '-c copy' )
ffmpeg -i example.mkv -c copy example.mp4

for f in *.mkv; do ffmpeg -i "$f" -c copy "${f%.mkv}.mp4"; done

更新源:

pi@raspberrypi:~$  sudo apt-get update --allow-releaseinfo-change
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian buster InRelease
Get:2 http://mirrors.tuna.tsinghua.edu.cn/raspberrypi buster InRelease [32.6 kB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/raspberrypi buster/main armhf Packages [393 kB]
Get:4 https://download.docker.com/linux/raspbian buster InRelease [33.6 kB]         
Fetched 459 kB in 4s (127 kB/s)     
Reading package lists... Done
N: Repository 'http://mirrors.tuna.tsinghua.edu.cn/raspberrypi buster InRelease' changed its 'Suite' value from 'testing' to 'oldstable'
pi@raspberrypi:~$ 

自动挂载U盘:

https://www.shellhacks.com/raspberry-pi-mount-usb-drive-automatically/

查询磁盘的UUID 和文件系统格式
pi@raspberrypi:~ $ sudo blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="592B-C92C" TYPE="vfat" PARTUUID="d8c1202f-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="706944a6-7d0f-4a45-9f8c-7fb07375e9f7" TYPE="ext4" PARTUUID="d8c1202f-02"
/dev/mmcblk0: PTUUID="d8c1202f" PTTYPE="dos"
/dev/sda: UUID="254c51d6-8f79-48b4-aed3-8626662ae41e" TYPE="ext4"


备份并修改文件系统的 配置文件
(该修改有风险,可能无法进入系统,灾难恢复 参考这个:
https://talhasariyuerek.com/en/linux-raspberry-pi-3b3b4-emergency-mode-root-account-locked-solution/
)
我的树莓派系统为:PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"

$ sudo cp /etc/fstab /etc/fstab.back
$ sudo nano /etc/fstab
UUID=FC05-DF26 /mnt/usb0 ext4 defaults,auto,users,rw,nofail 0 0

保存,退出

重启测试 是否自动挂载

添加持久化静态路由:

文章详情:https://huf.org/wp/?p=355

我的树莓派系统为:PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
临时路由;
/sbin/route add -net 10.1.2.0/24 gw 10.1.1.100

持久路由:
sudo vi /etc/dhcpcd.exit-hook

## adding the persistent route from the example above:
/sbin/route add -net 10.1.2.0/24 gw 10.1.1.100
保持,退出

重启服务
sudo service dhcpcd restart
或者重启设备,测试是否持久路由

Related Posts

Leave a Reply

Your email address will not be published.