Skip to content

Ubuntu 装机指南

Guang Chen edited this page Apr 20, 2018 · 13 revisions

Ubuntu 装机指南

本文适用对象: SA

安装

按照安装说明即可。请注意如果RAID或LVM尝试失败,则务必不要浪费时间,使用默认的LVM分区即可。稍后可手动添加硬盘到LVM group中.

安装时注意在选择软件时要使用空格选择openssh

网络

dhcp

auto eth0
iface eth0 inet dhcp

注意把eth0换成实际的网卡名

static

auto eth0
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx
dns-nameservers xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx

ssh

  1. 首先添加ssh public key, 在$HOME下创建.ssh目录,并在.ssh目录中添加authorized_keys文件,文件内容为ssh public key.
  2. 测试此时ssh登陆是否需要密码
  3. 用root权限编辑/etc/ssh/sshd_config,找到# PasswordAuthentication yes改为PasswordAuthentication no
  4. sudo service ssh restart,并在没有key的机器上尝试登陆,应当显示Permission denied (publickey).

用户

添加用户

sudo adduser username

添加到sudo用户组

sudo adduser username sudo

注意,由于禁止了密码登陆,需要为该用户添加.ssh/authorized_keys, 添加时务必先sudo su username切换到该用户

换源(14.04)

校内tuna源v4

deb http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty main restricted
deb-src http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty main restricted
deb http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty-updates main restricted
deb-src http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty-updates main restricted
deb http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty universe
deb-src http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty universe
deb http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty-updates universe
deb-src http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty-updates universe
deb http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty multiverse
deb-src http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty multiverse
deb http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty-updates multiverse
deb-src http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty-updates multiverse
deb http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty-backports main restricted universe multiverse
deb-src http://mirrors.4.tuna.tsinghua.edu.cn/ubuntu trusty-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse

tuna v6

deb http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty main restricted
deb-src http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty main restricted
deb http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty-updates main restricted
deb-src http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty-updates main restricted
deb http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty universe
deb-src http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty universe
deb http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty-updates universe
deb-src http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty-updates universe
deb http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty multiverse
deb-src http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty multiverse
deb http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty-updates multiverse
deb-src http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty-updates multiverse
deb http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty-backports main restricted universe multiverse
deb-src http://mirrors.6.tuna.tsinghua.edu.cn/ubuntu trusty-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse

北交大ipv6

deb http://mirror.bjtu.edu.cn/ubuntu/ trusty main restricted
deb-src http://mirror.bjtu.edu.cn/ubuntu/ trusty main restricted
deb http://mirror.bjtu.edu.cn/ubuntu/ trusty-updates main restricted
deb-src http://mirror.bjtu.edu.cn/ubuntu/ trusty-updates main restricted
deb http://mirror.bjtu.edu.cn/ubuntu/ trusty universe
deb-src http://mirror.bjtu.edu.cn/ubuntu/ trusty universe
deb http://mirror.bjtu.edu.cn/ubuntu/ trusty-updates universe
deb-src http://mirror.bjtu.edu.cn/ubuntu/ trusty-updates universe
deb http://mirror.bjtu.edu.cn/ubuntu/ trusty multiverse
deb-src http://mirror.bjtu.edu.cn/ubuntu/ trusty multiverse
deb http://mirror.bjtu.edu.cn/ubuntu/ trusty-updates multiverse
deb-src http://mirror.bjtu.edu.cn/ubuntu/ trusty-updates multiverse
deb http://mirror.bjtu.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirror.bjtu.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse

安装docker

添加docker的gpg key

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

如果keyserver被墙需要添加代理参数

--keyserver-options http-proxy=http://host:port/

编辑/etc/apt/sources.list.d/docker.list,将其内容设置为tuna的镜像源(http://mirrors.tuna.tsinghua.edu.cn/help/#docker)

# ubuntu 14.04
deb https://mirrors.tuna.tsinghua.edu.cn/docker/apt/repo ubuntu-trusty main

安装docker

sudo apt-get install docker-engine

安装docker-compose

install pip

sudo apt-get install python-pip

install docker-compose

sudo pip install -U docker-compose

LVM

首先将新的硬盘格式化, 例如:

cgcgbcbc@IBM:/dev$ ls sd*
sda  sda1  sda2  sda3  sdb

这里的sda是我们安装系统的物理卷, sdb是另外一盘硬盘,我们首先查看当前系统的文件格式:

cgcgbcbc@IBM:/dev$ sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
NAME                      FSTYPE        SIZE MOUNTPOINT LABEL
sda                                     1.8T            
|-sda1                    vfat          512M /boot/efi  
|-sda2                    ext2          244M /boot      
`-sda3                    LVM2_member   1.8T            
  |-IBM--vg-root (dm-0)   ext4          1.8T /          
  `-IBM--vg-swap_1 (dm-1) swap            4G [SWAP]   

现有硬盘的格式是ext4,我们将新硬盘也格式化为ext4:

cgcgbcbc@IBM:/dev$ sudo mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (4-Feb-2014)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
122101760 inodes, 488378646 blocks
24418932 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
14905 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done       

初始化:sudo pvcreate /dev/sdb

# 通过 sudo lvm 进入lvm shell中.
lvm> pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created

添加卷:

lvm> vgextend IBM-vg /dev/sdb
  Volume group "IBM-vg" successfully extended

扩大根分区

lvm> lvs
  LV     VG     Attr      LSize Pool Origin Data%  Move Log Copy%  Convert
  root   IBM-vg -wi-ao--- 1.81t                                           
  swap_1 IBM-vg -wi-ao--- 3.99g                                           
lvm> lvextend -l +100%FREE /dev/IBM-vg/root
  Rounding size to boundary between physical extents: 1.81 TiB
  Extending logical volume root to 3.62 TiB
  Logical volume root successfully resized
lvm> lvs
  LV     VG     Attr      LSize Pool Origin Data%  Move Log Copy%  Convert
  root   IBM-vg -wi-ao--- 3.62t                                           
  swap_1 IBM-vg -wi-ao--- 3.99g   

最后, 我们需要sudo resize2fs /dev/IBM-vg/root来刷新文件系统

cgcgbcbc@IBM:~$ df -h
Filesystem                Size  Used Avail Use% Mounted on
/dev/mapper/IBM--vg-root  3.6T  1.7G  3.5T   1% /
none                      4.0K     0  4.0K   0% /sys/fs/cgroup
udev                      2.0G  4.0K  2.0G   1% /dev
tmpfs                     395M  532K  394M   1% /run
none                      5.0M     0  5.0M   0% /run/lock
none                      2.0G     0  2.0G   0% /run/shm
none                      100M     0  100M   0% /run/user
/dev/sda2                 237M   83M  142M  37% /boot
/dev/sda1                 511M  3.4M  508M   1% /boot/efi

参考