本文最后更新于 2025年11月19日 晚上
修改主机名称
1 2 3 4 5 6 7 8 9 10 11 12 13
| hostname 新的主机名
echo "新的主机名" > /etc/hostname
vi /etc/hosts
127.0.0.1 localhost 新的主机名 ::1 localhost 新的主机名
rc-service hostname restart
|
更新软件包
1
| apk update && apk upgrade
|
修改ssh端口号
1.修改配置文件
找到#Port 22这一行,取消注释并修改为其他端口号
2.重启ssh生效
开启密钥登录
1.生成密钥对
1
| ssh-keygen -t rsa -b 2048
|
一路enter跳过即可,会在/root/.ssh下生成公钥id_rsa.pub和私钥id_rsa (公钥是用于服务器端,私钥是用于客户端) 然后将私钥id_rsa下载至电脑上(登录时会用到)
2.将公钥添加到 authorized_keys
1 2 3
| cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
|
3.修改配置文件
1 2 3 4 5
| vi /etc/ssh/sshd_config
PubkeyAuthentication yes PasswordAuthentication no
|
3.重启ssh生效
安装nginx
1. 更新软件包索引
首先,确保你的包管理器中的索引是最新的:
2. 安装 Nginx
3. 启动 Nginx
4. 设置 Nginx 开机自启
为了让 Nginx 在系统启动时自动运行,可以使用以下命令:
5. 配置 Nginx
Nginx 的配置文件通常位于 /etc/nginx/nginx.conf。你可以根据需要编辑此文件:
1
| vi /etc/nginx/nginx.conf
|
6. 测试 Nginx 配置
在修改配置文件后,建议测试 Nginx 配置文件是否正确:
7. 重启 Nginx
如果一切正常,重启 Nginx 以应用新的配置:
1
| rc-service nginx restart
|
创建启动脚本设置开机自启
以XrayR为例
1. 编辑或创建 XrayR 的启动脚本
首先确保 XrayR 的启动脚本位于 /etc/init.d/ 目录下。如果没有现成的启动脚本,你可以创建一个:
添加以下内容作为 XrayR 的启动脚本示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
name="XrayR" description="XrayR Server" command="/etc/XrayR/XrayR" command_args="--config /etc/XrayR/config.yml > /dev/null 2>&1" pidfile="/var/run/XrayR.pid" command_background=true
depend() { need net after nginx after frps }
start_pre() { sleep 30 }
|
修改 command 为 XrayR 二进制文件的正确路径。
修改 command_args 为你 XrayR 的配置文件路径。
2. 设置脚本权限
确保启动脚本有可执行权限:
1
| chmod +x /etc/init.d/XrayR
|
3. 添加开机启动
将 XrayR 添加到系统启动项中:
1
| rc-update add XrayR default
|
4. 测试脚本
为了确保脚本工作正常,可以立即手动启动服务:
通过这一步,你可以验证XrayR是否能够成功启动,以及是否有正确的延迟。
安装docker和docker compose
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| apk update && apk upgrade
apk add docker
rc-update add docker boot
service docker start
docker version
apk add docker-compose
docker-compose version
|
更换国内软件源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| 1. 备份原有源 cp /etc/apk/repositories /etc/apk/repositories.bak
2. 编辑源文件 vi /etc/apk/repositories
3. 查看系统版本号 cat /etc/alpine-release
4. 更换默认源(注意修改版本号)
https://mirrors.aliyun.com/alpine/v3.19/main https://mirrors.aliyun.com/alpine/v3.19/community
https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.19/main https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.19/community
https://mirrors.ustc.edu.cn/alpine/v3.19/main https://mirrors.ustc.edu.cn/alpine/v3.19/community
5.更新索引 apk update
|