windows vmware 擴展硬盤 + 共享文件


《SpringCloud Nginx 高併發核心編程》 環境搭建 圖文教程和演示視頻:c++

組件 連接地址
【必須】 虛擬機Linux 開發環境準備 windows vmware 擴展硬盤 + 共享文件
Linux openresty 安裝 Linux openresty 安裝
【必須】Linux Redis 安裝(帶視頻) Linux Redis 安裝(帶視頻)
【必須】Linux Zookeeper 安裝(帶視頻) Linux Zookeeper 安裝, 帶視頻
Windows Redis 安裝(帶視頻) Windows Redis 安裝(帶視頻)
RabbitMQ 離線安裝(帶視頻) RabbitMQ 離線安裝(帶視頻)
ElasticSearch 安裝, 帶視頻 ElasticSearch 安裝, 帶視頻
Nacos 安裝(帶視頻) Nacos 安裝(帶視頻)
【必須】Eureka Eureka 入門,帶視頻
【必須】springcloud Config 入門,帶視頻 springcloud Config 入門,帶視頻
【必須】Zuul 詳解,帶視頻 Zuul 詳解,帶視頻
【必須】SpringCloud 腳手架打包與啓動 SpringCloud腳手架打包與啓動

1 虛擬機Linux 環境準備

VMware下載和安裝

絕大多數初學者使用的是 Windows,這裏僅僅介紹在 Windows 下安裝 VMware 和 Linux。
VMware 有兩個版本,分別是 VMware Workstation Pro 和 VMware Workstation Player。面試

VMware Workstation Pro 下載地址:https://pan.baidu.com/s/1XXhFFh0Fx0vzvcd1A543Yg,提取碼:2o19redis

VMware 對計算機的硬件配置要求比較高,配置低了虛擬機會很慢,甚至不能運行。理論上,配置越高越好,如今主流的計算機配置均可以達到運行 VMware 的要求。千萬不要用多年珍藏的老古董來運行 VMware,我保證你將會失去耐心。spring

因爲 VMware 的安裝過程比較簡單,與安裝普通軟件無異,所以再也不過多闡述。這裏假設讀者已經下載並已安裝好 VMware,接下來直接開始使用 VMware 安裝 Linux 系統。編程

使用 VMware 安裝 Linux 系統

啓動 VMware,進入其主界面,如圖 1 所示。windows

虛擬機設置嚮導界面
圖 2 虛擬機設置嚮導界面centos

點擊「下一步」,進入「安裝操做系統」界面,若初學者已提早準備好 Linux 系統的映像文件(.iso 文件),此處可選擇「安裝程序光盤映像文件」,並經過「瀏覽」按鈕找到要安裝 Linux 系統的 iso 文件;不然選擇「稍後安裝操做系統」,如圖 3 所示。

點擊「下一步」,進入「選擇客戶機操做系統」,選擇「Linux」,並在「版本」下拉列表框中選擇要安裝的對應的 Linux 版本,這裏選擇「CentOS 6」,如圖 4 所示。

命名虛擬機
圖 5 命名虛擬機

單擊"下一步"按鈕,進入"指定磁盤容量"界面。默認虛擬硬盤大小爲 20GB(虛擬硬盤會以文件形式存放在虛擬機系統安裝目錄中)。虛擬硬盤的空間能夠根據須要調整大小,但不用擔憂其佔用的空間,由於實際佔用的空間仍是以安裝的系統大小而非此處劃分的硬盤大小爲依據的。

好比你設定了硬盤容量爲 20GB,可是安裝 Linux 只用了 4GB,那麼實際上只會在你的 Windows 分區中佔用 4GB 的空間,佔用空間會隨着虛擬機系統使用的空間增長而增長。

此「指定磁盤容量」界面保持默認設置便可,如圖 6 所示。

指定磁盤容量界面
圖 6 指定磁盤容量界面

接下來進入「已準備好建立虛擬機」界面,確認虛擬機設置,不需改動則單擊"完成"按鈕,開始建立虛擬機,如圖 7 所示。

VMware啓動Linux系統
圖 12 VMware 啓動 Linux 系統

而在圖 3 中選擇「稍後安裝操做系統」的讀者,此時必須先下載某個 Linux 映像文件,並經過「編輯虛擬機設置->CD/DVD(IDE)」中,選擇「使用ISO映像文件」,手動添加 iso 文件,而後點擊「肯定」便可手動開啓 Linux 系統。如圖 13 所示。

通過以上幾步,咱們就成功地用 VMware 虛擬機安裝好了 Linux 系統。

二、掛載擴展硬盤

1 前言

本機vmware會老提示nospace空間不足,通常都須要掛載擴展硬盤

2.添加新硬盤

依次點擊"虛擬機"->"設置"

img

3.查看磁盤信息

[root@localhost ~]# fdisk -l

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x364f5e2e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   83  Linux

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000cbf1e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

能夠看到有2個磁盤,/dev/sda磁盤有3個分區,/dev/sdb磁盤爲我此次新增的,1分區

4.磁盤分區

fdisk /dev/sdb

在這裏插入圖片描述

分區後能夠經過fdisk -l查看/dev/sdb磁盤下有一個sdb1分區

5.格式化分區

# 格式化分區
mkfs.ext4 /dev/sdb1 
# 將分區掛載到根目錄
mount -t ext4 /dev/sdb1 /work

掛載後

[root@localhost ~]# df -ll
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda3       18555904  7347232  11208672  40% /
devtmpfs         1925244        0   1925244   0% /dev
tmpfs            1934520        0   1934520   0% /dev/shm
tmpfs            1934520    58484   1876036   4% /run
tmpfs            1934520        0   1934520   0% /sys/fs/cgroup
/dev/sda1         303788   109596    194192  37% /boot
/dev/sdb1       20510288 11187164   8258216  58% /work
tmpfs             386908        0    386908   0% /run/user/0

6.設置開機自動掛載

vi /etc/rc.d/rc.local
#mount  disk 2  掛載第二塊硬盤
/bin/mount /dev/sdb1 /work

3 CentOS7 安裝VMware Tools

VMware 強烈建議你在每一臺虛擬機中完成操做系統安裝以後當即安裝 VMware Tools 套件。在客戶操做系統中安裝 VMware Tools 很是重要。

VMware Tools是VMware虛擬機中自帶的一種加強工具,至關於VirtualBox中的加強功能(Sun VirtualBox Guest Additions),是VMware提供的加強虛擬顯卡和硬盤性能、以及同步虛擬機與主機時鐘的驅動程序。

只有在VMware虛擬機中安裝好了VMware Tools,才能實現主機與虛擬機之間的文件共享,同時可支持自由拖拽的功能,鼠標也可在虛擬機與主機以前自由移動(不用再按ctrl+alt),且虛擬機屏幕也可實現全屏化。

1 安裝依賴包

[root@localhost ~]# yum -y install perl gcc gcc-c++ make cmake kernel kernel-headers kernel-devel net-tools

2 加載 vmware tools 到CentOS7光驅CD-ROM

點擊菜單 `虛擬機` ——> `安裝VMware Tools(T)...`

在這裏插入圖片描述

點擊加載 vmware tools 到CentOS7光驅CD-ROM

3 將CD-ROM掛載到指定目錄

一般狀況下都是將設備目錄 /dev/crrom 掛載到 /mnt/cdrom 目錄,
  • 若是 /mnt 目錄下不存在 cdrom 目錄則建立

    /mnt/cdrom

    則建立

    [root@localhost ~]# mkdir -p /mnt/cdrom
  • 掛載目錄

    [root@localhost ~]# mount -t auto /dev/cdrom /mnt/cdrom
    mount: /dev/sr0 is write-protected, mounting read-only

    img

    若是掛載目錄錯了,能夠輸入umout /dev/cdrom進行卸載掛載。

ps:mount命令介紹

命令格式:mount [-t vfstype] [-o options] device dir
1.-t vfstype 指定文件系統的類型,一般沒必要指定。mount 會自動選擇正確的類型。經常使用類型有:
  光盤或光盤鏡像:iso9660
  DOS fat16文件系統:msdos
  Windows 9x fat32文件系統:vfat
  Windows NT ntfs文件系統:ntfs
  Mount Windows文件網絡共享:smbfs
  UNIX(LINUX) 文件網絡共享:nfs
2.-o options 主要用來描述設備或檔案的掛接方式。經常使用的參數有:
  loop:用來把一個文件當成硬盤分區掛接上系統
  ro:採用只讀方式掛接設備
  rw:採用讀寫方式掛接設備
  iocharset:指定訪問文件系統所用字符集
3.device 要掛接(mount)的設備。
4.dir設備在系統上的掛接點(mount point)。

完整的掛載命令爲

mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom

4 拷貝安裝包到用戶家目錄

[root@localhost ~]# cp /mnt/cdrom/VMwareTools-10.0.5-3228253.tar.gz ~

5 解除掛載

[root@localhost ~]# umount /dev/cdrom

6 解壓VMwareTools安裝包

[root@localhost ~]# tar -zxvf VMwareTools-10.0.5-3228253.tar.gz

輸入命令tar -zxf VMwareTools-10.0.5-3228253.tar.gz 將剛剛複製的VMwareTools-10.0.5-3228253.tar.gz解壓,默認解壓到當前目錄下,此時就會多出一個命名爲相似於「vmware-tools-distrib」的文件夾,這裏和windows 裏面的解壓結果同樣。

7 安裝VMware Tools

輸入命令 cdvmware-linux-tools 進入解壓後的目錄

[root@localhost ~]# cd vmware-tools-distrib/

運行 vmware-install.pl 文件

[root@localhost vmware-tools-distrib]# ./vmware-install.pl

在運行安裝過程當中,它會一步一步的有問題提出要你迴應,此過程當中,你只要見到問題後面顯示[yes]、[no]、[yes/no]的都輸入yes,而後回車, 若是是其餘的問題,無論[ ]裏面是什麼直接回車就好

一路Enter便可

[root@XD-ORACLE vmware-tools-distribu]# cd vmware-tools-distrib/
[root@XD-ORACLE vmware-tools-distrib]# ls
bin  doc  etc  FILES  INSTALL  installer  lib  vmware-install.pl
[root@XD-ORACLE vmware-tools-distrib]# ./vmware-install.pl
A previous installation of VMware Tools has been detected.

The previous installation was made by the tar installer (version 4).

Keeping the tar4 installer database format.

You have a version of VMware Tools installed.  Continuing this install will
first uninstall the currently installed version.  Do you wish to continue?
(yes/no) [yes] yes

Uninstalling the tar installation of VMware Tools.

Stopping services for VMware Tools

Stopping VMware Tools services in the virtual machine:
   Guest operating system daemon:                          [  OK  ]
   VMware User Agent (vmware-user):                        [  OK  ]
   Blocking file system:                                   [  OK  ]
   Unmounting HGFS shares:                                 [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   VM communication interface socket family:               [  OK  ]
   VM communication interface:                             [  OK  ]

Stopping Thinprint services in the virtual machine:
   Stopping Virtual Printing daemon:                                   done

/sbin/restorecon:  Warning no default label for /tmp/vmware-block-restore0/tmp_file
File /etc/pulse/default.pa is backed up to /etc/pulse/default.pa.old.0.

The removal of VMware Tools 9.6.1 build-1378637 for Linux completed
successfully.

Installing VMware Tools.

In which directory do you want to install the binary files?
[/usr/bin]

What is the directory that contains the init directories (rc0.d/ to rc6.d/)?
[/etc/rc.d]

What is the directory that contains the init scripts?
[/etc/rc.d/init.d]

In which directory do you want to install the daemon files?
[/usr/sbin]

In which directory do you want to install the library files?
[/usr/lib/vmware-tools]

The path "/usr/lib/vmware-tools" does not exist currently. This program is
going to create it, including needed parent directories. Is this what you want?
[yes]


yes
In which directory do you want to install the documentation files?
[/usr/share/doc/vmware-tools]
The path "/usr/share/doc/vmware-tools" does not exist currently. This program
is going to create it, including needed parent directories. Is this what you
want? [yes]
The installation of VMware Tools 9.6.1 build-1378637 for Linux completed
successfully. You can decide to remove this software from your system at any
time by invoking the following command: "/usr/bin/vmware-uninstall-tools.pl".

Before running VMware Tools for the first time, you need to configure it by
invoking the following command: "/usr/bin/vmware-config-tools.pl". Do you want
this program to invoke the command for you now? [yes] yes

Initializing...

/usr/bin/xrandr: Failed to get size of gamma for output default

Making sure services for VMware Tools are stopped.

Stopping Thinprint services in the virtual machine:
   Stopping Virtual Printing daemon:                                   done
Stopping VMware Tools services in the virtual machine:
   Guest operating system daemon:                          [  OK  ]
   VMware User Agent (vmware-user):                        [  OK  ]
   Blocking file system:                                   [  OK  ]
   Unmounting HGFS shares:                                 [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   VM communication interface socket family:               [  OK  ]
   VM communication interface:                             [  OK  ]


Found a compatible pre-built module for vmci.  Installing it...


Found a compatible pre-built module for vsock.  Installing it...


The module vmxnet3 has already been installed on this system by another
installer or package and will not be modified by this installer.

Use the flag --clobber-kernel-modules=vmxnet3 to override.

The module pvscsi has already been installed on this system by another
installer or package and will not be modified by this installer.

Use the flag --clobber-kernel-modules=pvscsi to override.

The module vmmemctl has already been installed on this system by another
installer or package and will not be modified by this installer.

Use the flag --clobber-kernel-modules=vmmemctl to override.

The VMware Host-Guest Filesystem allows for shared folders between the host OS
and the guest OS in a Fusion or Workstation virtual environment.  Do you wish
to enable this feature? [yes] yes

Found a compatible pre-built module for vmhgfs.  Installing it...


Found a compatible pre-built module for vmxnet.  Installing it...


The vmblock enables dragging or copying files between host and guest in a
Fusion or Workstation virtual environment.  Do you wish to enable this feature?
[yes] yes

VMware automatic kernel modules enables automatic building and installation of
VMware kernel modules at boot that are not already present. This feature can be

enabled/disabled by re-running vmware-config-tools.pl.

Would you like to enable VMware automatic kernel modules?
[no] no

Thinprint provides driver-free printing. Do you wish to enable this feature?
[yes] yes


Disabling timer-based audio scheduling in pulseaudio.



Detected X server version 1.13.0



Distribution provided drivers for Xorg X server are used.

Skipping X configuration because X drivers are not included.

Creating a new initrd boot image for the kernel.
   Starting Virtual Printing daemon:                                   done
   Checking acpi hot plug                                  [  OK  ]
Starting VMware Tools services in the virtual machine:
   Switching to guest configuration:                       [  OK  ]
   VM communication interface:                             [  OK  ]
   VM communication interface socket family:               [  OK  ]
   Guest filesystem driver:                                [  OK  ]
   Mounting HGFS shares:                                   [  OK  ]
   Blocking file system:                                   [  OK  ]
   VMware User Agent:                                      [  OK  ]
   Guest operating system daemon:                          [  OK  ]
The configuration of VMware Tools 9.6.1 build-1378637 for Linux for this
running kernel completed successfully.

You must restart your X session before any mouse or graphics changes take
effect.

You can now run VMware Tools by invoking "/usr/bin/vmware-toolbox-cmd" from the
command line.

To enable advanced X features (e.g., guest resolution fit, drag and drop, and
file and text copy/paste), you will need to do one (or more) of the following:
1. Manually start /usr/bin/vmware-user
2. Log out and log back into your desktop session; and,
3. Restart your X session.

Enjoy,

--the VMware team

Found VMware Tools CDROM mounted at /media/VMware Tools. Ejecting device
/dev/sr0 ...
/sbin/restorecon:  Warning no default label for /tmp/vmware-block-restore0/tmp_file
[root@XD-ORACLE vmware-tools-distrib]#

安裝完成後,選擇虛擬機上方的:虛擬機-設置-選項-客戶機隔離,勾選「啓用複製粘貼」,而後重啓centos系統,就能夠實如今虛擬機系統與主機系統之間複製,粘貼文字,以及文件能夠直接在兩系統間拖動了。
在這裏插入圖片描述

8 啓用共享文件夾

在這裏插入圖片描述

在命令窗口輸入以下命令(ls /mnt/hgfs/)以後,會看到本身剛剛設置的共享文件夾

[root@localhost ~]# ls /mnt/hgfs/
develop
[root@localhost ~]#

完整的自定義開機程序 /etc/rc.d/rc.local

[root@localhost ~]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.


#start redis
/usr/local/redis/bin/redis-server  /usr/local/redis/redis.conf

#mount  disk 2  掛載第二塊硬盤
/bin/mount /dev/sdb1 /work

#start nginx  以root帳號 啓動 nginx

/usr/bin/su  - root  -c   "/usr/local/openresty/nginx/sbin/nginx  -c /usr/local/openresty/nginx/conf/nginx.conf"

# 啓動 zookeeper
/usr/bin/su  - root  -c   "/work/zookeeper/zookeeper-1/bin/zkServer.sh start"
/usr/bin/su  - root  -c   "/work/zookeeper/zookeeper-2/bin/zkServer.sh start"
sleep 10s

#start springcloud 註冊中心  eureka
/usr/bin/su  - root  -c   "/work/cloud-eureka-1.0-SNAPSHOT/bin/start.sh start"
sleep 20s 

#start springcloud 配置中心  config
/usr/bin/su  - root  -c   "/work/cloud-config-1.0-SNAPSHOT/bin/start.sh start"

# 啓動 Nacos  ,若是要使用的話
/usr/bin/su  - root  -c   "/work/nacos/bin/startup.sh -m standalone"

以上用到的 su命令,說明以下:

su - root -c command :

切換到root並得到root的環境變量及執行權限並執行命令, -c是command的縮寫

回到◀瘋狂創客圈

瘋狂創客圈 - Java高併發研習社羣,爲你們開啓大廠之門

相關文章
相關標籤/搜索