Back to prev

ubuntu system use

Jan 31, 2023
Linkang Chan
@Jesse Chan

本文记录在日常使用 ubuntu 或者在镜像中使用时遇到的一些问题,主要是环境配置等等。同时还有各种镜像源和配置的记录。

配置源

  • conda

一个速度比较快一些的 condarc 配置。需要将.condarc放到$HOME下。

$ cat $HOME/.condarc
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  dglteam: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  • pip

临时使用可以通过-i选项完成。

$ pip install rich -i https://pypi.tuna.tsinghua.edu.cn/simple

设置为默认可以通过如下命令完成

$ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

[清华源 pip 配置说明]: pip 清华源配置

apt update 问题

Couldn’t create temporary file /tmp/apt.conf.RpjjUo for passing config to apt-key

这个时候大概率是 tmp 目录的权限不对。使用

$ chmod 1777 /tmp

[stackoverflow]: sudo apt-get update couldn’t create temporary file

apt 的源

  • debian(bullseys)
# 阿里云

deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib

# 腾讯云
deb https://mirrors.tencent.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.tencent.com/debian/ bullseye main non-free contrib
deb https://mirrors.tencent.com/debian-security/ bullseye-security main
deb-src https://mirrors.tencent.com/debian-security/ bullseye-security main
deb https://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib

安装库

一些比较精简的镜像或者系统不会默认安装一些必要的库,此时我们需要手动对其进行安装。

# 安装 ping
$ sudo apt-get install inetutils-ping

# 安装 ifconfig
$ sudo apt-get install net-tools

# 安装 ip
$ sudo apt-get install iproute2 

安装 postgresql 客户端

$ sudo apt-get install -y postgresql-client

Kernel inotify watch limit reached

$ cat /proc/sys/fs/inotify/max_user_watches
8109
$ cat 65535 > /proc/sys/fs/inotify/max_user_watches

[stack exchange]: 相关回答

用户管理

快速去除指定用户的密码:

$ sudo passwd -d ecs-user

快速创建一个用户:

#!/bin/bash
adduser --gecos "" --disabled-password $1 --home /home/$1

passwd -d $1
passwd -e $1
mkdir -p /home/$1/.ssh
echo "$2" >> /home/$1/.ssh/authorized_keys
chmod 0600 /home/$1/.ssh/authorized_keys
chown -R "$1"."$1" /home/$1/.ssh

追加用户到指定的组内

$ sudo usermod -aG docker $USER

检查 minio 是否可用

$ curl -I https://minio.example.net:9000/minio/health/live

挂载硬盘

$ fdisk -l
$ lsblk

$ mkfs -t ext4 /dev/vdb
$ mkdir /x/xx/
$ sudo mount /dev/vdb/ /x/xx/
$ df -h

minio conda install in dockerfile

# change version for what you want
$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py311_23.5.2-0-Linux-x86_64.sh
$ bash Miniconda3-py311_23.5.2-0-Linux-x86_64.sh

获取系统上所有用户的所属组

$ cut -d: -f1 /etc/passwd | xargs -n1 groups

inotify_add_watch--failed ‘no space left on device’

echo fs.inotify.max_user_watches=65536 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

[stack exchange]: 相关回答