@yangwenbo
2023-04-26T16:06:48.000000Z
字数 4799
阅读 225
虚拟机小笔记
1.点击左上角文件
-->>新建虚拟机
2.选择经典
,点击下一步
3.选择稍后安装操作系统
,点击下一步
4.系统选择Linux
,版本选择CentOS 7 64位
,点击下一步
5.创建虚拟机名称,选择虚拟机文件储存位置,点击下一步
6.选择磁盘大小,建议20G
左右;选择将虚拟磁盘拆分成多个文件
,点击下一步
7.选择自定义硬件
8.依次修改配置信息
9.最后点击完成
即可
1.子网掩码
2.IP范围(DHCP)
3.网关地址
1.点击开启此虚拟机
2.点击enter
3.等待。。。
4.选择语言包,可以根据个人喜好来选择中文
和英文
5.进入操作界面
6.选择时区,建议选择shanghai
7.选择安装模式,一般选择最小化安装
8.根据自己的需求选择分区
9.设置网络
和主机名
10.开始安装
11.等待安装,设置密码
12.安装完毕,重启虚拟机
#修改IP
[root@ywb ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.200.200
NETMASK=255.255.255.0
GATEWAY=192.168.200.2
#修改网卡
[root@ywb ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search localdomain
nameserver 192.168.200.2
#重启网络
[root@ywb ~]# service network restart
#关闭防火墙,并关闭开机启动
[root@ywb ~]# service iptables stop
[root@ywb ~]# chkconfig iptables off
#关闭selinux开机自启动
[root@ywb ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#配置yum源
[root@ywb ~]# mkdir -p /media/cdrom
[root@ywb ~]# mount /dev/sr0 /media/cdrom/
[root@ywb ~]# tail -6 /etc/yum.repos.d/CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
[root@ywb ~]# yum -y clean all
[root@ywb ~]# yum makecache
#设置开机自挂载
[root@ywb ~]# echo "mount /dev/sr0 /media/cdrom/" >> /etc/rc.local
#安装一些常用命令
[root@ywb ~]# yum -y install tree curl telnet make cmake gcc gcc-c++ vim wget lrzsz lsof sysstat tcpdump openssh-clients nc htop
#把系统中的命令版本全部更新为最新
[root@ywb ~]# yum -y update
#清空70-persistent-net.rules文件,避免模板依赖
[root@ywb ~]# >/etc/udev/rules.d/70-persistent-net.rules
#修改IP
[root@ywb ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE="Ethernet"
BOOTPROTO="static"
NAME="ens32"
DEVICE="ens32"
ONBOOT="yes"
IPADDR=192.168.200.200
NETMASK=255.255.255.0
GATEWAY=192.168.200.2
#修改网卡
[root@ywb ~]# cat /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
search localdomain
nameserver 192.168.200.2
#重启网络
[root@ywb ~]# systemctl restart network
#关闭NetworkManager服务,并关闭开机启动
[root@ywb ~]# systemctl stop NetworkManager
[root@ywb ~]# systemctl disable NetworkManager
#关闭防火墙,并关闭开机启动
[root@ywb ~]# systemctl stop firewalld
[root@ywb ~]# systemctl disable firewalld
#关闭selinux开机自启动
[root@ywb ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#安装一些常用命令
[root@ywb ~]# yum -y install net-tools tree curl telnet make cmake gcc gcc-c++ vim wget lrzsz lsof sysstat tcpdump nc
#把系统中的命令版本全部更新为最新
[root@ywb ~]# yum -y update
#配置静态IP
root@ubuntu-virtual-machine:~# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto ens32
iface ens32 inet static
address 192.168.200.200
netmask 255.255.255.0
gateway 192.168.200.2
dns-nameserver 192.168.200.2
#重启网络
root@ubuntu-virtual-machine:~# systemctl restart NetworkManager.service
root@ubuntu-virtual-machine:~# apt-get update
#安装ssh
root@ubuntu-virtual-machine:~# apt-get -y install openssh-server
#修改sshd配置,使用户可以远程登录
root@ubuntu-virtual-machine:~# vim /etc/ssh/sshd_config
root@ubuntu-virtual-machine:~# sed -n "28p;52p" /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
#重启sshd
root@ubuntu-virtual-machine:~# systemctl restart sshd
#安装一些常用命令
root@ubuntu-virtual-machine:~# apt-get -y install net-tools tree curl telnet make cmake gcc g++ vim wget lrzsz lsof tcpdump nano inetutils-ping usbutils pciutils resolvconf open-vm-tools open-vm-tools-desktop tmux htop ethtool
#把系统中的命令版本全部更新为最新
root@ubuntu-virtual-machine:~# apt-get -y upgrade
ubuntu镜像源:https://www.zybuluo.com/yangwenbo/note/2271749
#配置静态IP
root@ywb-virtual-machine:~# cat /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
ethernets:
ens32:
addresses: [192.168.200.200/24]
dhcp4: no
dhcp6: no
gateway4: 192.168.200.2
nameservers:
addresses: [255.255.255.0]
#设置网关
root@ywb-virtual-machine:~# cat /etc/resolv.conf
nameserver 192.168.200.2
#重启网络
root@ywb-virtual-machine:~# systemctl restart NetworkManager.service
root@ywb-virtual-machine:~# apt-get update
#安装ssh
root@ywb-virtual-machine:~# apt-get -y install openssh-server
#修改sshd配置,使用户可以远程登录
root@ywb-virtual-machine:~# vim /etc/ssh/sshd_config
root@ywb-virtual-machine:~# sed -n "32p;56p" /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
#重启sshd
root@ywb-virtual-machine:~# systemctl restart sshd
#安装一些常用命令
root@ywb-virtual-machine:~# apt-get -y install net-tools tree curl telnet make cmake gcc g++ vim wget lrzsz lsof tcpdump nano inetutils-ping usbutils pciutils resolvconf open-vm-tools open-vm-tools-desktop tmux htop ethtool
#把系统中的命令版本全部更新为最新
root@ywb-virtual-machine:~# apt-get -y upgrade
ubuntu镜像源:https://www.zybuluo.com/yangwenbo/note/2271749
#配置网关(解决resolv.conf配置在机器在重启时被重置问题)
root@ywb-virtual-machine:~# cat /etc/resolvconf/resolv.conf.d/tail
nameserver 192.168.200.2
#重启resolvconf
root@ywb-virtual-machine:~# systemctl restart resolvconf