安全

绝对不推荐直接使用 root 账号登录生产服务器进行部署。这是运维安全中的一条重要红线。
即使你是拥有最高权限的管理员,正确的做法也应该是使用一个拥有 sudo 权限的个人管理员账号来登录和操作。

以下是行业标准的、遵循“最小权限原则”的管理员操作流程:

创建你的个人管理员账号 在你刚配置好的新服务器上,第一件事就是为你自己(或其他管理员)创建一个普通的个人账号,并赋予其 sudo 权限。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# 1. 以 root 身份登录 (仅限这一次初始化配置)
# 2. 创建你的个人账号,例如 "admin_user"
adduser admin_user

# 3. 将这个新账号添加到 sudo 或 wheel 组,使其能使用 sudo 命令
#    - 在 Debian/Ubuntu 系统上,组名通常是 "sudo"
usermod -aG sudo admin_user

#    - 在 CentOS/RHEL 系统上,组名通常是 "wheel"
usermod -aG wheel admin_user

安装列表

  • Docker

Docker

参考Docker CE镜像

CentOS7

 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
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils

# Step 2: 添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# Step 3: 安装Docker
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Step 4: 开启Docker服务
sudo service docker start
sudo systemctl enable docker

# 注意:
# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。
# vim /etc/yum.repos.d/docker-ce.repo
#   将[docker-ce-test]下方的enabled=0修改为enabled=1
#
# 安装指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
# yum list docker-ce.x86_64 --showduplicates | sort -r
#   Loading mirror speeds from cached hostfile
#   Loaded plugins: branch, fastestmirror, langpacks
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable
#   docker-ce.x86_64            17.03.1.ce-1.el7.centos            @docker-ce-stable
#   docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable
#   Available Packages
# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
# sudo yum -y install docker-ce-[VERSION]

配置

1、编辑 /etc/docker/daemon.json 文件

1
2
3
4
5
6
7
8
{
  "registry-mirrors": [
    "https://mirror.ccs.tencentyun.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://registry.docker-cn.com",
    "https://vfs1y0dl.mirror.aliyuncs.com"
  ]
}

2、重启

1
2
sudo systemctl daemon-reload
sudo service docker restart

Docker compose

参考

示例

1
sudo curl -L "https://github.com/docker/compose/releases/download/v2.28.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Git

CentOS

1
yum install -y git

SSH

1
2
# -t 指定类型为 ed25519 (现代且安全),-C 是注释,通常用邮箱
ssh-keygen -t ed25519 -C "your_email@example.com"

一路按回车键,它会在你的家目录下的 .ssh 文件夹里生成两个文件:

id_ed25519:私钥。绝对不能泄露给任何人! 留在你的电脑上。

id_ed25519.pub:公钥。这个是用来放到服务器上的。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ ssh-keygen -t ed25519 -C "finnley@einscat.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/finnley/.ssh/id_ed25519):
Created directory '/home/finnley/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/finnley/.ssh/id_ed25519.
Your public key has been saved in /home/finnley/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:J8s7/VmdhqpW28l76DOAZPA61AS3IGIukzyiKspoG18 finnley@einscat.com
The key's randomart image is:
+--[ED25519 256]--+
|   o . o..       |
|. + . ..o..      |
|.* .    =.       |
|o +    . =       |
|.     . S o      |
|.      + = o  ...|
|o.   E  +.. =.+o.|
|=.o .   .o...X.. |
|+o..    oo.o+o=  |
+----[SHA256]-----+
[finnley@VM-0-2-centos shared]$

相关设置

  • gitee
  • github
  • 将https替换为ssh
    1
    2
    
    # 将 xxx 替换为你的 GitHub 用户名
    git remote set-url origin git@github.com:xxx/repo.git
    

jq

CentOS

1
yum install -y jq

yq

参考