Archive for the '技术-操作系统' Category


在linux下使用nfs及软链接解决图片文件共享问题

    由于在门户社区中,诸如图片、下载软件这样的资源都较大,且在下载过程中,对带宽资源的占用也较大,因此为不影响正常业务应用,一般情况下都是将图片等资源部署到一台单独的服务器上以分配单独的带宽(在同一台服务器上也将这些资源存放在磁盘空间较大的地方),此种情况下图片等资源与应用不一定在同一台服务器上,即使在同一台服务器上也不一定部署在同一目录下。方案如下:

1、 图片等资源部署在单独的另外一台服务器上

    此种模式可以通过linux的nfs来把完成远程文件mount为本地的文件目录(类似于windows的网络共享),步骤如下:

    下面以将192.168.1.199(NFS服务器端)上的目录/liang mount到192.168.1.202(NFS客户端)上为例,说明一下远程mount的实现

1) NFS服务端(192.168.1.199)执行如下操作

  • 在NFS服务端(192.168.1.199)修改/etc/exports,内容如下
         /liang 192.168.1.*(rw)

    格式如下:directory machine1(option11,option12)

  • 在NFS服务器端启动NFS:

    /etc/rc.d/init.d/portmap start

   /etc/rc.d/init.d/nfs start

  • exportfs命令:

    在启动了NFS之后又修改了/etc/exports后可以用exportfs命令来使改动立刻生效,命令格式如下:

    exportfs [-aruv]

      -a :全部mount或者unmount /etc/exports中的内容

      -r :重新mount /etc/exports中分享出来的目录

      -u :umount 目录

      -v :在 export 的时候,将详细的信息输出到屏幕上。

2) 在NFS客户端(192.168.1.202)执行如下操作

  • 建立本地mount点目录

    mkdir /liang

  • mount远端目录到本地目录

    mount 192.168.1.199:/liang /liang

  • 修改/etc/fstab以在系统重启时候自动mount:
     # device       mountpoint     fs-type     options      dump fsckorder
     192.168.1.199:/liang  /liang    nfs          rw            0    0
  • showmout命令

    -e :显示指定的NFS SERVER上export出来的目录。

    -a :是用来显示已经mount上本机nfs目录的cline机器,一般在NFS SERVER上使用

2、 图片等资源与应用部署在同一台服务器上,但资源目录与应用目录不在一处

    此种情况,采用linux的软链接把图片等资源链接链接到应用的目录下。

        ln  -s /image /www/newwap/wap/image

    由于安全上的考虑,tomcat及jboss缺省情况下都不允许访问软链接的文件,改动如下:

    在conf/server.xml中或conf/Catalina/localhost(根据虚拟主机配置情况做相应改变)下的context中增加如下内容:

        <Context path="" docBase="/www/newwap/wap"  allowLinking="true">

                <Resources className="org.apache.naming.resources.FileDirContext"

                         allowLinking="true"/>

                <Logger className="org.apache.catalina.logger.FileLogger"/>

        </Context>

3、参考资料

    http://nfs.sourceforge.net/nfs-howto/ar01s04.html

Vmware使用几则技巧

   为了平常测试系统部署使用方便,在笔记本IBM T42上使用vmware 6安装了Redhat Enterprise Linux 5 作为服务器,记录一下使用过程中遇见的一些问题。

1、“cannot find a valid peer process to connect to”错误解决

使用vmware后由于关闭速度较慢,没有正常进行关闭操作,直接用process explorer杀掉vmware进程,重新启动虚拟机时候报错,提示的是信息如下:

vmware1

点击“OK”确定之后报错:
cannot find a valid peer process to connect to

解决方法如下:

1、用process explorer杀掉vmware-vmx.exe进程(如果有的话)

2、清除虚拟机目录下的.lck文件

3、在dos命令行下执行net start vmx86,以启动peer process

 

2、VMware Tools问题

  在vmware下安装完了后默认的分辨率选项只有800×600与640×480,在linux的"显示设置"里怎么修改显卡及分辨率后重新启动或注销都没有变化,要想改变linux的分辨率,必须安装VMware Tools;另外安装VMware Tools后提供了增强Guest OS的显示和鼠标功能,可以在虚拟机和主机之间流畅使用鼠标,不用通过CTRL+ALT切换

具体过程如下:

  1. 启动虚拟机
  2. 安装VMware tools

    按照正常的方法安装VMware tools:VM -> Install VMware Tools。但是在点击Install VMware Tools后安装后一段时间,没有任何反映,菜单项始终是“Cancel VMware Tools Install”,在tmp下也没有vmware-linux-tools.tar.gz。

    实际上vmware-linux-tools.tar.gz保存在“VMware的安装目录\VMware Workstation\linux.iso”中,因此可以手工把vmware-linux-tools.tar.gz通过ssh或ftp上传到到Linux中安装即可。

也可以通过VMware 中mount cdrom的方法进行安装,步骤如下

  • 在VMWARE菜单项VM ->Settings->CD-ROM(IDE 1:0),指定“Use ISO image”,路径指向“VMware的安装目录\VMware Workstation\linux.iso”,如下图所示

                                      vmware-tools

  • init 3,切换到runlevel 3
  • mount -t iso9660 /dev/cdrom /mnt
  • cd /mnt;ls /mnt 可以看到下面有如下两个文件

    VMwareTools-6.0.0-45731.i386.rpm  VMwareTools-6.0.0-45731.tar.gz

  • 安装VMwareTools

    采用rpm包安装:

        rpm -ivh VMwareTools-6.0.0-45731.i386.rpm

        vmware-config-tools.pl

        一路回车,完成后出现分辨率列表供选择

    或者采用tar包安装:

       cp VMwareTools-6.0.0-45731.tar.gz /tmp;

       tar zxvf VMwareTools-6.0.0-45731.tar.gz;

       cd VMwareTools-6.0.0-45731.tar.gz;

       ./vmware-install.pl

  • umount /dev/cdrom
  • init 5

   安装完成后,如有问题,可以通过执行/usr/bin/vmware-config-tools.pl 来运行vmware tools,重新配置vmware tool及设定系统分辨率等。

运行vmware tools后,X11的配置文件/etc/X11/xorg.conf内容为:

# Xorg configuration created by system-config-display

Section "ServerLayout"
        Identifier     "single head configuration"
        Screen      0  "Screen0" 0 0
        InputDevice    "Keyboard0" "CoreKeyboard"
        InputDevice     "XWorkAround"
EndSection

Section "InputDevice"
        Identifier  "Keyboard0"
        Driver      "kbd"
        Option      "XkbModel" "pc105"
        Option      "XkbLayout" "us"
EndSection

Section "Device"
    Identifier  "VMware SVGA"
    Driver      "vmware"
EndSection

Section "Screen"
        Identifier "Screen0"
    Device      "VMware SVGA"
    Monitor     "vmware"
    # Don‘t specify DefaultColorDepth unless you know what you’re
    # doing. It will override the driver’s preferences which can
    # cause the X server not to run if the host doesn’t support the
    # depth.
    Subsection "Display"
        # VGA mode: better left untouched
        Depth       4
        Modes       "640×480"
        ViewPort    0 0
    EndSubsection
    Subsection "Display"
        Depth       8
        Modes       "1024×768"
        ViewPort    0 0
    EndSubsection
    Subsection "Display"
        Depth       15
        Modes       "1024×768"
        ViewPort    0 0
    EndSubsection
    Subsection "Display"
        Depth       16
        Modes       "1024×768"
        ViewPort    0 0
    EndSubsection
    Subsection "Display"
        Depth       24
        Modes       "1024×768"
        ViewPort    0 0
    EndSubsection
EndSection

Section "Monitor"
    Identifier      "vmware"
    VendorName      "VMware, Inc"
    HorizSync       1-10000
    VertRefresh     1-10000
EndSection

Section "InputDevice"
        Identifier  "XWorkAround"
        Driver      "void"
EndSection

3、Bridge模式下vmnet0问题

采用VMWare安装Rehat AS 5时候,采用Bridge模式,启动时候报错:

The network bridge on device VMnet0 is not running. The virtual machine will not be able to communicate with the host or with other machines on your network. Virtual device Ethernet0 will start disconnected

原因是在宿主机的本地连接里少了:VMware Bridge Protocol,在正常安装后会在本地网卡的连接属性里有这一项的。

解决方法如下:

1、禁用vmnet1(host-only模式)和vmnet8(nat模式)网卡

2、在服务中禁用VMware NAT Service

3、安装VMware Bridge Protocol

控制面板->网络连接->本地连接->属性->安装->(选中服务)添加->从磁盘安装->浏览->

VMware安装路径\VMware Workstation目录下选 netbridge.inf

然后重装电脑。

4、VMware Tools在xeno服务器安装问题

在DELL Powerdege 1900 服务器(xeon Processor)上安装的虚拟机,运行/usr/bin/vmware-config-tools.pl时候报错:

[root@linux-server-v1 ~]# vmware-config-tools.pl

It looks like you are trying to run this program in a remote session. This

program will temporarily shut down your network connection, so you should only

run it from a local console session. Are you SURE you want to continue?

[no] yes

Stopping VMware Tools services in the virtual machine:

   Guest operating system daemon:                          [  OK  ]

Trying to find a suitable vmmemctl module for your running kernel.

None of the pre-built vmmemctl modules for VMware Tools is suitable for your

running kernel.  Do you want this program to try to build the vmmemctl module

for your system (you need to have a C compiler installed on your system)?

[yes]

Using compiler "/usr/bin/gcc". Use environment variable CC to override.

What is the location of the directory of C header files that match your running

kernel? [/usr/src/linux/include]

The path "/usr/src/linux/include" is not an existing directory.

找不到kernel的header文件,主要原因是没有安装kernel-xen-devel-2.6.18-8.el5,解决方案

确认安装了如下几个包,如果没有安装,从安装盘上拷贝安装上:

kernel-xen-2.6.18-8.el5

kernel-devel-2.6.18-8.el5

kernel-headers-2.6.18-8.el5

kernel-xen-devel-2.6.18-8.el5