虛擬機設置windows共享目錄

版本說明

CentOS-7-x86_64-Minimal-1708
VMware® Workstation 12 Pro 12.5.6 build-5528349

依賴安裝

yum -y install perl gcc make kernel-headers kernel-devel

vm-tools 安裝

1. 虛擬機>設置>CD/DVD
1. 使用ISO映像文件: C:\Program Files (x86)\VMware\VMware Workstation\linux.iso
2. 勾選已鏈接

linux.iso文件在VMware安裝目錄下找。php

2. 掛載CD, 複製VMwareTools, 執行vmware-install.pl
mount /dev/cdrom /mnt
cp /mnt/VMwareTools-10.1.6-5214329.tar.gz ~/
cd ~
tar zxvf VMwareTools-10.1.6-5214329.tar.gz
cd vmware-tools-distrib/
./vmware-install.pl
3. 成功提示
//...一直回車直至出現一下信息表明安裝完畢
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
3. Restart your X session.

Enjoy,

--the VMware team
4. 取消mnt掛載
umount /mnt

配置共享目錄

1. 虛擬機>設置>選項>共享文件夾
1. 選擇:老是啓用
2. 添加目錄便可
2. 查看目錄
cd /mnt/hgfs
ls

設置成功的話,能夠看到共享的文件夾node

共享目錄沒法建立軟鏈問題

windows共享目錄沒法建立軟連接, 有些項目像laravel,node_modules安裝的時候會出現問題。我是經過rsync同步的方式,同步共享目錄裏的項目到另外一個linux目錄下。雖然不是很優雅,可是比較實用

1. 同步項目

rsync -vzrtopgu --progress /mnt/hgfs/www/blog  /srv/projects/

2. 編寫php腳本

vim  /opt/scripts/rsync.php

<?php
function rsync_projects()
{
    $command = 'rsync -vzrtopgu  --exclude=index.php /mnt/hgfs/www/blog  /srv/projects/';
    $output = [];
    exec($command , $output);
    $str = '---------' . date('Y-m-d H:i:s') . '---------' . PHP_EOL;
    if($output) {
        foreach ($output as $val) {
            $str .= $val . PHP_EOL;
        }
    }
    @file_put_contents('/opt/scripts/rsync.log', $str, FILE_APPEND);
}
rsync_projects();

3. 加載同步腳本

同步後的項目入口文件index.php開頭處加入linux

require '/opt/scripts/rsync.php';

rsync.php的同步命令是rsync -vzrtopgu --exclude=index.php /mnt/hgfs/www/blog /srv/projects/。排除了index.phplaravel

開發項目 /mnt/hgfs/www/blog, 實際運行項目 /srv/projects/blog。每次想要查看修改代碼效果的時候會訪問 /srv/projects/blog入口文件 index.php,同時執行 rsync.php腳本同步文件。這樣作實際上比加到crontab執行或者監測文件變化同步都簡單實用
相關文章
相關標籤/搜索