VMware

VMware / 2023-01-10

VMware 【常见虚拟机操作系统安装】

Cent OS

镜像版本:CentOS-7.9_x86_64.iso

(一)、初始化设置

# 关闭防火墙
# centos 6
service iptables stop   # 关闭
chkconfig iptables off  # 禁止开机自启动
# centos 7
systemctl disable --now firewalld  # 禁止开机自启动

# selinux
# 永久关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# 调整句柄数
vim /etc/security/limits.conf
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
* soft core unlimited
* hard core unlimited

 # 自定义登录提示
 vim /etc/motd
 -- OR
 /etcmotd.d/*

(二)、配置yum源(阿里云)

# centos 6
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
sed -i 's|http://mirrors.aliyun.com/centos|https://mirrors.aliyun.com/centos-vault/centos|g' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's|http://mirrors.aliyun.com/epel|http://archives.fedoraproject.org/pub/archive/epel|gp' /etc/yum.repos.d/epel.repo

# centos 7
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

# 更新所有软件
yum -y update

# 清除所有缓存并建立源数据
yum clean all && yum makecache

# tips
# centos 6的虚拟机在克隆后,需要将网卡配置文件中的UUID和H删除,然后清空70-persistent-net.rules文件,然后重启
echo > /etc/udev/rules.d/70-persistent-net.rules

(三)、常用工具

# 安装常用工具
yum -y install bash-completion net-tools yum-utils vim vim-enhanced less tree nmap lrzsz nc lsof wget telnet tcpdump htop iftop iotop sysstat nethogs psmisc dstat ntpdate httpd-tools bind-utils  traceroute nload logrotate git

# 常用别名
vim ~/.bashrc
alias ll='ls -lFh'
alias less='less -Ns'
source ~/.bashrc

# 工具介绍
translate-shell:一个命令行下的翻译工具
	· 使用方法:trans -b :zh-CN xxx
  · -b:简洁输出
  · :zh-CN:中文的语言代码
	· trans -T:可以查找支持的翻译语种和相应的语言代码
tree:tree以树形结构显示文件和目录
	· -L:指定显示几层目录
nmap:nmap扫描端口的工具
lrzsz:包含上传(rz)下载(sz)文件工具
nc:端口扫描
lsof:显示Linux系统进程打开的所有文件列表
	· lsof -p $pid
wget:下载软件包工具
tcpdump:抓包、监听等工具
	· tcpdump -i eth1
htop:系统进程相关信息查看工具
iftop:查看主机网卡带宽工具
iotop:磁盘io
sysstat:含有sar,iostat等重要系统性能查看工具
nethogs:显示进程的网络流量
psmisc:含有killall、pstree等命令
net-tools:含有netstat、ifconfig、route、arp等命令
bash-completion:tab补全功能工具
	· 安装完后需在命令行执行bash,TAB补全才能生效
vim-enhanced:vim编辑器工具包
traceroute:路由跟踪工具
nload:监控linux下网络流量
logrotate:日志自动切割

(四)、优化配置项

  • 网络

    • 管理网络的服务–network
      • Centos 7中添加了新的管理网络的服务NetworkManager,network与NetworkManager有时会造成冲突,network与NetworkManager保留一个即可
      • NetworkManager是Centos 7默认的网络管理服务,有些云服务器关闭NetworkManager后会导致无法连接服务器
    • 关闭NetworkManager
      • systemctl disable --now network
  • sshd

    • sshd配置文件:/etc/ssh/sshd_config
    • GSSAPIAuthentication:对不同的客户端安全机制的封装(默认yes)
      • sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
    • UseDNS:每次连接之前先检查DNS解析(默认yes)
      • sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
    • Port:修改端口(默认端口为22)
      • sed -i 's/#Port 22/Port xx/' /etc/ssh/sshd_config
    • PremitRootLogin:是否允许root用户直接登录(默认yes)
      • sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
  • 命令行

    # 命令提示符
    PS1='\[\033[0;31m\]\342\224\214\342\224\200$([[ $? != 0 ]] && echo "[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200")[\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]\$\[\e[0m\]'
    
    # 历史命令显示时间
    # 如果只是写到用户变量中,whoami就没必要添加
    HISTTIMEFORMAT="%F %T `whoami` -- "
    
    # 设置操作系统语言
    # 修改为中文
    LANG="zh_CN.UTF-8"
    # 修改为英文
    LANG="en_US.UTF-8"
    # 永久修改
    vim /etc/locale.conf
    LANG=zh_CN.UTF-8
    

Red Hat

镜像版本:rhel-8.6-x86_64.iso

# rhel需要注册系统才能使用官方软件源,可以注册[红帽](https://access.redhat.com/management)开发者账号免费激活
# 注册系统
subscription-manager register
# 查看注册信息
subscription-manager list --installed
# 续订
subscription-manager remove --all
subscription-manager unregister
subscription-manager clean
subscription-manager register
subscription-manager refresh

# 安装[epel](https://docs.fedoraproject.org/en-US/epel/)源
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
yum clean all && yum makecache

# 安装常用工具
yum -y install bash-completion net-tools yum-utils vim vim-enhanced less tree nmap lrzsz nc lsof wget telnet tcpdump htop iftop iotop sysstat nethogs psmisc dstat httpd-tools bind-utils traceroute nload logrotate git

# 禁止防火墙和web系统管理工具
systemctl disable --now cockpit.socket firewalld

# selinux
# 永久关闭selinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# 禁用 ipv6
# ipv6.method = disabled
nmcli c modify $网卡名 ipv6.method disabled
# 重载网卡设备
nmcli d reapply $网卡名

# 调整句柄数
vim /etc/security/limits.conf
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
* soft core unlimited
* hard core unlimited

# 减少不必要的I/O写入
# 关闭文件元数据的写入,确保在挂载所有磁盘时使用noatime时间以及挂载所有目录时使用nodir时间,相应磁盘default后追加",noatime,nodiratime",重启系统后生效
# 例:
vim /etc/fstab
/dev/mapper/cl-root  /  xfs  defaults,noatime,nodiratime  0  0

# 修改内核配置文件
# 内核默认参数值(1:启用,0:关闭)
vim /etc/sysctl.conf
fs.file-max = 65535				# 表示最大可以打开的句柄数;
fs.aio-max-nr = 1048576				# 最大并发I/O请求数
net.ipv4.tcp_max_tw_buckets = 6000		# TCP最大的连接数,默认为32768
net.ipv4.tcp_fin_timeout = 10			# 缩短TCP无用状态的超时,更有效的重新利用或销毁,默认为60
net.ipv4.tcp_tw_reuse = 1			# 回收的TCP可重新利用
net.ipv4.tcp_syncookies = 1			# 当出现SYN等待队列溢出时,启用cookies进行处理。
net.ipv4.tcp_keepalive_time = 120		# 连接健康检测,默认7200秒
net.ipv4.tcp_keepalive_intvl = 7		# 连接健康检测间隔,默认75秒
net.ipv4.tcp_keepalive_probes = 3		# 连接健康检测连续成功次数判定,默认9
net.ipv4.tcp_rmem = 32768 131072 16777216	# 接收窗口尺寸的最小,默认,最大值
net.ipv4.tcp_wmem = 8192 262144 16777216	# 发送窗口尺寸的最小,默认,最大值
net.ipv4.tcp_mem = 786432 1048576 1572864	# 发送窗口尺寸的最小,默认,最大值
net.core.somaxconn = 16384			# 监听限制网络最大数据包的数量
net.core.rmem_max = 16777216			# 操作系统接收缓冲区最大值
net.core.wmem_max = 16777216			# 操作系统发送缓冲区最大值
net.core.rmem_default = 262144			# 操作系统接收缓冲区的默认大小
net.core.wmem_default = 262144			# 操作系统发送缓冲区的默认大小
# 重新加载内核配置项和网卡
sysctl -p
systemctl restart NetworkManager
  • sshd

    • sshd配置文件:/etc/ssh/sshd_config
    • GSSAPIAuthentication:对不同的客户端安全机制的封装(默认yes)
      • sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
    • UseDNS:每次连接之前先检查DNS解析(默认yes)
      • sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
    • Port:修改端口(默认端口为22)
      • sed -i 's/#Port 22/Port xx/' /etc/ssh/sshd_config
    • PremitRootLogin:是否允许root用户直接登录(默认yes)
      • sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
  • 命令行

    # 命令提示符
    PS1='\[\033[0;31m\]\342\224\214\342\224\200$([[ $? != 0 ]] && echo "[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200")[\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]\$\[\e[0m\]'
    
    # 历史命令显示时间
    # 如果只是写到用户变量中,whoami就没必要添加
    HISTTIMEFORMAT="%F %T `whoami` -- "
    
    # 常用别名
    vim ~/.bashrc
    alias ll='ls -lFh'
    alias less='less -Ns'
    source ~/.bashrc
    
    # 自定义登录提示
    vim /etc/motd
    -- OR
    /etcmotd.d/*
    
    # 设置操作系统语言
    # 修改为中文
    LANG="zh_CN.UTF-8"
    # 修改为英文
    LANG="en_US.UTF-8"
    # 永久修改
    vim /etc/locale.conf
    LANG=zh_CN.UTF-8
    

Ubantu

镜像版本: Ubuntu-22.04_server_64.iso

# Ubantu 阿里镜像站
http://mirrors.aliyun.com/ubuntu

# root 用户管理
# 修改 root 密码
sudo passwd root
# 允许 root 登录
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart sshd

# 关闭防火墙
systemctl stop ufw && /lib/systemd/systemd-sysv-install disable ufw

# 网卡配置文件,修改完需执行 netplan apply 才能生效
/etc/netplan/00-installer-config.yaml

# 安装常用工具包
apt -y install git net-tools tree nmap lrzsz iftop iftop iotop sysstat traceroute nload nethogs dstat ntpdate

# 更新资源并升级软件
# 更新本地报数据库
apt update
# 更新所有已安装的包
apt upgrade

# 调整句柄数
vim /etc/security/limits.conf
# * 代表所有用户,但是有些linux系统不支持*,所及又指定了root
root soft nproc 65535
root hard nproc 65535
root soft nofile 65535
root hard nofile 65535
root soft core unlimited
root hard core unlimited
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
* soft core unlimited
* hard core unlimited

# 卸载snap
snap list
snap remove --purge xxx
apt remove --autoremove snapd
# 关闭 apt 触发器
vim /etc/apt/preferences.d/nosnap.pref
Package: snapd
Pin: release a=*
Pin-Priority: -10
北京