Linux安装与配置笔记

Linux安装

不同系统安装配置的步骤和难度也不同,但开始安装的前提往往都是包含安装文件的介质,以下两种工具均可将U盘制作为安装介质

以安装简易的Ubuntu系统为例,Ubuntu官网下载系统镜像

Ventoy

介绍:多系统启动U盘解决方案

使用官网

下载软件安装到U盘,将系统镜像拷贝进U盘,将U盘插入主机

开机按esc(或对应键)进入BIOS,选择U盘为启动项启动,进入Ventoy

选择对应镜像进入,并根据提示一步步安装Ubuntu

UltraISO

介绍:光盘映像文件相关工具

使用官网

下载安装软件(试用即可,若不行可用破解版)

文件-打开中选择系统镜像文件,打开

启动-写入硬盘镜像中选择硬盘驱动器为U盘,写入

将U盘插入主机,开机按esc(或对应键)进入BIOS,选择U盘为启动项启动,根据提示安装Ubuntu

系统设置

Curl

介绍:用于请求Web服务器的命令行工具,许多安装脚本会用到该工具

使用文档 用法指南

1
2
# 安装命令
sudo apt install curl

Vim

介绍:命令行的文本编辑器

使用文档 快速上手

1
2
3
4
5
6
7
8
9
10
11
12
13
# 安装命令
sudo apt install vim
# 打开/创建文件xxx.sh
vim xxx.sh # 打开后默认进入命令模式
i # 进入编辑模式
xxx # 编辑内容
esc # 退出编辑模式
: # 进入底线命令模式
w # 保存文件
q # 退出程序
esc # 退出底线命令模式
ZZ # 保存并退出
ZQ # 不保存强制退出

Zerotier

介绍:在不同终端之间建立虚拟局域网

使用官网 文档 同类软件Tailscale

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 官网注册登录创建网络获取 Network ID:xxxxxxxxxxxxxxxx
# 安装命令
curl -s https://install.zerotier.com | sudo bash
# 检查终端信息
sudo zerotier-cli info
# 加入网络 xxxxxxxxxxxxxxxx
zerotier-cli join xxxxxxxxxxxxxxxx # 加入后需在网页启用
# 确认加入成功
zerotier-cli listnetworks # 如不成功会显示 Access Denied
# 配置文件位置
cd /var/lib/zerotier-one
# 进阶配置
zerotier-cli -h # 查看help信息,以下是一些可更改的'SettingID'
allowManaged=1 # 管理地址
allowGlobal=0 # Assignment of Global IPs
allowDefault=0 # 默认路由代理
allowDNS=0 # DNS配置

1Panel

介绍:服务器面板

使用官网 文档 安装脚本

1
2
3
4
# 安装命令,不同系统可点击 安装脚本 链接复制脚本
curl -sSL https://resource.fit2cloud.com/1panel/package/quick_start.sh -o quick_start.sh && sudo bash quick_start.sh
# 注意根据终端输出的信息进行初始化设置
# 如未安装 ssh 需手动安装 sudo apt install ssh

以下脚本可添加至计划任务来监测网络情况(用于解决网络连接偶尔断开):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

# 设置选定 Wi-Fi 的 SSID ,应当连接成功过且已保存密码
SSID='ZJUWLAN-Secure'

# 检查网络连接情况
ping -q -c 3 baidu.com > /dev/null

if [ $? -eq 0 ]
then
echo "网络连接正常"
# 将输出重定向到日志文件中,并添加时间戳
echo "$(date '+%Y-%m-%d %H:%M:%S') 网络连接正常" >> /home/wifi.log
else
echo "网络已断开,正在尝试重新连接..."
# 将输出重定向到日志文件中,并添加时间戳
echo "$(date '+%Y-%m-%d %H:%M:%S') 网络已断开,正在尝试重新连接..." >> /home/wifi.log
# 重启网络设备并打开 Wi-Fi
sudo systemctl restart NetworkManager
nmcli radio wifi on
sleep 5
# 连接指定的 Wi-Fi
nmcli device wifi connect $SSID
fi

Docker

介绍:容器

使用文档 快速上手

1
2
3
4
5
6
7
8
9
10
11
# 在安装 1Panel 面板时会自动安装,如需手动安装可采用以下步骤
# 首先,更新软件包索引,并且安装必要的依赖软件,来添加一个新的 HTTPS 软件源
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# 使用下面的 curl 导入源仓库的 GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 将 Docker APT 软件源添加到系统:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# 安装 docker 最新版本
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
1
2
3
4
5
6
7
8
9
10
11
# 启动/停止/删除编号为xxx的容器
sudo docker start/stop/rm xxx
# 查看正在运行的容器
sudo docker ps # -a 则查看所有容器
# docker-compose
# 创建并启动 docker-compose
sudo docker-compose up -d
# 停止 docker-compose
sudo docker-compose stop
# 手动更新
sudo docker-compose pull && docker-compose up -d

grub

新的Ubuntu系统可能启动时不显示grub,可通过以下设置使其显示

1
2
3
4
5
6
7
8
# 修改 grub 文件
sudo vim /etc/default/grub
# 1. 若有,将GRUB_TIMEOUT_STYLE=hidden前加#注释掉 或=后改为menu
# 2. 将GRUB_TIMEOUT=0中0改为3
# 3. 将GRUB_CMDLINE_LINUX_DEFAULT=“quiet splash”的值改为text
# 其中3的目的是使开机同时输出进度,可不更改
# 保存后更新grub
sudo update-grub

shell proxy

设置终端代理以解决终端无法访问GitHub的问题

1
2
3
4
5
6
7
8
# 编辑 .bashrc文件
vim ~/.bashrc
# 在文件末尾加入以下内容,或可从Clash中复制
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
# 保存后更新配置
source ~/.bashrc

软件配置

qBittorrent

介绍:BT软件

使用官网

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 主机安装 qbittorrent-nox ,安装后可通过默认端口 8080 和账户 admin 密码 adminadmin 进行访问和配置
sudo apt install qbittorrent-nox
# 设置通过 systemctl 控制
sudo cat >/etc/systemd/system/alist.service <<EOF
[Unit]
Description=qBittorrent-nox
After=network.target network.service

[Service]
ExecStartPre=/bin/sleep 30
ExecStart=/usr/bin/qbittorrent-nox
Type=simple
Restart=on-failure
TimeoutStopSec=10

[Install]
WantedBy=multi-user.target
EOF
# 注:开始前设置30s延迟是为了等待硬盘装载,也可不设置
# 重载systemctl
sudo systemctl daemon-reload
# 启用服务
sudo systemctl enable qbittorrent-nox
# 重启服务
sudo systemctl restart qbittorrent-nox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 以下是 docker-compose 安装的模板
version: "3"
services:
qbittorrent:
image: linuxserver/qbittorrent
container_name: qbittorrent
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai # 你的时区
- UMASK_SET=022
- WEBUI_PORT=8081 # WEB 管理平台端口
volumes:
- /home/qb/config:/config # :前修改为储存配置的文件夹
- /media/username:/downloads # :前修改为挂载磁盘的路径
ports:
# 要使用的映射下载端口与内部下载端口,安装完成后在管理页面的连接中将端口改为下列端口,可自定义修改
- 39873:39873
- 39873:39873/udp
# 此处 WEB UI 目标端口与内部端口务必保证相同
- 8081:8081
restart: unless-stopped

Alist

介绍:支持多种存储的文件列表程序

使用文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 以下是 docker-compose 安装的模板
version: '3.3'
services:
alist:
restart: always
volumes:
- '/etc/alist:/opt/alist/data'
- '/media/uesrname:/media/username' # 挂载磁盘的路径
ports:
- '5244:5244' # WEB 端口
environment:
- PUID=1000
- PGID=1000
- UMASK=022
container_name: alist
image: 'xhofe/alist:latest'
1
2
3
4
5
6
7
# 本地安装
# 一键脚本
curl -fsSL "https://alist.nn.ci/v3.sh" | sudo bash -s install
# 更新脚本
curl -fsSL "https://alist.nn.ci/v3.sh" | sudo bash -s update
# 卸载脚本
curl -fsSL "https://alist.nn.ci/v3.sh" | sudo bash -s uninstall

DDNS-GO

介绍:自动获得公网 IPv4 或 IPv6 地址,并解析到对应的域名服务

使用官网 Callback dynv6

1
2
# 使用docker host模式安装
sudo docker run -d --name ddns-go --restart=always --net=host -v /opt/ddns-go:/root jeessy/ddns-go
1
2
3
4
5
6
7
8
# 以下使用Callback配置IPv6-ddns参考,于dynv6注册账号获取Zones
# 于dynv6点击右上角账户-Keys生成或获取HTTP Token,复制
# 通过以下网址打开配置页面,DNS服务商选择Callback
http://IP:9876
# 在URL一栏中输入如下链接,将domain替换为Zones的值,YOUR_TOKEN替换为Token
https://dynv6.com/api/update?zone=domain&token=YOUR_TOKEN&ipv6=#{ip}
# 下方IPv6栏选启用、通过接口获取,Domains中填写获取的Zones,后点击Save观察日志确认是否成功
# 如果无法通过接口获取可尝试命令获取,如 ip -6 addr show | grep "global dynamic"

Reader

介绍:自建网页看小说

使用文档 书源地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 需要root权限
apt install docker-compose -y
# 下载项目里的 docker-compose.yaml
wget https://ghproxy.com/https://raw.githubusercontent.com/hectorqin/reader/master/docker-compose.yaml
# 根据 docker-compose.yaml 里面的注释编辑所需配置
vim docker-compose.yaml
# 保存
esc
:wq
# 启动 docker-compose
docker-compose up -d
# 停止 docker-compose
docker-compose stop
# 手动更新
docker-compose pull && docker-compose up -d
# 以下为docker-compose.yaml成功例子
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 以下是 docker-compose 安装的模板
version: '3.1'
services:
# reader 在线阅读
# 公开服务器(服务器位于日本):[https://reader.nxnow.top](https://reader.nxnow.top) 测试账号/密码分别为guest/guest123,也可自行创建账号添加书源,不定期删除长期未登录账号(2周)
# 书源集合 : [https://legado.aoaostar.com/](https://legado.aoaostar.com/) 点击打开连接,添加远程书源即可
# 公众号汇总 : [https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MjM5MzMyMDgyMA==&action=getalbum&album_id=2397535253763801090#wechat_redirect](https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MjM5MzMyMDgyMA==&action=getalbum&album_id=2397535253763801090#wechat_redirect)
# 手动更新方式 : docker-compose pull && docker-compose up -d
reader:
image: hectorqin/reader
#image: hectorqin/reader:openj9-latest #docker镜像,arm64架构或小内存机器优先使用此镜像.启用需删除上一行
container_name: reader #容器名 可自行修改
restart: always
ports:
- 4396:8080 #4396端口映射可自行修改
networks:
- share_net
volumes:
- /home/reader/logs:/logs #log映射目录 /home/reader/logs 映射目录可自行修改
- /home/reader/storage:/storage #数据映射目录 /home/reader/storage 映射目录可自行修改
environment:
- SPRING_PROFILES_ACTIVE=prod
- READER_APP_USERLIMIT=50 #用户上限,默认50
- READER_APP_USERBOOKLIMIT=200 #用户书籍上限,默认200
- READER_APP_CACHECHAPTERCONTENT=true #开启缓存章节内容 V2.0
# 如果启用远程webview,需要取消注释下面的 remote-webview 服务
# - READER_APP_REMOTEWEBVIEWAPI=http://remote-webview:8050 #开启远程webview
# 下面都是多用户模式配置
- READER_APP_SECURE=true #开启登录鉴权,开启后将支持多用户模式
- READER_APP_SECUREKEY=adminpwd #管理员密码 建议修改
- READER_APP_INVITECODE=registercode #注册邀请码 建议修改,如不需要可注释或删除
# remote-webview:
# image: hectorqin/remote-webview
# container_name: remote-webview #容器名 可自行修改
# restart: always
# ports:
# - 8050:8050
# networks:
# - share_net
# 自动更新docker镜像
watchtower:
image: containrrr/watchtower
container_name: watchtower
restart: always
# 环境变量,设置为上海时区
environment:
- TZ=Asia/Shanghai
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: reader watchtower --cleanup --schedule "0 0 4 * * *"
networks:
- share_net
# 仅更新reader与watchtower容器,如需其他自行添加 '容器名' ,如:reader watchtower nginx
# --cleanup 更新后清理旧版本镜像
# --schedule 自动检测更新 crontab定时(限定6位crontab) 此处代表凌晨4点整
networks:
share_net:
driver: bridge

ChatGPT-Next-Web

介绍:使用api建立ChatGPT网页服务

使用文档 azure-openai-proxy

1
2
3
4
5
6
7
8
9
# 拉取镜像
docker pull yidadaa/chatgpt-next-web
# 创建docker,sk-xxx为openAI的api
docker run -d --restart=always -p 3000:3000 \
-e OPENAI_API_KEY="sk-xxxx" \
-e CODE="页面访问密码" \
--net=host \
-e PROXY_URL="http://127.0.0.1:7890" \
yidadaa/chatgpt-next-web
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 结合 azure-openai-proxy 的可以使用 Azure 上 openai 服务的 Compose 模板
version: '3'

services:
chatgpt-next-web:
image: yidadaa/chatgpt-next-web
container_name: chatgpt-next-web
ports:
- 3000:3000
environment:
- OPENAI_API_KEY=xxx # Azure 上的 openai-key
- CODE=xxx # 页面访问密码
- BASE_URL=http://azure-openai:8080
depends_on:
- azure-openai
links:
- azure-openai
networks:
- chatgpt-ns

azure-openai:
image: stulzq/azure-openai-proxy
container_name: azure-openai-proxy
ports:
- 8410:8080
environment:
AZURE_OPENAI_ENDPOINT: https://xxx.openai.azure.com/ # 如何设置详见官网
AZURE_OPENAI_MODEL_MAPPER: gpt-3.5-turbo=xxx # 如何设置详见官网
AZURE_OPENAI_API_VER: 2023-03-15-preview
networks:
- chatgpt-ns

networks:
chatgpt-ns:
driver: bridge

code-server

介绍:VS Code的服务器版,可通过网页使用VS Code

使用:项目地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 本地安装
curl -fsSL https://code-server.dev/install.sh | sh
# 配置和使用
# 运行
code-server
# 第一次运行会在创建一个config.yaml配置文件
vim ~/.config/code-server/config.yaml
# 修改配置文件
bind-addr: 0.0.0.0:8848 # IP地址修改为0.0.0.0,8848为端口号
auth: password # 无需修改
passsword: 123456 # 改为你自己的密码
cert: false # 不启用https,如需启用需在cert后填写证书路径,并新开一行cert-key填写密钥路径
# 保存退出
:wq
# 再次运行
code-server # 成功会显示active,按ctrl+C停止
# 配置systemctl使其开机自启
# 创建qbittorrent-nox.service文件
sudo cat >/etc/systemd/system/alist.service <<EOF
[Unit]
Description=code-server
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/code-server
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
EOF
# 重载systemctl
sudo systemctl daemon-reload
# 启用服务
sudo systemctl enable code-server.service
# 重启服务
sudo systemctl restart code-server.service
1
2
3
4
5
6
7
8
9
10
# 非主机网页端使用时由于未配置https会出现无法预览pdf等文件的情况,解决方法有两种
# 第一种
# 浏览器为Edge,在地址栏输入 edge://flags 打开实验性功能
# 搜索Insecure origins treated as secure,将禁用改为启用
# 文本框内输入 http://172.26.56.40:8848 ,也即访问code-server的网址
# 这种方式可将非https的网页看作安全,从而解决问题
# 第二种
# 为服务器配置https,详情可见以下两个网址
# https://blog.csdn.net/whzzz_1/article/details/129212144
# https://blog.csdn.net/weixin_48387678/article/details/124665324

qinglong

介绍:定时任务管理平台

使用官网

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 以下是 docker-compose 安装的模板
version: '3'
services:
web:
# alpine 基础镜像版本
image: whyour/qinglong:latest
# debian-slim 基础镜像版本
# image: whyour/qinglong:debian
volumes:
- ./data:/ql/data
ports:
- "0.0.0.0:5700:5700"
environment:
# 部署路径非必须,以斜杠开头和结尾,比如 /test/
QlBaseUrl: '/'
restart: unless-stopped