Linux入门

7/21/2023 自学

# Linux 入门

# Mac安装VMware Fusion

VMware Fusion下载 (opens new window)

![image-20230726154854643](/Users/mac/Library/Application Support/typora-user-images/image-20230726154854643.png)

需要获取激活码,网上搜索即可。

双击开始安装

![image-20230726153749642](/Users/mac/Library/Application Support/typora-user-images/image-20230726153749642.png)

点击打开

![image-20230726153830408](/Users/mac/Library/Application Support/typora-user-images/image-20230726153830408.png)

输入密码开始安装

![image-20230726153848151](/Users/mac/Library/Application Support/typora-user-images/image-20230726153848151.png)

# 安装虚拟机

直接拖入映像文件有时候安装不成功,先创建自定义虚拟机,点击继续。

![image-20230726154208006](/Users/mac/Library/Application Support/typora-user-images/image-20230726154208006.png)

选择Linux系统。CentOS 7为稳定版本,建议选择这个。

![image-20230726154305648](/Users/mac/Library/Application Support/typora-user-images/image-20230726154305648.png)

不用设置,点击继续

![image-20230726154413067](/Users/mac/Library/Application Support/typora-user-images/image-20230726154413067.png)

不用设置,点击继续

![image-20230726154545991](/Users/mac/Library/Application Support/typora-user-images/image-20230726154545991.png)

先不用设置,点击完成。

![image-20230726154645137](/Users/mac/Library/Application Support/typora-user-images/image-20230726154645137.png)

点击存储。

![image-20230726154725315](/Users/mac/Library/Application Support/typora-user-images/image-20230726154725315.png)

点击好。

![image-20230726154745550](/Users/mac/Library/Application Support/typora-user-images/image-20230726154745550.png)

虚拟机创建好后会显示以下信息,因为还未安装操作系统。

![image-20230726155533427](/Users/mac/Library/Application Support/typora-user-images/image-20230726155533427.png)

先关闭虚拟机。

![image-20230726155946185](/Users/mac/Library/Application Support/typora-user-images/image-20230726155946185.png)

# 安装操作系统

下载CentOS 7 映像文件 (opens new window)

![image-20230726155350190](/Users/mac/Library/Application Support/typora-user-images/image-20230726155350190.png)

点击虚拟机设置并选择CD/DVD

![image-20230726160121373](/Users/mac/Library/Application Support/typora-user-images/image-20230726160121373.png)

勾选连接CD/DVD驱动器

![image-20230726160218400](/Users/mac/Library/Application Support/typora-user-images/image-20230726160218400.png)

点击下拉选择光盘映像

![image-20230726160333309](/Users/mac/Library/Application Support/typora-user-images/image-20230726160333309.png)

选择自己之前下载好的CentOS 7 映像

![image-20230726160443298](/Users/mac/Library/Application Support/typora-user-images/image-20230726160443298.png)

点击设置并选择硬盘。

![image-20230726162008686](/Users/mac/Library/Application Support/typora-user-images/image-20230726162008686.png)

将磁盘大小改为64G,为什么要改64G,因为怕后期多开导致内存不够用。

![image-20230726161928740](/Users/mac/Library/Application Support/typora-user-images/image-20230726161928740.png)

重新启动虚拟机

![image-20230726160708407](/Users/mac/Library/Application Support/typora-user-images/image-20230726160708407.png)

键盘上下键进行选择,白色字代表当前项,向上选中 Install CentOS,然后按回车键开始安装。

![image-20230726160807258](/Users/mac/Library/Application Support/typora-user-images/image-20230726160807258.png)

选择English直接下一步。

![image-20230726161030552](/Users/mac/Library/Application Support/typora-user-images/image-20230726161030552.png)

点击DATE & TIME,选择时区,并点击DONE。

![image-20230726161135256](/Users/mac/Library/Application Support/typora-user-images/image-20230726161135256.png)

![image-20230726161203984](/Users/mac/Library/Application Support/typora-user-images/image-20230726161203984.png)

选择硬盘分区。

![image-20230726161431269](/Users/mac/Library/Application Support/typora-user-images/image-20230726161431269.png)

勾选 I will configure partitioning。

![image-20230726162444801](/Users/mac/Library/Application Support/typora-user-images/image-20230726162444801.png)

点击加号按钮。

![image-20230726162547923](/Users/mac/Library/Application Support/typora-user-images/image-20230726162547923.png)

新建第一个引导分区。

![image-20230726162644410](/Users/mac/Library/Application Support/typora-user-images/image-20230726162644410.png)

新建第二个swap分区,一般为运行内存的2倍。

![image-20230726162747340](/Users/mac/Library/Application Support/typora-user-images/image-20230726162747340.png)

新建第三个分区。

![image-20230726162907917](/Users/mac/Library/Application Support/typora-user-images/image-20230726162907917.png)

建完后如图,点击DONE。

![image-20230726162943751](/Users/mac/Library/Application Support/typora-user-images/image-20230726162943751.png)

点击Accept Changes。

![image-20230726163030655](/Users/mac/Library/Application Support/typora-user-images/image-20230726163030655.png)

点击Network & HOSTNAME。

![image-20230726163802535](/Users/mac/Library/Application Support/typora-user-images/image-20230726163802535.png)

修改主机名为CentOS 7,并点击Apply,然后点击DONE。

![image-20230726163734958](/Users/mac/Library/Application Support/typora-user-images/image-20230726163734958.png)

改完以上配置之后,点击开始安装。

![image-20230726163859133](/Users/mac/Library/Application Support/typora-user-images/image-20230726163859133.png)

设置ROOT用户密码。

![image-20230726163942790](/Users/mac/Library/Application Support/typora-user-images/image-20230726163942790.png)

![image-20230726164010747](/Users/mac/Library/Application Support/typora-user-images/image-20230726164010747.png)

安装完成点击Reboot。

![image-20230726164857242](/Users/mac/Library/Application Support/typora-user-images/image-20230726164857242.png)

输入用户名和密码。

![image-20230726165052410](/Users/mac/Library/Application Support/typora-user-images/image-20230726165052410.png)

# 配置虚拟机网络

点击设置,并选择网络。

![image-20230726165842432](/Users/mac/Library/Application Support/typora-user-images/image-20230726165842432.png)

![image-20230726165933842](/Users/mac/Library/Application Support/typora-user-images/image-20230726165933842.png)

点击解锁,并输入密码。

![image-20230726170015758](/Users/mac/Library/Application Support/typora-user-images/image-20230726170015758.png)

按下图配置并点击应用。

![image-20230726170444364](/Users/mac/Library/Application Support/typora-user-images/image-20230726170444364.png)

输入以下命令修改网络配置。

vi /etc/sysconfig/network-scripts/ifcfg-ens33

![image-20230726193512500](/Users/mac/Library/Application Support/typora-user-images/image-20230726193512500.png)

输入以下命令查看IP地址。

ip addr

![image-20230726193821448](/Users/mac/Library/Application Support/typora-user-images/image-20230726193821448.png)

此时ping一下网络。

ping www.google.com

![image-20230726195000583](/Users/mac/Library/Application Support/typora-user-images/image-20230726195000583.png)

输入以下命令重启网络。

systemctl restart network.service

再次输入ip addr 查看如下。

![image-20230726195136698](/Users/mac/Library/Application Support/typora-user-images/image-20230726195136698.png)

再次ping一下网络,已经有网络了。

![image-20230726195235263](/Users/mac/Library/Application Support/typora-user-images/image-20230726195235263.png)

# 防火墙配置

常用命令。

systemctl status firewalld // 查看防火墙状态

// 本次开机状态下防火墙关闭
systemctl stop firewalld  // (本次服务内关闭防火墙) 

// 服务器重启后防火墙禁用
systemctl disable firewalld(禁用防火墙服务)

# 虚拟机软件安装限制

操作系统对未知软件的安装有可能拒绝或者警告,我们需要禁用这个功能。

vi /etc/selinux/config

![image-20230727193623487](/Users/mac/Library/Application Support/typora-user-images/image-20230727193623487.png)

# 关机

  • halt -p (centos6 为halt ) 直接拔掉电源

  • poweroff 直接关闭机器,但是有可能当前虚拟机其他人在使用

  • shutdown -h now 马上关闭计算机 ,但是可以给其他用户发送消息

  • reboot 重启虚拟机

# 修改hostname

vi /etc/hostname
hostname 你的新hostname
ll
exit

# 使用mac终端连接虚拟机

ssh root@192.168.36.100 // ssh 账户名@服务器IP地址

![image-20230727202319927](/Users/mac/Library/Application Support/typora-user-images/image-20230727202319927.png)

Last Updated: 3/20/2024, 8:15:43 AM
강남역 4번 출구
Plastic / Fallin` Dild