cat /lib/systemd/system/rc.local.service # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This unit gets pulled automatically into multi-user.target by # systemd-rc-local-generator if /etc/rc.local is executable. [Unit] Description=/etc/rc.local Compatibility ConditionFileIsExecutable=/etc/rc.local After=network.target
vim /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # 这里写你需要执行的命令 # 注意: 一定要将命令添加在 exit 0之前
cat /lib/systemd/system/rc.local.service # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This unit gets pulled automatically into multi-user.target by # systemd-rc-local-generator if /etc/rc.local is executable. [Unit] Description=/etc/rc.local Compatibility ConditionFileIsExecutable=/etc/rc.local After=network.target
vim /etc/rc.local #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # 这里写你需要执行的命令 # 注意: 一定要将命令添加在 exit 0之前
root@raspbian:/opt# startx -bash: startx: command not found #若报这个错,说明x服务没有装,利用search查一次是哪个包提供的 root@raspbian:/opt# apt search startx Sorting... Done Full Text Search... Done xinit/stable 1.4.0-1 arm64 X server initialisation tool #查到后直接安装 root@raspbian:/opt# apt install xinit
#若报这个错 xauth: file /root/.Xauthority does not exist
X.Org X Server 1.20.4 X Protocol Version 11, Revision 0 Build Operating System: Linux 4.19.0-16-arm64 aarch64 Debian Current Operating System: Linux raspbian 5.10.42-Release-OPENFANS+20210611-v8 #1 SMP PREEMPT Fri Jun 11 17:19:45 CST 2021 aarch64 Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 bcm2708_fb.fbwidth=1824 bcm2708_fb.fbheight=984 bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 smsc95xx.macaddr=DC:A6:32:E1:6A:E3 vc_mem.mem_base=0x3f000000 vc_mem.mem_size=0x3f600000 dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=PARTUUID=daf1c5e3-02 rootfstype=ext4 elevator=deadline fsck.repair=yes net.ifnames=0 cgroup_enable=1 cgroup_memory=1 cgroup_enable=cpuset cgroup_enable=memory swapaccount=1 zswap.enabled=1 zswap.zpool=z3fold zswap.compressor=lz4 zswap.max_pool_percent=25 rootwait Build Date: 19 April 2021 09:34:38AM xorg-server 2:1.20.4-1+deb10u3 (https://www.debian.org/support) Current version of pixman: 0.36.0 Before reporting problems, check http://wiki.x.org to make sure that you have the latest version. Markers: (--) probed, (**) from config file, (==) default setting, (++) from command line, (!!) notice, (II) informational, (WW) warning, (EE) error, (NI) not implemented, (??) unknown. (==) Log file: "/var/log/Xorg.0.log", Time: Fri Aug 27 22:29:50 2021 (==) Using system config directory "/usr/share/X11/xorg.conf.d" (EE) Fatal server error: (EE) no screens found(EE) (EE) Please consult the The X.Org Foundation support at http://wiki.x.org for help. (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information. (EE) (EE) Server terminated with error (1). Closing log file.
xinit: giving up xinit: unable to connect to X server: Connection refused xinit: server error #错说明还有一个X的依赖包没有安装
root@raspbian:/opt# startx -bash: startx: command not found #若报这个错,说明x服务没有装,利用search查一次是哪个包提供的 root@raspbian:/opt# apt search startx Sorting... Done Full Text Search... Done xinit/stable 1.4.0-1 arm64 X server initialisation tool #查到后直接安装 root@raspbian:/opt# apt install xinit
#若报这个错 xauth: file /root/.Xauthority does not exist
X.Org X Server 1.20.4 X Protocol Version 11, Revision 0 Build Operating System: Linux 4.19.0-16-arm64 aarch64 Debian Current Operating System: Linux raspbian 5.10.42-Release-OPENFANS+20210611-v8 #1 SMP PREEMPT Fri Jun 11 17:19:45 CST 2021 aarch64 Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 bcm2708_fb.fbwidth=1824 bcm2708_fb.fbheight=984 bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 smsc95xx.macaddr=DC:A6:32:E1:6A:E3 vc_mem.mem_base=0x3f000000 vc_mem.mem_size=0x3f600000 dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=PARTUUID=daf1c5e3-02 rootfstype=ext4 elevator=deadline fsck.repair=yes net.ifnames=0 cgroup_enable=1 cgroup_memory=1 cgroup_enable=cpuset cgroup_enable=memory swapaccount=1 zswap.enabled=1 zswap.zpool=z3fold zswap.compressor=lz4 zswap.max_pool_percent=25 rootwait Build Date: 19 April 2021 09:34:38AM xorg-server 2:1.20.4-1+deb10u3 (https://www.debian.org/support) Current version of pixman: 0.36.0 Before reporting problems, check http://wiki.x.org to make sure that you have the latest version. Markers: (--) probed, (**) from config file, (==) default setting, (++) from command line, (!!) notice, (II) informational, (WW) warning, (EE) error, (NI) not implemented, (??) unknown. (==) Log file: "/var/log/Xorg.0.log", Time: Fri Aug 27 22:29:50 2021 (==) Using system config directory "/usr/share/X11/xorg.conf.d" (EE) Fatal server error: (EE) no screens found(EE) (EE) Please consult the The X.Org Foundation support at http://wiki.x.org for help. (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information. (EE) (EE) Server terminated with error (1). Closing log file.
xinit: giving up xinit: unable to connect to X server: Connection refused xinit: server error #错说明还有一个X的依赖包没有安装
Port 22 # 先不要去掉 Port 6666 # 增加一个端口,这样做是为了确保6666端口不能正常连接的情况下依然能保持22端口连接
重启服务,并确认服务没有问题
1 2 3 4
#重启服务 systemctl restart sshd.service #确认服务没有问题 systemctl status sshd.service
使用6666端口,确认可以正常连接
再次编辑配置,将22端口注释掉,然后重启服务
5. 配置禁止root用户直接登录
先确认有普通用户,或者创建一个普通用户
1 2 3 4 5 6 7 8 9 10
[root@CentOS ~]# useradd test #使用passwd命令即可给相应帐户设置或修改密码。
[root@CentOS ~]# passwd test #根据图示,设置或修改密码需要填写两次,第二次为效验密码,输入完毕后请回车确认。 Changing password for user test. New password: Retype new password: passwd: all authentication tokens updated successfully.
修改配置文件
1 2 3 4 5
vi /etc/ssh/sshd_config
查找 #PermitRootLogin yes” 将“#”去掉,末尾“Yes”改为“No”
重启服务
1
systemctl restart sshd
确认已经无法用root用户登录
普通用户可以登录
1 2
# 登陆后切换root su -
6.解决 SSH 连接速度慢
一个个试,不行就还原了,再试下一个
关闭DNS反向解析
1 2 3 4 5
vi /etc/ssh/sshd_config UseDNS=no
重启验证,不行的话要改回来!!! service sshd restart
关闭GSS认证
1 2 3 4 5
# vi /etc/ssh/sshd_config GSSAPIAuthentication no
重启验证,不行的话要改回来!!! service sshd restart
7. fzf-模糊查找神器
1 2 3 4 5 6 7 8 9 10 11
apt install fzf
根据readme添加环境变量 more /usr/share/doc/fzf/README.Debian Bash ====
Append this line to ~/.bashrc to enable fzf keybindings for Bash:
Port 22 # 先不要去掉 Port 6666 # 增加一个端口,这样做是为了确保6666端口不能正常连接的情况下依然能保持22端口连接
重启服务,并确认服务没有问题
1 2 3 4
#重启服务 systemctl restart sshd.service #确认服务没有问题 systemctl status sshd.service
使用6666端口,确认可以正常连接
再次编辑配置,将22端口注释掉,然后重启服务
5. 配置禁止root用户直接登录
先确认有普通用户,或者创建一个普通用户
1 2 3 4 5 6 7 8 9 10
[root@CentOS ~]# useradd test #使用passwd命令即可给相应帐户设置或修改密码。
[root@CentOS ~]# passwd test #根据图示,设置或修改密码需要填写两次,第二次为效验密码,输入完毕后请回车确认。 Changing password for user test. New password: Retype new password: passwd: all authentication tokens updated successfully.
修改配置文件
1 2 3 4 5
vi /etc/ssh/sshd_config
查找 #PermitRootLogin yes” 将“#”去掉,末尾“Yes”改为“No”
重启服务
1
systemctl restart sshd
确认已经无法用root用户登录
普通用户可以登录
1 2
# 登陆后切换root su -
6.解决 SSH 连接速度慢
一个个试,不行就还原了,再试下一个
关闭DNS反向解析
1 2 3 4 5
vi /etc/ssh/sshd_config UseDNS=no
重启验证,不行的话要改回来!!! service sshd restart
关闭GSS认证
1 2 3 4 5
# vi /etc/ssh/sshd_config GSSAPIAuthentication no
重启验证,不行的话要改回来!!! service sshd restart
7. fzf-模糊查找神器
1 2 3 4 5 6 7 8 9 10 11
apt install fzf
根据readme添加环境变量 more /usr/share/doc/fzf/README.Debian Bash ====
Append this line to ~/.bashrc to enable fzf keybindings for Bash:
[root@zmr-service ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4bc7425371cb lizheming/waline:1.30.4 "docker-entrypoint.s…" 22 hours ago Up 22 hours 8360/tcp waline af3b2f1b7892 nginx:1.24.0 "/docker-entrypoint.…" 39 hours ago Up 24 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp nginx 60ba55559d39 snowdreamtech/frpc:0.48.0 "/bin/sh -c '/usr/bi…" 13 days ago Up 24 hours frpc 61e4f29b5ebc gitea/gitea:1.19.0 "/usr/bin/entrypoint…" 2 weeks ago Up 38 hours 22/tcp, 3000/tcp gitea 413621548b9a mysql/mysql-server:8.0.32 "/entrypoint.sh --de…" 2 weeks ago Up 38 hours (healthy) 3306/tcp, 33060-33061/tcp mysql8 [root@zmr-service ~]#
核心就是所有的docker容器都使用相同的网络。
1 2 3 4 5 6 7 8 9
# 创建网卡 docker network create -d bridge app_net
[root@zmr-service ~]# docker network ls NETWORK ID NAME DRIVER SCOPE 391b4ed84d89 app_net bridge local fab5d9edb87f bridge bridge local e976eb0945b9 host host local fa4d4514eb40 none null local
[root@zmr-service conf.d]# docker exec -it nginx ping gitea PING gitea (172.25.0.4): 56 data bytes 64 bytes from 172.25.0.4: icmp_seq=0 ttl=64 time=0.190 ms 64 bytes from 172.25.0.4: icmp_seq=1 ttl=64 time=0.134 ms 64 bytes from 172.25.0.4: icmp_seq=2 ttl=64 time=0.148 ms 64 bytes from 172.25.0.4: icmp_seq=3 ttl=64 time=0.133 ms 64 bytes from 172.25.0.4: icmp_seq=4 ttl=64 time=0.128 ms 64 bytes from 172.25.0.4: icmp_seq=5 ttl=64 time=0.130 ms 64 bytes from 172.25.0.4: icmp_seq=6 ttl=64 time=0.131 ms 64 bytes from 172.25.0.4: icmp_seq=7 ttl=64 time=0.130 ms
[root@zmr-service conf.d]# docker exec -it nginx ping waline PING waline (172.25.0.5): 56 data bytes 64 bytes from 172.25.0.5: icmp_seq=0 ttl=64 time=0.261 ms 64 bytes from 172.25.0.5: icmp_seq=1 ttl=64 time=0.136 ms 64 bytes from 172.25.0.5: icmp_seq=2 ttl=64 time=0.139 ms
[root@zmr-service ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4bc7425371cb lizheming/waline:1.30.4 "docker-entrypoint.s…" 22 hours ago Up 22 hours 8360/tcp waline af3b2f1b7892 nginx:1.24.0 "/docker-entrypoint.…" 39 hours ago Up 24 hours 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp nginx 60ba55559d39 snowdreamtech/frpc:0.48.0 "/bin/sh -c '/usr/bi…" 13 days ago Up 24 hours frpc 61e4f29b5ebc gitea/gitea:1.19.0 "/usr/bin/entrypoint…" 2 weeks ago Up 38 hours 22/tcp, 3000/tcp gitea 413621548b9a mysql/mysql-server:8.0.32 "/entrypoint.sh --de…" 2 weeks ago Up 38 hours (healthy) 3306/tcp, 33060-33061/tcp mysql8 [root@zmr-service ~]#
核心就是所有的docker容器都使用相同的网络。
1 2 3 4 5 6 7 8 9
# 创建网卡 docker network create -d bridge app_net
[root@zmr-service ~]# docker network ls NETWORK ID NAME DRIVER SCOPE 391b4ed84d89 app_net bridge local fab5d9edb87f bridge bridge local e976eb0945b9 host host local fa4d4514eb40 none null local
[root@zmr-service conf.d]# docker exec -it nginx ping gitea PING gitea (172.25.0.4): 56 data bytes 64 bytes from 172.25.0.4: icmp_seq=0 ttl=64 time=0.190 ms 64 bytes from 172.25.0.4: icmp_seq=1 ttl=64 time=0.134 ms 64 bytes from 172.25.0.4: icmp_seq=2 ttl=64 time=0.148 ms 64 bytes from 172.25.0.4: icmp_seq=3 ttl=64 time=0.133 ms 64 bytes from 172.25.0.4: icmp_seq=4 ttl=64 time=0.128 ms 64 bytes from 172.25.0.4: icmp_seq=5 ttl=64 time=0.130 ms 64 bytes from 172.25.0.4: icmp_seq=6 ttl=64 time=0.131 ms 64 bytes from 172.25.0.4: icmp_seq=7 ttl=64 time=0.130 ms
[root@zmr-service conf.d]# docker exec -it nginx ping waline PING waline (172.25.0.5): 56 data bytes 64 bytes from 172.25.0.5: icmp_seq=0 ttl=64 time=0.261 ms 64 bytes from 172.25.0.5: icmp_seq=1 ttl=64 time=0.136 ms 64 bytes from 172.25.0.5: icmp_seq=2 ttl=64 time=0.139 ms