winloong
3 years ago
10 changed files with 587 additions and 4 deletions
@ -0,0 +1,191 @@ |
|||||
|
--- |
||||
|
title: 初识 Raspberry Pi OS Lite |
||||
|
author: Uncle Dragon |
||||
|
date: 2021-07-13 |
||||
|
categories: linux |
||||
|
tags: [linux,containerd,mqtt] |
||||
|
--- |
||||
|
|
||||
|
<div align='center' ><b><font size='70'> 初识 Raspberry Pi OS Lite </font></b></div> |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
<center> author: Uncle Dragon </center> |
||||
|
|
||||
|
|
||||
|
<center> date: 2021-07-13 </center> |
||||
|
|
||||
|
|
||||
|
<div STYLE="page-break-after: always;"></div> |
||||
|
|
||||
|
[TOC] |
||||
|
|
||||
|
<div STYLE="page-break-after: always;"></div> |
||||
|
|
||||
|
Raspberry Pi OS Lite 基于 Debian 10 32 位版本的精简版,因此debian 下默认使用的命令,绝大部分它都可以使用。 |
||||
|
|
||||
|
# set up Raspberry |
||||
|
设置静态IP |
||||
|
|
||||
|
```shell |
||||
|
$ vi /etc/dhcpcd.conf |
||||
|
|
||||
|
interface eth0 |
||||
|
static ip_address=10.8.30.100/24 |
||||
|
static routes=10.8.30.1 |
||||
|
static domain_name_servers=114.114.114.114 223.5.5.5 223.6.6.6 |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
|
||||
|
ssh |
||||
|
默认已经安装ssh服务 |
||||
|
设置开机自启 |
||||
|
```shell |
||||
|
$ systemctl enable ssh |
||||
|
Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install. |
||||
|
Executing: /lib/systemd/systemd-sysv-install enable ssh |
||||
|
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service. |
||||
|
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service. |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
安装 vim |
||||
|
|
||||
|
```shell |
||||
|
$ apt-get update && apt-get install vim |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
|
||||
|
时区设置 |
||||
|
|
||||
|
```shell |
||||
|
$ apt-get install ntpdate |
||||
|
|
||||
|
$ tzselect |
||||
|
Please identify a location so that time zone rules can be set correctly. |
||||
|
Please select a continent, ocean, "coord", or "TZ". |
||||
|
1) Africa 5) Atlantic Ocean 9) Pacific Ocean |
||||
|
2) Americas 6) Australia 10) coord - I want to use geographical coordinates. |
||||
|
3) Antarctica 7) Europe 11) TZ - I want to specify the time zone using the Posix TZ format. |
||||
|
4) Asia 8) Indian Ocean |
||||
|
#? 4 |
||||
|
Please select a country whose clocks agree with yours. |
||||
|
1) Afghanistan 7) Brunei 13) Hong Kong 19) Japan 25) Kyrgyzstan 31) Myanmar (Burma) 37) Qatar 43) Taiwan 49) Vietnam |
||||
|
2) Armenia 8) Cambodia 14) India 20) Jordan 26) Laos 32) Nepal 38) Russia 44) Tajikistan 50) Yemen |
||||
|
3) Azerbaijan 9) China 15) Indonesia 21) Kazakhstan 27) Lebanon 33) Oman 39) Saudi Arabia 45) Thailand |
||||
|
4) Bahrain 10) Cyprus 16) Iran 22) Korea (North) 28) Macau 34) Pakistan 40) Singapore 46) Turkmenistan |
||||
|
5) Bangladesh 11) East Timor 17) Iraq 23) Korea (South) 29) Malaysia 35) Palestine 41) Sri Lanka 47) United Arab Emirates |
||||
|
6) Bhutan 12) Georgia 18) Israel 24) Kuwait 30) Mongolia 36) Philippines 42) Syria 48) Uzbekistan |
||||
|
#? 9 |
||||
|
Please select one of the following time zone regions. |
||||
|
1) Beijing Time |
||||
|
2) Xinjiang Time |
||||
|
#? 1 |
||||
|
|
||||
|
The following information has been given: |
||||
|
|
||||
|
China |
||||
|
Beijing Time |
||||
|
|
||||
|
Therefore TZ='Asia/Shanghai' will be used. |
||||
|
Selected time is now: Mon Jul 12 17:33:01 CST 2021. |
||||
|
Universal Time is now: Mon Jul 12 09:33:01 UTC 2021. |
||||
|
Is the above information OK? |
||||
|
1) Yes |
||||
|
2) No |
||||
|
#? 1 |
||||
|
|
||||
|
You can make this change permanent for yourself by appending the line |
||||
|
TZ='Asia/Shanghai'; export TZ |
||||
|
to the file '.profile' in your home directory; then log out and log in again. |
||||
|
|
||||
|
Here is that TZ value again, this time on standard output so that you |
||||
|
can use the /usr/bin/tzselect command in shell scripts: |
||||
|
Asia/Shanghai |
||||
|
|
||||
|
$ vi /etc/profile |
||||
|
|
||||
|
TZ='Asia/Shanghai'; export TZ |
||||
|
|
||||
|
$ source /etc/profile |
||||
|
|
||||
|
$ date |
||||
|
Mon 12 Jul 17:36:07 CST 2021 |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
# install containerd |
||||
|
|
||||
|
```shell |
||||
|
$ sudo apt-get update |
||||
|
|
||||
|
$ sudo apt-get install \ |
||||
|
apt-transport-https \ |
||||
|
ca-certificates \ |
||||
|
curl \ |
||||
|
gnupg \ |
||||
|
lsb-release |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
```shell |
||||
|
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg |
||||
|
``` |
||||
|
|
||||
|
|
||||
|
|
||||
|
```shell |
||||
|
$ echo \ |
||||
|
"deb [arch=armhf signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \ |
||||
|
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null |
||||
|
``` |
||||
|
|
||||
|
```shell |
||||
|
$ sudo apt-get update |
||||
|
$ sudo apt-get install containerd.io |
||||
|
``` |
||||
|
|
||||
|
# install mqtt |
||||
|
|
||||
|
```shell |
||||
|
|
||||
|
|
||||
|
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key |
||||
|
|
||||
|
sudo apt-key add mosquitto-repo.gpg.key |
||||
|
|
||||
|
# sudo wget -P /etc/apt/sources.list.d/ http://repo.mosquitto.org/debian/mosquitto-jessie.list |
||||
|
# sudo wget -P /etc/apt/sources.list.d/ http://repo.mosquitto.org/debian/mosquitto-stretch.list |
||||
|
sudo wget -P /etc/apt/sources.list.d/ http://repo.mosquitto.org/debian/mosquitto-buster.list |
||||
|
|
||||
|
apt-get update |
||||
|
|
||||
|
apt-get install mosquitto |
||||
|
|
||||
|
|
||||
|
``` |
||||
|
|
||||
|
|
||||
|
|
Binary file not shown.
@ -0,0 +1,70 @@ |
|||||
|
--- |
||||
|
title: SSH 免密认证 |
||||
|
date: 2020-09-28 |
||||
|
categories: |
||||
|
- devops |
||||
|
tags: [linux, ssh] |
||||
|
--- |
||||
|
|
||||
|
|
||||
|
## a. 安装ssh |
||||
|
|
||||
|
``` bash |
||||
|
sudo apt-get update |
||||
|
sudo apt-get install openssh-server |
||||
|
sudo apt-get install openssh-client |
||||
|
# 测试是否安装成功 |
||||
|
ssh -l anxinyun 10.8.30.179 |
||||
|
``` |
||||
|
<!--more--> |
||||
|
|
||||
|
## b. 修改配置 |
||||
|
|
||||
|
``` |
||||
|
修改 /etc/ssh/sshd_config: |
||||
|
RSAAuthentication yes (启用RSA认证) |
||||
|
PubkeyAuthentication yes (启用公钥私钥配对认证) |
||||
|
AuthorizedKeysFile %h/.ssh/authorized_keys (公钥文件路径) |
||||
|
``` |
||||
|
|
||||
|
``` bash |
||||
|
# 重启服务 |
||||
|
service ssh restart |
||||
|
``` |
||||
|
|
||||
|
## c. 配置密钥 |
||||
|
|
||||
|
``` bash |
||||
|
# 生成密钥对 |
||||
|
# ssh-keygen -t rsa -P "" |
||||
|
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" |
||||
|
# 输出到authorized_keys文件 |
||||
|
cat .ssh/id_rsa.pub >> .ssh/authorized_keys |
||||
|
# 设置authorized_keys权限 |
||||
|
chmod 600 .ssh/authorized_keys |
||||
|
``` |
||||
|
|
||||
|
``` bash |
||||
|
# 需要免密登录 哪台主机,就把公钥注册到哪台主机 |
||||
|
# 复制 n1 公钥到 m1 |
||||
|
scp anxinyun@10.8.30.179:/home/anxinyun/.ssh/id_rsa.pub . |
||||
|
# 追加到 authorized_keys |
||||
|
cat id_rsa.pub >> .ssh/authorized_keys |
||||
|
# 删除 n1 公钥 |
||||
|
rm id_rsa.pub |
||||
|
|
||||
|
# 在 n1、n2中重复上述命令 |
||||
|
``` |
||||
|
|
||||
|
## M1 远程登录免密 |
||||
|
|
||||
|
``` basic |
||||
|
用xshell 用户密钥生成工具生成密钥对 |
||||
|
把公钥追加到 .ssh/authorized_keys |
||||
|
私钥和密钥自己妥善保存 |
||||
|
|
||||
|
# 禁用ssh用户密码登录 |
||||
|
修改 /etc/ssh/sshd_config: |
||||
|
PasswordAuthentication no |
||||
|
``` |
||||
|
|
@ -0,0 +1,37 @@ |
|||||
|
--- |
||||
|
title: 忘记 Linux root 密码 |
||||
|
date: 2020-05-26 |
||||
|
categories: |
||||
|
- linux |
||||
|
tags: [linux] |
||||
|
--- |
||||
|
|
||||
|
|
||||
|
> linux 忘记密码,别慌,按下面步骤轻松重置密码。 |
||||
|
|
||||
|
## 1. 重启系统 |
||||
|
|
||||
|
``` |
||||
|
# 根据提示在系统启动菜单,选择系统,然后根据提示 按 `e` 修改启动参数 |
||||
|
Use the ↑ and ↓ keys to changed the selection. |
||||
|
Press 'e' to edit the selected item. or 'c' for ... ... |
||||
|
``` |
||||
|
<!--more--> |
||||
|
|
||||
|
## 2. 修改参数 |
||||
|
|
||||
|
向下滚动光标,找到 `...root=/dev/Mapper/centos-root ro rd.lvm.lv=...` 主要时找 **ro** |
||||
|
把 ro 更改为 `rw init=/sysroot/bin/sh` |
||||
|
修改完成,根据提示 按 `Ctrl-x` |
||||
|
|
||||
|
## 3. 修改密码 |
||||
|
|
||||
|
```bash |
||||
|
passwd root # 不只是root,任何你想修改的可登录用户名 |
||||
|
# 下面根据系统提示输入新密码并确认密码 |
||||
|
``` |
||||
|
|
||||
|
## 4. 重启系统 |
||||
|
|
||||
|
> 使用新创建的密码登录 |
||||
|
|
Binary file not shown.
@ -0,0 +1,202 @@ |
|||||
|
--- |
||||
|
title: Linux 设置静态 IP |
||||
|
date: 2020-05-26 |
||||
|
categories: |
||||
|
- linux |
||||
|
tags: [linux] |
||||
|
--- |
||||
|
|
||||
|
## Ubuntu |
||||
|
|
||||
|
### Ubuntu 16 |
||||
|
#### 修改 `/etc/network/interfaces` |
||||
|
|
||||
|
``` bash |
||||
|
sudo vi /etc/network/interfaces |
||||
|
``` |
||||
|
|
||||
|
<!--more--> |
||||
|
|
||||
|
``` ini |
||||
|
auto eno4 |
||||
|
iface eno4 inet static |
||||
|
address 10.8.30.176 |
||||
|
netmask 255.255.255.0 |
||||
|
gateway 10.8.30.1 |
||||
|
dns-nameserver 114.114.114.114 |
||||
|
``` |
||||
|
|
||||
|
### Ubuntu 18.04 + |
||||
|
|
||||
|
> 原来设置 `/etc/network/interfaces` 的方法还可以用,只是设置的dns没有用 |
||||
|
> 新的配置使用 netplan 管理 |
||||
|
|
||||
|
#### 修改配置文件 |
||||
|
|
||||
|
> 编辑 `/etc/netplan/`下的yaml文件 |
||||
|
> |
||||
|
> 这里文件名是 `01-network-manager-all.yaml` |
||||
|
|
||||
|
```bash |
||||
|
sudo vi /etc/netplan/01-network-manager-all.yaml |
||||
|
|
||||
|
# 注释掉 renderer:NetworkManager |
||||
|
|
||||
|
network: |
||||
|
version: 2 |
||||
|
ethernets: |
||||
|
# 网络名 |
||||
|
enp0s3: |
||||
|
# 一个ip数组,用 ‘,’ 隔开 |
||||
|
addresses: [10.8.40.119/24] |
||||
|
# 使用dhcp 动态获取ip: true/no |
||||
|
dhcp4: no |
||||
|
# ipv4 网关 |
||||
|
gateway4: 192.168.0.1 |
||||
|
# dns |
||||
|
nameservers: |
||||
|
addresses: [114.114.114.114] |
||||
|
search: [localdomain] |
||||
|
optional: true |
||||
|
|
||||
|
# 立即生效 |
||||
|
sudo netplan apply |
||||
|
``` |
||||
|
|
||||
|
### 补充 |
||||
|
|
||||
|
#### 查看网关 |
||||
|
|
||||
|
```bash |
||||
|
# 查看网关 |
||||
|
netstat -rn |
||||
|
# 或 |
||||
|
route -n |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
#### 设置默认网关 |
||||
|
``` bash |
||||
|
route add default gw 10.8.30.1 |
||||
|
``` |
||||
|
|
||||
|
#### 重启网关 |
||||
|
``` bash |
||||
|
/etc/init.d/networking restart |
||||
|
``` |
||||
|
|
||||
|
### 配置 `/etc/resolv.conf` |
||||
|
> 以上配置完成就可以了 |
||||
|
> 如果是desktop 版本可能设置的dns不能使 /etc/resolv.conf生效. 重启又恢复到默认 |
||||
|
|
||||
|
#### 安装 resolvconf 服务 |
||||
|
|
||||
|
```bash |
||||
|
sudo apt-get update |
||||
|
sudo apt-get install resolvconf |
||||
|
``` |
||||
|
|
||||
|
#### 配置 resolvconf |
||||
|
|
||||
|
> 修改 /etc/resolvconf/resolv.conf.d/head |
||||
|
|
||||
|
```bash |
||||
|
vi /etc/resolvconf/resolv.conf.d/head |
||||
|
# 增加 |
||||
|
nameserver 223.5.5.5 |
||||
|
nameserver 223.6.6.6 |
||||
|
``` |
||||
|
|
||||
|
> 保存退出,执行 |
||||
|
|
||||
|
```bash |
||||
|
resolvconf -u |
||||
|
``` |
||||
|
|
||||
|
> 查看 /etc/resolv.conf, 重启再看 |
||||
|
|
||||
|
```bash |
||||
|
cat /etc/resolv.conf |
||||
|
``` |
||||
|
|
||||
|
## CentOS |
||||
|
|
||||
|
> |
||||
|
>配置文件在 `/etc/sysconfig/network-scripts ` 下 |
||||
|
> |
||||
|
>这里测试机文件名为:ifcfg-enp0s3 |
||||
|
> |
||||
|
>修改 ifcfg-enp0s3 文件 |
||||
|
|
||||
|
```bash |
||||
|
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 |
||||
|
``` |
||||
|
|
||||
|
> 默认配置 |
||||
|
|
||||
|
```bash |
||||
|
TYPE=Ethernet |
||||
|
PROXY_METHOD=none |
||||
|
BROWSER_ONLY=no |
||||
|
BOOTPROTO=dhcp |
||||
|
DEFROUTE=yes |
||||
|
IPV4_FAILURE_FATAL=no |
||||
|
IPV6INIT=yes |
||||
|
IPV6_AUTOCONF=yes |
||||
|
IPV6_DEFROUTE=yes |
||||
|
IPV6_FAILURE_FATAL=no |
||||
|
IPV6_ADDR_GEN_MODE=stable-privacy |
||||
|
NAME=enp0s3 |
||||
|
UUID=64a31304-95d8-4ab6-961e-8d5db92f8cc0 |
||||
|
DEVICE=enp0s3 |
||||
|
ONBOOT=no |
||||
|
``` |
||||
|
|
||||
|
> 修改为 |
||||
|
|
||||
|
```bash |
||||
|
TYPE=Ethernet |
||||
|
PROXY_METHOD=none |
||||
|
BROWSER_ONLY=no |
||||
|
#BOOTPROTO=dhcp |
||||
|
DEFROUTE=yes |
||||
|
IPV4_FAILURE_FATAL=no |
||||
|
IPV6INIT=yes |
||||
|
IPV6_AUTOCONF=yes |
||||
|
IPV6_DEFROUTE=yes |
||||
|
IPV6_FAILURE_FATAL=no |
||||
|
IPV6_ADDR_GEN_MODE=stable-privacy |
||||
|
NAME=enp0s3 |
||||
|
UUID=64a31304-95d8-4ab6-961e-8d5db92f8cc0 |
||||
|
DEVICE=enp0s3 |
||||
|
#ONBOOT=no |
||||
|
|
||||
|
#static assignment |
||||
|
NM_CONTROLLED=no |
||||
|
ONBOOT=yes |
||||
|
BOOTPROTO=static |
||||
|
IPADDR=192.168.0.116 |
||||
|
NETMASK=255.255.255.0 |
||||
|
GATEWAY=192.168.0.1 |
||||
|
|
||||
|
``` |
||||
|
|
||||
|
|
||||
|
|
||||
|
> 修改/etc/sysconfig/network |
||||
|
|
||||
|
> 默认为空 |
||||
|
|
||||
|
```bash |
||||
|
# Created by anaconda |
||||
|
NETWORKING=yes |
||||
|
GATEWAY=192.168.0.1 |
||||
|
DNS1=114.114.114.114 |
||||
|
``` |
||||
|
|
||||
|
> 重启服务 |
||||
|
|
||||
|
```bash |
||||
|
service network restart |
||||
|
``` |
||||
|
|
Binary file not shown.
@ -0,0 +1,83 @@ |
|||||
|
--- |
||||
|
title: VIM 编辑器 |
||||
|
date: 2020-10-18 |
||||
|
categories: |
||||
|
- linux |
||||
|
tags: [linux] |
||||
|
--- |
||||
|
|
||||
|
|
||||
|
## VIM 文本编辑器 |
||||
|
> 一般 `linux` 系统上默认都会安装 `vim` 文本编辑器。 |
||||
|
|
||||
|
|
||||
|
|
||||
|
## 快捷操作 |
||||
|
|
||||
|
### 批量添加注释 |
||||
|
|
||||
|
> 有两种方法: |
||||
|
|
||||
|
#### 使用可视模式 |
||||
|
|
||||
|
##### 注释 |
||||
|
|
||||
|
1. 按 **`Ctrl+ v`** 进入块选择模式, |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191058873.png) |
||||
|
|
||||
|
|
||||
|
2. 然后移动光标选中你要注释的行, |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191059608.png) |
||||
|
|
||||
|
|
||||
|
3. 再按大写的 **`I`** 进入首行插入模式,输入注释符号比如 `#`, |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191059940.png) |
||||
|
|
||||
|
|
||||
|
4. 输入完成后,按 **两下** `ESC`, vim 会自动将你选中的行都加上注释,保存退出 |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191059429.png) |
||||
|
|
||||
|
|
||||
|
##### 取消注释 |
||||
|
|
||||
|
1. **`Ctrl + v`** 进入块选择模式, |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191100130.png) |
||||
|
|
||||
|
2. 选中你要删除的行首的注释符号, |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191100634.png) |
||||
|
|
||||
|
3. 选好之后按 **d** 即可删除注释,**ESC** 保存退出。 |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191100231.png) |
||||
|
|
||||
|
|
||||
|
|
||||
|
#### 使用替换命令 |
||||
|
|
||||
|
##### 注释 |
||||
|
|
||||
|
使用下面命令在指定的行首添加注释。 |
||||
|
|
||||
|
使用名命令格式: **`:起始行号,结束行号s/^/注释符/g`** |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191101730.png) |
||||
|
|
||||
|
|
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191101021.png) |
||||
|
|
||||
|
##### 取消注释 |
||||
|
|
||||
|
使用名命令格式: **`:起始行号,结束行号s/^注释符//g`** |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191101890.png) |
||||
|
|
||||
|
![](https://cdn.jsdelivr.net/gh/vinloong/imgchr@latest/notes/img/202201191101210.png) |
||||
|
|
||||
|
|
Binary file not shown.
Loading…
Reference in new issue