前段时间趁着双11打折,又将阿里云主机续费了3年。之前布署的系统是Ubuntu 12.04,从系统发布到现在也有四年半了,其官方支持的生命周期也将止于明年春,且这在几年里出现了很多新的事物,我也需要跟上时代的步伐,于是着手将整个环境更新至最新的Ubuntu 16.04,现将布署过程记录如下
10. 停止服务器实例,选择更换系统盘,选择Ubuntu 16.04 64bit,重启实例
20. 挂载虚拟内存
mkdir /swap && cd /swap && fallocate -l 2g 2GB.swap && mkswap 2GB.swap && swapon 2GB.swap && echo "# # # Swap File # # #" >> /etc/fstab && echo "/swap/2GB.swap none swap sw 0 0" >> /etc/fstab && mount -a
调整内存参数,内存使用超90%时启用虚拟内存
sudo sysctl vm.swappiness=10
打开配置文件
sudo vim /etc/sysctl.conf
将上述参数修改配置文件后,保存
vm.swappiness = 10
How To Add Swap Space on Ubuntu 16.04
Does it make sense to create swap partitions for new installations nowadways?
30.重新挂载阿里云数据盘
echo '/dev/xvdb1 /opt ext4 defaults 0 0' >> /etc/fstab && mount -a
40. 新增个人用户
adduser ljz gpasswd -a ljz sudo
后面的操作使用新用户完成
50. 更新软件源
取消阿里云自带的源代理设置。这会导致大部份国外源的更新失败
sudo vim /etc/apt/apt.conf
注释代理设置
#Acquire::http::Proxy "http://mirrors.aliyun.com/";
查看源设置
sudo vim /etc/apt/sources.list
可以看到,阿里已经帮我将源指向了阿里镜象自己,这也是最快的选择,所以不需要作任何修改
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ xenial-proposed main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ xenial-proposed main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ xenial-backports main restricted universe multiverse
更新软件源
sudo apt update
升级软件
sudo apt upgrade
What is the difference between apt and apt-get?
Debian、Ubuntu 源列表说明(2013-06-07 更新)
PPA也是软件的一个重要来源
60. 解决异常关机后重动时的卡顿
打开引导配置文件
sudo vim /etc/default/grub
增加异常停顿时间参数
GRUB_RECORDFAIL_TIMEOUT=2
保存退出后,更新启动配置
sudo update-grub
How can I force Ubuntu to boot on a stuck boot menu?
Force ubuntu to boot after power failure without user input
70. 安装常用工具
sudo apt install zip unzip screen nmon ne
How to list all the files in a tree (a directory and its subdirs)?
Linux监控工具-Nmon命令行:Linux系统性能的监测利器
80. 让SSH在screen中会话,保证稳定性
vim ~/.profile
在文件最后添加
screen -d -RR
后续都在screen中作业
85. ne设置
Tab Size:4 Tabs as Spaces:on Auto Indent:on ... Save Def Prefs
90. vim设置【不再首选】
sudo vim /etc/vim/vimrc
在打开的文件最后输入下面的内容
set nu
set ai
保存。这样vim显示时就自动显示行号,也能自动缩进了