系统安装ubuntu
ubuntu下载地址
注意:如果是虚拟机,确认硬盘已挂载;物理机避免选错硬盘(会清空数据)。
1、手动删除自动光盘安装的盘符
注意:如果是要手动安装系统,修改网卡名称,则要删除自动安装的光盘;不然系统会自动安装;
2、在内核里修改网卡名
按F6进入其他选项:
选择专家模式后,按ESC键退出后在命令行界面修改网卡名称:
net.ifnames=0 biosdevname=0
3、系统自动安装完成后操作
首先给宿主机联网,虚拟机ubuntu设置为nat连接方式(桥接连接方式也可以),ubuntu就可以正常上网。
后边的安装选择安装openssl,其他的不安装,都选择默认;IP地址可以选择手动配置一个,也可以默认dhcp自动分配;等系统安装完毕,这个过程可能稍微有点漫长,耐心等待安装完毕后重启机器做初始化相应的设置;
执行如下命令:
sudo apt-get update #联网更新此过程时间可能有点长
4、安装openssl
安装后优先更新系统、确认 SSH 可用,避免后续基础问题。
sudo apt-get install openssh-server
ps -ef |gerp ssh #查看ssh服务,如果看到,说明sshd成功,然后就可以在其他地方用ssh远程登录了。
sudo systemctl enable --now ssh # 设置开机自启
初始化环境安装好后,拍快照保留初始环境,以便下次恢复干净环境;
系统安装完初始环境设置
1、设置root密码
sudo su
# 用普通用户名密码首次登陆root目录修改设置root
passwd
#设置好root密码
2、设置root远程登录xshell
#设置允许远程xshell登录时root直接登录
apt install vim
root@elwyn:~# vim /etc/ssh/sshd_config
PermitRootLogin yes
UseDNS no
3、修改网卡名
root@zhang:/home/zhang# vim /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
root@zhang:~# update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/50-curtin-settings.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-54-generic
Found initrd image: /boot/initrd.img-4.15.0-54-generic
done
root@zhang:/home/zhang# vim /etc/network/interfaces
auto eth0
iface eth0 inet dhcp
root@zhang:/home/zhang# sudo apt install ifupdown
网络问题:如果 DHCP 没获取到 IP,检查路由器 DHCP 是否开启,或手动配置静态 IP。
暂时不需要改
给服务器配置外网IP:
#修改为静态IP:
root@elwyn:~# vim /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
# sudo apt install ifupdown
auto eth0
iface eth0 inet dhcp
#address 14.17.65.109 #IP
#netmask 255.255.255.0 #子网
#gateway 14.17.65.65 #网关
#dns-nameservers 114.114.114.114 8.8.8.8 #这里设置了两个DNS
#重启网卡生效:
sudo /etc/init.d/networking restart
暂时不做修改
# 修改服务器的DNS(这里不需要操作,因为上面网卡IP配置文件中设置了DNS):
vim /etc/resolvconf/resolv.conf.d/base
# 增加:
search localdomain #如果服务器做专门的DNS服务器,可以加上这一句,如果不是就不加,一般不用加
nameserver 114.114.114.114 # 国内通用
nameserver 233.5.5.5 # 阿里
nameserver 8.8.8.8 #谷歌
# 重启网络和DNS后生效:
sudo /etc/init.d/networking restart
sudo /etc/init.d/resolvconf restart
4、更换阿里源
# 更换镜像源为阿里源
https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.3e221b11hDl7dS
/etc/apt/sources.list
root@elwyn:~# vim /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
5、系统版本升级
root@elwyn:~# cat /etc/issue
Ubuntu 18.04.2 LTS \n \l
root@elwyn:~# apt-get --help
apt 1.6.8 (amd64)
Usage: apt-get [options] command
apt-get [options] install|remove pkg1 [pkg2 ...]
apt-get [options] source pkg1 [pkg2 ...]
apt-get is a command line interface for retrieval of packages
and information about them from authenticated sources and
for installation, upgrade and removal of packages together
with their dependencies.
Most used commands:
update - Retrieve new lists of packages
upgrade - Perform an upgrade #更新升级系统版本到最新版本
install - Install new packages (pkg is libc6 not libc6.deb)
remove - Remove packages
purge - Remove packages and config files
autoremove - Remove automatically all unused packages
dist-upgrade - Distribution upgrade, see apt-get(8)
dselect-upgrade - Follow dselect selections
build-dep - Configure build-dependencies for source packages
clean - Erase downloaded archive files
autoclean - Erase old downloaded archive files
check - Verify that there are no broken dependencies
source - Download source archives
download - Download the binary package into the current directory
changelog - Download and display the changelog for the given package
See apt-get(8) for more information about the available commands.
Configuration options and syntax is detailed in apt.conf(5).
Information about how to configure sources can be found in sources.list(5).
Package and version choices can be expressed via apt_preferences(5).
Security details are available in apt-secure(8).
This APT has Super Cow Powers.
root@elwyn:~# apt-get upgrade
#可以更新到最新的系统版本
6、最小化安装的命令
root@elwyn:~# apt-get install -y iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev gcc rpcbind unzip zip
7、配置静态IP地址
# 众所周知,ubuntu desktop配置静态IP地址是修改配置文件/etc/network/interfaces。然而,修改这个文件对ubuntu server没有效果。
# ubuntu server 18.04静态IP地址配置方法如下:
vim /etc/netplan/50-cloud-init.yaml
# yaml是一种通用配置文件格式,规定不能出现tab符号,修改时要注意这点。eth0是绑定静态IP的网卡,步骤如下:
1. dhcp4由true改为false
2. addresses填写你的静态IP地址(带掩码段位)
3. 增加gateway4,填写你的gateway。
4. nameservers,114.114.114.114,223.5.5.5是DNS服务器,最好填写两个,有时一个解析不出来。
5. 执行命令netplan apply立即生效。
8、修改主机用户名
#修改主机用户名hostname
zhang@zhang:~$ sudo vim /etc/hostname
docker1
# Ubuntu在以前的发行版本中,直接修改/etc/hostname中的文本内容就可以完成主机名的修改。但在Ubuntu18.04版本中,好像不再生效,重启后会恢复为原先设置的主机名
18.04版本下的修改方法如下:
root@zhang:~# vim /etc/cloud/cloud.cfg
preserve_hostname #开关设置为true
root@zhang:~# vim /etc/hostname
修改主机名
# 重启机器,完成主机名称的修改
# 临时修改主机名
命令行下运行命令:“hostname 新主机名”
终端下不会立即显示生效后的主机名,重开一个终端窗口(通过ssh连接的终端需要重新连接才可以);
修改成功