Linux系统禁用交换分区

Kubernetes集群为了不影响性能要禁用交换分区。

查看交换区信息

$ swapon --show

临时禁用 /proc/swaps 中的交换分区(系统重启后会失效)

$ sudo swapoff -a

启用 /etc/fstab 中的所有交换区

$ sudo swapon -a

禁用交换分区(系统重启后也有效)

$ sudo sed -i '/swap/s/^/#/' /etc/fstab

查看是否禁用交换分区(什么也不显示代表成功)

$ swapon

参考资料

Linux系统DNS设置

之前在文件/etc/resolv.conf中设置了,过段时间总是自动恢复默认值。(注释中写的很详细,是不可编辑的由系统自动生成的文件)

/etc/resolv.conf # This file is managed by man:systemd-resolved(8). Do not edit. # # This is a dynamic resolv.conf file for connecting local clients to the # internal DNS stub resolver of systemd-resolved. This file lists all # configured search domains. # # Run "resolvectl status" to see details about the uplink DNS servers # currently in use. # # Third party programs must not access this file directly, but only through the # symlink at /etc/resolv.conf. To manage man:resolv.

Linux系统上修改用户名

今天同事安装了一台新的服务器Ubuntu20.04,但用户名和主机名不是我想要的,这里尝试了直接修改Linux文件的方式。

登录root用户

$ su - root

修改用户信息

/etc/passwd

# nano /etc/passwd
username:x:1000:1000:username:/home/username:/bin/bash

/etc/shadow

# nano /etc/shadow
username:D78/D2/DdYW.FVG.GlqDlZsZ4sK21gSxhDooqWlJtCVl3oUbDUTKtGxBWkCE3E/Oha40kjDrk0pBbsvT4TwtzuH61vYmnJ/GY.bAHWbVv1:18545:0:99999:7:::

/etc/group

# nano /etc/group
adm:x:4:syslog,username
cdrom:x:24:username
sudo:x:27:username
dip:x:30:username
plugdev:x:46:username
lxd:x:116:username
username:x:1000:

修改HOME路径

# mv /home/old_username /home/new_username

修改主机名 /etc/hostname # nano /etc/hostname hos

在Ubuntu上安装nvidia-docker2

在 Ubuntu20.04 上安装 nvidia-docker2

配置 apt 仓库(repository)

$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | \
  sudo apt-key add -
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-docker.list

更新安装包的列表

$ sudo apt-get update

安装 nvidia-docker2

$ sudo apt-get install -y nvidia-docker2
  • 安装后可以查看 nvidia runtime 配置
$ nano /etc/docker/daemon.json
{
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}

在Ubuntu上安装Docker

在 Ubuntu20.04 上安装 Docker

安装 Docker

$ curl -fsSL https://get.docker.com | sh -

把用户名(username)加入到 docker 组,这样以后在非 root 用户下不用每次操作都 sudo

$ sudo usermod -aG docker username

需要退出用户会话,重新登录方可生效。

卸载Docker

  • 删除Docker及其依赖
$ sudo apt-get remove --auto-remove docker
  • 删除所有数据
$ sudo rm -rf /var/lib/docker

基于Apt-Cacher NG创建本地Ubuntu存储库

安装 Apt-Cacher-NG

$ sudo apt install apt-cacher-ng
$ sudo systemctl enable apt-cacher-ng
$ sudo service apt-cacher-ng start

配置

$ sudo nano /etc/apt-cacher-ng/acng.conf
  • CacheDir: /var/cache/apt-cacher-ng
  • LogDir: /var/log/apt-cacher-ng

查看缓存目录的数据

$ du -sh /var/cache/apt-cacher-ng/
19M	/var/cache/apt-cacher-ng/

客户端配置

$ sudo nano /etc/apt/apt.conf.d/00aptproxy
Acquire::http::Proxy "http://172.16.33.157:3142";

安装软件

$ sudo apt install nodejs

参考资料 使用apt-cacher-ng的快速Debian/Ubuntu軟件包緩存代理設置 使用“ apt-cacher”设置“ apt-cache”服务器 使用 apt-mir

Welcome to Jekyll!

You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated.

Jekyll requires blog post files to be named according to the following format:

YEAR-MONTH-DAY-title.MARKUP

Where YEAR is a four-digit number, MONTH and DAY are both two-digit numbers, and MARKUP is the file extension representing the format used in the file. After that, include the necessary front matter.