环境准备
虚拟机环境准备
-
vmware Workstation16.1.2
-
vmware默认环境配置
-
ununtu18.04TLS环境安装
vmware workstation安装与配置
-
参考站点: https://www.aiweibk.com/203582.html
-
注意事项[必须注意]:
-
- 此软件千万不要安装在C盘
- 软件安装路径不要出现中文
vmware默认环境配置
首选项
虚拟机安装位置首选项:在[编辑]-[首选项]设置即可
网络配置
在[编辑]-[虚拟网络编辑器]设置即可
- NAT子网:10.168.56.0,掩码:255.255.255.0
- 仅主机网络子网:192.168.56.0, 掩码:255.255.255.0
ununtu18.04TLS环境安装
镜像下载
下载站点:http://cdimage.ubuntu.com/releases/
选择: https://cdimage.ubuntu.com/releases/18.04/release/
虚拟机安装准备
- 新建虚拟机: 【文件】-【新建虚拟机】-【下一步】-【下一步】
- 选择【稍后安装操作系统】-【下一步】
- 选择要安装的操作系统
- 配置虚拟机名称和路径
- 配置选择1核2GRAM,网络选择NAT, 磁盘选择20G配置即可,然后新增网卡
- 设置新增网卡为仅主机模式
- 设置CD: 选择下载好的ubuntu镜像
虚拟机安装
-
准备工作完成之后选择开启此虚拟机
-
语言选择【english】
-
先别急着回车,先按F6键盘功能键,然后再按ESC键盘按键
- 输入如下代码: net.ifnames=0 biosdevname=0
作用在于网卡配置会以eth0,eth1加载,而不是乱七八糟的ensxxx, 输入完成代码之后直接回车即可进行其他的安装与配置
- 键盘设置为US,键盘测试选择NO
-
然后回车,到最后设置账号名称为work, 密码
-
设置时区
-
磁盘分区: 【Manule】之分一个根分区,然后分区类型选择xfs
- 完成分区: 注意不需要交换分区,只需要安装根分区就好
- 代理不需要配置
- 不需要更新
- 安装openssh-server软件
- 安装grub
- 完成之后一路continue或者yes到服务器重启
虚拟机初始化配置
ssh登录配置
-
登录服务器: 使用装机配置的用户名和密码
-
然后设置sshd配置: vim /etc/ssh/sshd_config
-
- PermitRootLogin yes
- UseDNS no
网卡配置
由于配置了两块网卡,eth0[NAT]和eth1[仅主机],其中:
- eth0: NAT网卡用于模拟对外交互,可以访问外网, 所涉及的子网是10.168.56.0/24
- eth1: 仅主机网卡,用于模拟主机间的交互,不能访问外网, 所涉及的子网是192.168.56.0/24
配置网卡固定IP(root权限下):
vim /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses: [10.168.56.100/24]
gateway4: 10.168.56.2
nameservers:
addresses: [233.6.6.6]
eth1:
dhcp4: no
dhcp6: no
addresses: [192.168.56.100/24]
配置国内镜像源
阿⾥云仓库地址:https://opsx.alibaba.com/mirror
中科⼤:http://mirrors.ustc.edu.cn/help/ubuntu.html
清华⼤学:https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
华为:https://mirrors.huaweicloud.com/
$ sudo vim /etc/apt/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
- apt 包管理
# apt list #apt列出仓库软件包,等于yum list
# apt search NAME #搜索安装包
# apt show apache2 #查看某个安装包的详细信息
# apt install apache2 #在线安装软件包
# apt remove apache2 #卸载单个软件包但是保留配置⽂件
2.3.3:设置oracle JDK环境:
2.3.4:安装OpenJDK:
2.3.5:安装常⽤系统命令:
# apt autoremove apache2 #删除安装包并解决依赖关系
# apt update #更新本地软件包列表索引,修改了apt仓库后必须执⾏
# apt purge apache2 #卸载单个软件包删除配置⽂件
# apt upgrade #升级所有已安装且可升级到新版本的软件包
# apt full-upgrade #升级整个系统,必要时可以移除旧软件包。
# apt edit-sources #编辑source源⽂件
# apt-cache madison nginx #查看仓库中软件包有哪些版本可以安装
# apt install nginx=1.14.0-0ubuntu1.6 #安装软件包的时候指定安装具体的版本
默认系统优化参数
资源限制类的参数优化
#cat /etc/security/limits.conf
#root账户的资源软限制和硬限制
root soft core unlimited
root hard core unlimited
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 1000000
root hard nofile 1000000
root soft memlock 32000
root hard memlock 32000
root soft msgqueue 8192000
root hard msgqueue 8192000
#其他账户的资源软限制和硬限制
* soft core unlimited
* hard core unlimited
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
* soft memlock 32000
* hard memlock 32000
* soft msgqueue 8192000
* hard msgqueue 8192000
内核参数调整
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536
# # Controls the maximum size of a message, in bytes
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736
# # Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
# TCP kernel paramater
net.ipv4.tcp_mem = 786432 1048576 1572864
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_sack = 1
# socket buffer
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 20480
net.core.optmem_max = 81920
# TCP conn
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_syn_retries = 3
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 15
# tcp conn reuse
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_max_tw_buckets = 20000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syncookies = 1
# keepalive conn
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.ip_local_port_range = 10001 65000
# swap
vm.overcommit_memory = 0
vm.swappiness = 10
系统默认安装和卸载包
# apt purge ufw lxd lxd-client lxcfs lxc-common -y
# apt update
# apt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip -y
服务器重启&克隆
-
sudo reboot -f
-
挂起服务并创建快照
-
关闭服务器并克隆服务器(完整克隆)