zoukankan      html  css  js  c++  java
  • windows平台是上的sublime编辑远程linux平台上的文件

    sublime是个跨平台的强大的代码编辑工具,不多说。
    想使用sublime完毕linux平台下django网站的代码编辑工作以提高效率(原来使用linux下的vim效率较低,适合编辑一些小脚本)。

    下载linux平台下的Sublime_Text_2.0.2_x64.tar.bz2(http://www.sublimetext.com/)

    解压使用:
    tar -xjvf Sublime_Text_2.0.2_x64.tar.bz2
    cd Sublime Text 2/

    运行
    ./sublime_text 

    报错
    ./sublime_text: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./sublime_text)
    ./sublime_text: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by ./sublime_text)
    ./sublime_text: /lib64/libc.so.6: version `GLIBC_2.11' not found (required by ./sublime_text)

    原因是所使用的系统为centos5,版本号过低,c/c++库版本号过低。
    公司的电脑不能随便升级库或者升级系统,仅仅能另想办法。


    设想一:
    linuxserver上的代码拉下来存放在windows机器上,使用windows平台上的sublime对其进行编辑,之后又一次上传到linuxserver中。

    问题:代码编辑后通常须要实际执行调试,尤其是网站类型的代码。经常须要编辑好后立马验证一下显示结果。而我们的整个执行环境是搭建在linux平台下的,如此一来,便须要先将代码从linuxserver拉倒windows平台,修改一个地方后又一次传回linuxserver,測试执行。若有问题则又一次拉下来编辑。又一次上传、測试。如此下去。很繁琐耗时。有没有一种更好的办法?

    设想二:
    在linuxserver上使用git为代码建立仓库,在windows上clone该仓库。使用sublime对clone下来的仓库中的代码进行编辑。编辑完毕后一条push命令将全部提交的更新内容推到远程的代码仓库中进行測试。过程与设想一类似,改进之处在于使用git命令来向远程linuxserver推更新,而不是手工逐个将更新的文件上传到远程server。



    不知道有没有问题,先试试看:
    之前已经在linuxserver上创建了代码仓库。位置为
    /var/www/site/mycitsm
    直接使用 /var/www/site/mycitsm文件夹下的.git文件夹创建供其它机器clone的代码仓库
    sudo git remote add origin ssh://username@IP:PORT/var/www/site/mycitsm/.git

    之后远程机器就能够使用
    git clone ssh://username@IP:PORT/var/www/site/mycitsm/.git d:/www/mycitsm
    该命令将远程server上的代码仓库拉倒本地d:/www/mycits文件夹中

    我们在windows平台上下载安装Git-1.9.2(http://git-scm.com/download/win)或者第三方的gitHub等等
    clone仓库:
    进入git bash(安装Git后创建的命令行工具)
    $git clone ssh://username@IP:PORT/var/www/site/mycitsm/.git d:/www/mycitsm
    可能提示让输入远程server上op1的password,(假设将本地server的公钥写进了远程server的authorized_keys文件则无需password就可以。详细可參考怎样设置无passwordSSH至远程主机,Windows系统与linux系统之间与linux系统与linux系统之间的设置方法是同样的。)
    也可能提示找不到git-upload-pack,这是由于远程server中git安装的位置不是标准的默认位置。仅仅须要将这些工具拷贝到标准的位置,或在标准位置设置软连接连接至这些工具就可以。也能够在clone命令中指定工具的位置如: --upload-pack /home/op1/bin/git-upload-pack。



    此后远程仓库中的文件夹结构和内容被clone到了本地windowsserver的d:/www/mycitsm文件夹中了,能够使用sublime直接打开该文件夹对内部的文件进行编辑。



    在git bash中进入本地仓库
    $cd d://www/mycitsm

    查看git状态
    $git status

    提交变化
    $git add filename
    $git commit -m "some text"

    将本地仓库推到远程仓库
    $git push (origin master)

    报错:
    remote: error: refusing to update checked out branch: refs/heads/master
    remote: error: By default, updating the current branch in a non-bare repository
    remote: error: is denied, because it will make the index and work tree inconsistent
    remote: error: with what you pushed, and will require 'git reset --hard' to match
    remote: error: the work tree to HEAD.
    remote: error:
    remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
    remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
    remote: error: its current branch; however, this is not recommended unless you
    remote: error: arranged to update its work tree to match what you pushed in some
    remote: error: other way.
    remote: error:
    remote: error: To squelch this message and still keep the default behaviour, set
    remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
    To ssh://op1@192.168.83.36:1022/var/www/site/mycitsm/.git
     ! [remote rejected] master -> master (branch is currently checked out)
    error: failed to push some refs to 'ssh://op1@192.168.83.36:1022/var/www/site/my
    citsm/.git'

    意思为:默认情况下不同意在非裸仓库中更新当前分支,由于推送的内容会导致索引和工作文件夹树不一致。


    虽然能够通过通过将git配置文件里'receive.denyCurrentBranch'变量值设置为ignore或warn来同意推送至当前分支,但很不推荐这么做,除非你安排更新工作文件夹树来匹配你推送的内容。

    既然如此,那我们设置一个罗仓库会怎么样呢?
    来到linuxserver的/var/www/site/文件夹
    创建裸仓库(详细參考http://git-scm.com/book/zh):
    $ git clone --bare mycitsm mycitsm.git
    该命令实际上相当于
    $ cp -Rf mycitsm/.git mycitsm.git

    之后把该罗仓库移动至你期望的位置就可以。
    $sudo git remote add origin ssh://username@IP:PORT/var/www/site/mycitsm.git
    $git clone ssh://username@IP:PORT/var/www/site/mycitsm.git d:/www/mycitsm

    用sublime编辑,本地提交,推送至远程仓库。

    没有看到异常。
    那,是否意味着我们能够在远程的仓库中測试了呢?

    连到linuxserver进入/var/www/site/mycitsm/文件夹发现里边的文件并没有发生不论什么变化。哦对,我们是将更新推送到了linuxserver上的裸仓库mycitsm.git中。


    进入mycitsm.git。恩并没有工作文件夹树(这也是罗仓库之所以叫裸仓库的原因)。它仅仅记录了提交历史信息。

    费了好大劲,也就是说我们并不能通过这样的方式来将本地最新内容同步到linux原始仓库中,仅仅能将变化信息同步到相关的裸仓库中。而我们又不能在裸仓库中获取到能够进行測试的文件夹文件。

    且上述两种方案都有一个问题。那就是linuxserver中的文件变化不能主动直接的反馈到windows端,我们必须又一次拉回最新的文件才干看到这样的变化。


    设想三:
    了解到sublime有个叫sftp的插件,能够通过它直接打开远程机器上的文件进行编辑,并在保存后直接同步到远程机器上,听起来非常诱人。

    先为sublime安装包管理插件Package Control:
    按Ctrl+`调出sublime控制台, 粘贴下面代码到控制台并回车
    import urllib2,os;
    pf='Package Control.sublime-package';
    ipp=sublime.installed_packages_path();
    os.makedirs(ipp) if not os.path.exists(ipp) else None;
    open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read())

    重新启动sublime,在Perferences->package settings中看到package control这一项,则成功安装。



    用Package Control安装插件
    按下Ctrl+Shift+P调出命令面板
    输入install 调出 Install Package 选项并回车,然后输入ftp,下拉列表中会出现一些相关的插件。选中sftp进行安装即可了,装好后还需配置例如以下:选菜单条中的File->SFTP/FTP->Set up Server。然后出现一个配置窗体例如以下:

    {
        // The tab key will cycle through the settings when first created
        // Visit http://wbond.net/sublime_packages/sftp/settings for help
        
        // sftp, ftp or ftps
        "type": "ftp",

        "sync_down_on_open": true,
        "sync_same_age": true,
        
        "host": "IP",
        "user": "username",
        "password": "passowrd",
        //"port": "22",
        
        "remote_path": "/var/www/site/mycitsm/",
        //"file_permissions": "664",
        //"dir_permissions": "775",
        
        //"extra_list_connections": 0,

        "connect_timeout": 30,
        //"keepalive": 120,
        //"ftp_passive_mode": true,
        //"ftp_obey_passive_host": false,
        //"ssh_key_file": "~/.ssh/id_rsa",
        //"sftp_flags": ["-F", "/path/to/ssh_config"],
        
        //"preserve_modification_times": false,
        //"remote_time_offset_in_hours": 0,
        //"remote_encoding": "utf-8",
        //"remote_locale": "C",
        //"allow_config_upload": false,
    }

    一般配置一下一下參数就可以
    "host": "yourIP",
    "user": "yourUsername",
    "password": "yourPassowrd",
    "remote_path": "yourPath",

    这样的方法要求远程的linux服务器能够通过sftp或ftp连接上去,也就远程linux服务器上须要执行有类似ftp server的东西。ftp server产品非常多,选其一安装配置好就可以。

    安装配置參考详细的产品。

    linux的ftp server端和sublime端都配置好后便可通过file->stfp/ftp/browser server来查看远程服务器上的文件夹和文件了。然后可依据提供的命令重命名文件夹,编辑文件等。编辑好的文件保存后可马上同步至远程的linux服务器中。
    该方案貌似非常好的攻克了我们的问题。但让不够完美,我们在sublime中浏览到linuxserver中工作文件夹的体验非常不好。必须使用一条条命令来返回值至上一文件夹,对文件进行编辑,重命名等操作。在不同文件夹和文件里导航非常不方便。



    有没有一种方案能够吧远程linuxserver中指定的文件夹同步到windows本地。直接用sublime打开windows本地的文件夹,显示出一颗完美的文件夹树。迅速的在各文件夹和文件间切换编辑,并实时的将更新内容同步到远程server呢?

    终于方案:
    功夫不负有心人,查找到确实存在这么一个东西。能够通过SSH到远程server上,把远程server的某个文件夹挂载到本地,远程或本地的变化能实时的反应到还有一端(实际上。两者是同一位置,你编辑的就是linuxserver上的文件)。

    这样我们仅仅需把linuxserver上所需的文件夹挂载到windows本地,使用sublime打开该文件夹跟打开本地其它文件夹全然一样。直接对文件夹内的文件进行编辑。

    这个工具叫sshfs使用ssh訪问远程主机,由windows版本号和linux版本号的分别用于在windows上和linux上挂载远程文件夹。



    下载安装windows版本号的工具
    要先装依赖:dokan library -->DokanInstall_0.6.0.exe(http://dokan-dev.net/wp-content/uploads/DokanInstall_0.6.0.exe)
    在安装sshfs本身:win-sshfs-0.0.1.5-setup.exe (https://win-sshfs.googlecode.com/files/win-sshfs-0.0.1.5-setup.exe)

    启动、配置指定host、port、username、password、directory等内容后将文件夹挂载到本地,之后便能够使用sublime随心所欲的编辑了。



    目标最终达成了!

  • 相关阅读:
    Linux命令_2
    Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.
    壁纸目录
    ubuntu 解决“无法获得锁 /var/lib/dpkg/lock -open (11:资源暂时不可用)”的方法
    Oracle VM VirtulBox 安装Ubuntu16.04
    Linux 中文输入法安装
    Android LayoutInflater 相关知识
    Linux命令_1
    青蛙跳杯子
    横向打印二叉树
  • 原文地址:https://www.cnblogs.com/yxysuanfa/p/6846888.html
Copyright © 2011-2022 走看看