天天看點

windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

  • 狂創客圈 經典圖書 : 《Netty Zookeeper Redis 高并發實戰》 面試必備 + 面試必備 + 面試必備 【部落格園總入口 】
  • 瘋狂創客圈 經典圖書 : 《SpringCloud、Nginx高并發核心程式設計》 大廠必備 + 大廠必備 + 大廠必備 【部落格園總入口 】
  • 入大廠+漲工資必備: 高并發【 億級流量IM實戰】 實戰系列 【 SpringCloud Nginx秒殺】 實戰系列 【部落格園總入口 】

《SpringCloud Nginx 高并發核心程式設計》 環境搭建 圖文教程和示範視訊:

元件 連結位址
【必須】 虛拟機Linux 開發環境準備 windows vmware 擴充硬碟 + 共享檔案
Linux openresty 安裝
【必須】Linux Redis 安裝(帶視訊) Linux Redis 安裝(帶視訊)
【必須】Linux Zookeeper 安裝(帶視訊) Linux Zookeeper 安裝, 帶視訊
Windows Redis 安裝(帶視訊)
RabbitMQ 離線安裝(帶視訊)
ElasticSearch 安裝, 帶視訊
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,提取碼:2o19

VMware 對計算機的硬體配置要求比較高,配置低了虛拟機會很慢,甚至不能運作。理論上,配置越高越好,現在主流的計算機配置都可以達到運作 VMware 的要求。千萬不要用多年珍藏的老古董來運作 VMware,我保證你将會失去耐心。

由于 VMware 的安裝過程比較簡單,與安裝普通軟體無異,是以不再過多闡述。這裡假設讀者已經下載下傳并已安裝好 VMware,接下來直接開始使用 VMware 安裝 Linux 系統。

使用 VMware 安裝 Linux 系統

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

windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

圖 2 虛拟機設定向導界面

點選“下一步”,進入“安裝作業系統”界面,若初學者已提前準備好 Linux 系統的映像檔案(.iso 檔案),此處可選擇“安裝程式CD光牒映像檔案”,并通過“浏覽”按鈕找到要安裝 Linux 系統的 iso 檔案;否則選擇“稍後安裝作業系統”,如圖 3 所示。

  • 32 位 CentOS 6.5 映像下載下傳:http://archive.kernel.org/centos-vault/6.5/isos/i386/CentOS-6.5-i386-bin-DVD1.iso
  • 64 位 CentOS 6.5 映像下載下傳:http://archive.kernel.org/centos-vault/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1.iso

點選“下一步”,進入“選擇客戶機作業系統”,選擇“Linux”,并在“版本”下拉清單框中選擇要安裝的對應的 Linux 版本,這裡選擇“CentOS 6”,如圖 4 所示。

windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

圖 5 命名虛拟機

單擊"下一步"按鈕,進入"指定磁盤容量"界面。預設虛拟硬碟大小為 20GB(虛拟硬碟會以檔案形式存放在虛拟機系統安裝目錄中)。虛拟硬碟的空間可以根據需要調整大小,但不用擔心其占用的空間,因為實際占用的空間還是以安裝的系統大小而非此處劃分的硬碟大小為依據的。

比如你設定了硬碟容量為 20GB,但是安裝 Linux 隻用了 4GB,那麼實際上隻會在你的 Windows 分區中占用 4GB 的空間,占用空間會随着虛拟機系統使用的空間增加而增加。

此“指定磁盤容量”界面保持預設設定即可,如圖 6 所示。

windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

圖 6 指定磁盤容量界面

接下來進入“已準備好建立虛拟機”界面,确認虛拟機設定,不需改動則單擊"完成"按鈕,開始建立虛拟機,如圖 7 所示。

windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

圖 12 VMware 啟動 Linux 系統

而在圖 3 中選擇“稍後安裝作業系統”的讀者,此時必須先下載下傳某個 Linux 映像檔案,并通過“編輯虛拟機設定->CD/DVD(IDE)”中,選擇“使用ISO映像檔案”,手動添加 iso 檔案,然後點選“确定”即可手動開啟 Linux 系統。如圖 13 所示。

經過以上幾步,我們就成功地用 VMware 虛拟機安裝好了 Linux 系統。

2、挂載擴充硬碟

1 前言

本機vmware會老提示nospace空間不足,一般都需要挂載擴充硬碟

2.添加新硬碟

依次點選"虛拟機"->"設定"

windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

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 
           
windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

分區後可以通過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)...`
           
windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

點選加載 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
               
    windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈
    如果挂載目錄錯了,可以輸入umout /dev/cdrom進行解除安裝挂載。

ps:mount指令介紹

指令格式:mount [-t vfstype] [-o options] device dir

1.-t vfstype 指定檔案系統的類型,通常不必指定。mount 會自動選擇正确的類型。常用類型有:

  CD光牒或CD光牒鏡像: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系統,就可以實作在虛拟機系統與主機系統之間複制,粘貼文字,以及檔案可以直接在兩系統間拖動了。

windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

8 啟用共享檔案夾

windows vmware 擴充硬碟 + 共享檔案 瘋狂創客圈

在指令視窗輸入如下指令(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高并發研習社群,為大家開啟大廠之門