ubuntu 18.04虚拟机安装
镜像下载地址:
https://releases.ubuntu.com/18.04/ubuntu-18.04.6-live-server-amd64.iso
创建虚拟机[无特殊说明直接下一步]:
配置完成后启动该虚拟机
直接回车
键盘配置
安装SSH服务用于远程连接:
IP设置
配置第二块网卡ens34 :
方法和上面配置的一样,但是网段要改为规划的172
由于都是内网这里就不写网关了
两张网卡的配置:
这里直接回车 done 下一步
软件源:
修改为: http://mirrors.aliyun.com/ubuntu
磁盘分区
常规配置模式与LVM配置模式
正常配置的磁盘部署完成后通过df -h 显示的是
admin1@node03:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 796M 1.2M 795M 1% /run
/dev/sda3 98G 6.0G 87G 7% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda2 190M 79M 98M 45% /boot
tmpfs 796M 0 796M 0% /run/user/1000
LVM方式部署完成后通过df -h 显示的是:
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 796M 1.3M 795M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 98G 6.0G 87G 7% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda2 976M 80M 830M 9% /boot
tmpfs 796M 0 796M 0% /run/user/1000
#LVM企业较为常用,它可以动态扩缩容
常规模式配置硬盘[常规与LVM两者二选一]
创建 boot 分区
创建根 分区
检查分区状态:
其他分区不用再做了,因为系统装好了自己就可以操作
LVM模式配置硬盘[常规与LVM两者二选一]
选择第一块磁盘 按 回车
结果如下:
选择done提交
配置主机名 用户 密码等信息 账号密码全部配置为admin1
openssh服务安装:
不安装无法通过xshell连接到服务器,这里选择安装
这里提示升级,可以选择取消升级,直接reboot,也可以等待升级完成再重启
升级完成直接选择reboot now 即可
到这 ubuntu就装好了
服务器优化
yum源优化必备软件包安装
#清华源网站
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
#清华ubuntu源 https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
---------------------------------粘贴到sources.list---------------------------------
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
---------------------------------粘贴到sources.list---------------------------------
#备份
cp /etc/apt/sources.list /etc/apt/sources.list_bak
#新增配置 /etc/apt/sources.list
sudo su -
cat >>/etc/apt/sources.list<<EOF
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-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports 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
EOF
#更新yum源
sudo apt-get update
#安装必备软件包
sudo apt install -y git openssh-server net-tools vim lrzsz wget tree screen lsof tcpdump sysstat net-tools
#命令补全工具安装
sudo apt-get install bash-completion
vim ~/.bashrc文件内容新增:
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
#让配置生效
source ~/.bashrc
允许root远程登录[可选]
sudo vim /etc/ssh/sshd_config
......
#PermitRootLogin prohibit-password
改成:
PermitRootLogin yes
Port 22 #可选 这里修改默认ssh端口号
#重启
systemctl restart sshd
#设置root密码:
passwd root
#测试
ssh root@192.168.3.103
防火墙优化
sudo ufw disable # 关闭防火墙
sudo ufw enable # 开启防火墙
sudo ufw status # 查看防火墙当前状态
建议直接关闭防火墙
ufw disable
IP地址配置:
网卡配置和生效:
sudo vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens33: #修改ens33网卡IP
addresses:
- 192.168.3.100/24
gateway4: 192.168.3.2
nameservers:
addresses:
- 223.5.5.5
search:
- 223.6.6.6
ens34:
addresses:
- 172.16.10.100/24 #修改ens34网卡IP
nameservers:
addresses:
- 223.5.5.5
search: []
version: 2
#修改完毕后,
sudo netplan apply
用户级别切换[可选]
# ubuntu18.04 切换文本模式或图形界面模式
sudo systemctl set-default multi-user.target #默认进入字符界面
sudo systemctl set-default graphical.target #默认进入图形界面
其他优化
sudo su -
cat >>/etc/security/limits.conf<<EOF
# 末尾添加如下内容
* soft nofile 655360
* hard nofile 131072
* soft nproc 655350
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited
EOF
sysctl -p