Menu

#180 通过外围不能访问虚拟机上的prestashop

open
x x x
prestashop (1)
5
2012-12-08
2012-12-08
x x x
No

1.adsl 与 pC 通过wifi连接,pc可以获取adsl分配的wifi地址
2.

Discussion

  • x x x

    x x x - 2012-12-08

    外网访问Vmware虚拟机中的某个服务(如http)

    如果主机是windowx NAT中隐藏的端口映射,说明一下环境,利用当然是VMnet8网络连接,在虚拟机中架设linux WEB服务器利用WEB默认80端口,IP为192.168.11.10,真实主机win xp系统有两个IP,内网连接192.168.11.1,外网上IP为172.18.136.220。外网其他计算机,可以通过访问我的真实主机221.196.193.220,访问到Linux中的的WEB。 www.2cto.com

    首先说下原理,因为WEB服务是利用80端口,所以在Linux上开启了http服务,80也就自动被打开,因为Linux是内网ip(192.168.11.10),外网无法通过访问这个地址,找到我的web服务,但是可以通过外网地址(172.18.136.220)访问我的XP系统,XP又能连接到Linux,所以把80映射到我的Winxp的系统上是有可能的!

    首先设置网络为NAT方式。具体做法如下:

    选择Vm菜单下的settings选项:

    在弹出的对话框中选择Network Adapter 设置网络为NAT方式

    现在说实际操作打开虚拟机在菜单栏上选择,Edit--虚拟网络设置--NAT选项卡,如下图

    选择VMnet8 编辑,打开NAT设置:

    弹出如下界面 www.2cto.com

    然后在NAT Settings界面点击添加增加一个端口映射。如下图:

    这里就是NAT的端口映射配置了,比如我们要添加到linux虚拟机80端口的WEB服务映射,因为WEB属TCP连接,所以在TCP做了转换,点击Add(添加)

    主机端口,填入真实主机要被转换的端口,这里我们找一个主机没有用的端口开启比如900端口。虚拟机http服务端口为80端口所以在虚拟机端口输入80。如下图:

    确定后,你的朋友就可以在IE下输入http://221.196.193.220:900/ 访问到你虚拟机中linux系统下的WEB服务了。访问Vmware虚拟机中的http服务 www.2cto.com

    注:可能遇到问题 无法访问虚拟机中的服务。

    主机端口没有打开查看端口是否打开命令如下:telnet 后面是主机IP 后面跟端口号

    如果出现如下界面说明端口已经打开

    http://www.2cto.com/os/201206/134390.html

     
  • x x x

    x x x - 2012-12-08

    [unittest1]
    1. virtualBox的虚拟机通过桥接BoardCom芯片,获取ip为192.168.1.27
    2. 在adsl的NAT添加规则
    Web Server (HTTP) 80 80 TCP 80 80 192.168.1.27 ppp1.4
    3.在PC上访问http://113.92.174.83/prestashop/
    直接跳转到http://192.168.56.101/prestashop/index.php
    4.成功访问prestashop

     
  • x x x

    x x x - 2012-12-08

    CentOS 6下,远程安装KVM虚拟机,并使用apache mod_proxy反向代理建立多个web服务器 大 | 中 | 小
    [ 2012/09/19 13:11 | by Sonic ]
    目录:
    0. 配置目的及方案简介
    1. 安装KVM
    2. 安装配置VNC远程控制
    3. 在KVM虚拟机安装CentOS 6
    4. NAT网络配置
    5. 使用iptables防火墙配置,SSH,FTP
    6. 使用反向代理配置Web server
    7. 虚拟机中的Mysql配置
    8. 后续:iptables规则优化,虚拟机自动快照备份

    0. 配置目的及方案简介

    使用一台强劲的服务器,安装多个独立的虚拟机。达到增加安全性(一台虚拟机软故障时,对其他机器没有影响),每个虚拟机灵活管理,充分利用硬件资源的目的。
    主机双网卡,有两个公网IP。因为没有更多的公网IP,所以使用NAT方式为每个虚拟机配置内网IP。理论上以下设置对单网卡主机也完全适用。

    简单来说,主要分以下步骤。

    操作系统采用CentOS 6.3,加装虚拟化组件

    使用Apache reverse proxy反向代理,引导分配web访问

    使用iptables建立端口转发,从而帮助外网访问虚拟机中的ssh、ftp等服务。

    1. 安装KVM

    http://blog.csdn.net/samlei/article/details/7576635
    CentOS6.2 x86上安装KVM功能模块步骤
    以root用户进行。

    1、检查CPU信息
    KVM 需要有 CPU 的支持(Intel VT 或 AMD SVM),在安装 KVM 之前检查一下 CPU 是否提供了虚拟技术的支持。
    基于 Intel 处理器的系统,运行 grep vmx /proc/cpuinfo 查找 CPU flags 是否包括 vmx 关键词

    # grep vmx /proc/cpuinfo
    flags : fpu vme de pse tsc msr pae mce
    cx8 apic sep mtrr pge mca cmov pat
    pse36 clflush dts acpi mmx
    fxsr sse sse2 ss ht tm pbe syscall nx lm
    constant_tsc arch_perfmon pebs bts
    rep_good pni monitor ds_cpl
    vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
    flags : fpu vme de pse tsc msr pae mce
    cx8 apic sep mtrr pge mca cmov pat
    pse36 clflush dts acpi mmx fxsr sse sse2
    ss ht tm pbe syscall nx lm constant_tsc
    arch_perfmon pebs bts rep_good pni
    monitor ds_cpl vmx est tm2 ssse3 cx16
    xtpr lahf_lm ida

    基于 AMD 处理器的系统,运行 grep svm /proc/cpuinfo 查找 CPU flags 是否包括 svm 关键词
    # grep svm /proc/cpuinfo

    注 : 一些厂商禁止了机器 BIOS 中的 VT 选项 , 这种方式下 VT 不能被重新打开。
    注意:/proc/cpuinfo 仅从 Linux 2.6.15(Intel) 和 Linux 2.6.16(AMD) 开始显示虚拟化方面的信息。请使用 uname -r 命令查询您的内核版本。如有疑问,请联系硬件厂商。
    2、检查BIOS,确保BIOS里开启VT选项:
    Intel(R) Virtualization Tech [Enabled]
    如有必要,还需在BIOS中开启VT并重启机器。
    3、从本地光盘(把dvd光盘配置为yum本地库的方法)查询、安装软件包

    查询:
    yum --disablerepo=\* --enablerepo=c6-media groupinfo Virtualization
    yum --disablerepo=\* --enablerepo=c6-media groupinfo 'Virtualization Client'
    安装:
    yum --disablerepo=\* --enablerepo=c6-media groupinstall Virtualization
    yum --disablerepo=\* --enablerepo=c6-media groupinstall 'Virtualization Client'

    group的名字不分大小写。

    Virtualization各工具包内容如下表所示:

    主机能联互联网的,直接用指令:

    yum groupinstall Virtualization 'Virtualization Client'

    来完成安装。

    较低版本的系统,如Redhat/CentOS5.6的,使用指令:
    yum --disablerepo=\* --enablerepo=c5-media groupinstall kvm

    3、安装api支持

    yum --disablerepo=\* --enablerepo=c6-media install libvirt
    service libvirtd start

    4、验证是否已经载入KVM模块
    # lsmod | grep kvm
    kvm_intel 50380 3
    kvm 305081 1 kvm_intel
    #ll /dev/kvm
    crw-rw-rw-+ 1 root kvm 10, 232 May 4 16:06 /dev/kvm

    至此,主机的KVM功能已经具备,可以安装客户操作系统了。

    安装客户机操作系统

    安装客户机操作系统两种方式,一种通过母机GUI的虚拟机管理程序virt-manager,一种通过母机命令行virt-install工具。

    命令行方式:
    #virt-install \ --name=v1
    --ram=512
    --vcpus=1
    --cdrom=/media/CentOS_6.2_final.iso
    --os-type=rhel6
    --disk /var/lib/libvirt/imgages/v1.img,size=8,bus=virtio,cache=writeback
    --network bridge=br0,model=virtio

    下面对上面的命令进行解读

    --name 给虚拟机起个名字
    --ram 分配给虚拟机的内存,单位MB
    --vcpus 分配给虚拟机的cpu个数
    --cdrom 指定安装文件的全路径
    --disk 指定虚拟机img文件路径,如果虚拟机使用lvm分区,这里就指向到lvm的分区就行
    size 虚拟机文件大小,单位GB
    bus 虚拟机磁盘使用的总线类型,为了使虚拟机达到好的性能,这里使用virtio
    cache 虚拟机磁盘的cache类型
    --network bridge 指定桥接网卡
    model 网卡模式,这里也是使用性能更好的virtio
    --graphics 图形参数

    可以用man virt-install 指令查看帮助,最后有很多示例。

    GUI方式:远程操作需要VNC支持,见下文。
    打开菜单Applications->System Tools->Virtual Machine Management
    点击图标Create a new virtual machine
    按照顺序设置虚拟机名称、CPU,内存,磁盘,网络等。
    五个设置步骤完成后,仍然可以修改虚拟机的配置信息。
    至此,整个虚拟机安装过程完成。

    基于KVM建立的虚拟机相关文件默认存放位置
    kvm虚拟机配置文件位置:/etc/libvirt/qemu/
    kvm虚拟机文件位置:var/lib/libvirt/images/

    2. 安装配置VNC远程控制

    以下信息参考 http://blog.haohtml.com/archives/12281 根据实际情况略做改动。

    首先必须有X-Window和桌面环境。如果没有的话,先安装。

    yum groupinstall "X Window System" "GNOME Desktop Environment"
    yum -y install fonts-chinese firefox

    必须明白:vncserver在调用的时候,会根据你的配置来启用server端的监听端口,
    端口默认是从5900开始,再加上你的桌面号。
    比如你的桌面号为1,则vnc的连接端口号为5900+1=5901
    比如你的桌面号为10000,则vnc的连接端口号为5900+10000=15900
    ======================================================================
    下面配置VNC服务器,使用户(root)能够通过vnc客户端远程连接到linux系统的图形界面(前提是你的服务器要安装桌面)

    1、检查linux系统是否安装VNC
    在终端窗口输入命令:

    rpm -q vnc-server

    返回信息如下package vnc-server is not installed 说明vnc服务器没有安装

    2、运行以下命令进行安装:
    [/code]yum install vnc vnc-server[/code]

    3、启动VNC服务
    vncserver
    You will require a password to access your desktops.
    Password:
    Verify:

    会提示输入密码,这个密码是远程登录时所需要输入的密码,输入密码,回车
    4、切换到root账号:su root然后输入root账号的密码

    vi /etc/sysconfig/vncservers #vnc配置文件
    VNCSERVERS="10000:root" # 把前面的#取消了 10000:root (桌面号:用户)
    # VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

    最后保存退出
    5、配置防火墙,允许10000+5900=15900端口通过防火墙(否则远程连不上VNC服务器)

    vi /etc/sysconfig/iptables
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 15900 -j ACCEPT(允许15900端口通过防火墙)

    保存退出
    6、重启vnc服务器
    service vncserver restart

    7、重启防火墙,使刚才的端口配置生效

    /etc/init.d/iptables restart
    或 service iptables restart

    8、 设置vnc服务器开机自动启动
    hkconfig vncserver on
    chkconfig --list vncserver
    vncserver 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    9、更改vnc连接密码
    vncpasswd
    到此,VNC服务端设置完成,用VNC客户端可以连接了
    vnc服务器:你的ip:15900

    注意:如果在连接上之后,出现灰屏,可以按照下面的方法设置
    进入用户的home目录, cd /home/user
    如果是用root账号登录的,那么当前目录就是用户根目录

    cd ~/.vnc
    vi xstartup #编辑
    #twm & #注释掉这一行
    gnome-session & #添加这一行

    保存退出即可正常连接!

    做到这里VNC Server,接下来你可以用http://IP:port的方式来WEB登录比如说
    http://IP:5801,也可以在vncviewer里用IP:1这种来登录。
    但我选择的方式是下载vnc viewer客户端。下载地十: http://www.realvnc.com/download/viewer/

    3. 在KVM虚拟机安装CentOS 6

    有了VNC远程桌面,就可以比较方便的在图型界面中,为虚拟机安装操作系统了。
    过程不再详述,与普通安装没什么差异。

    4. NAT网络配置
    虚拟机中设置:

    回到主机ssh,看到有virbr0接口。默认ip 192.168.1.1/24。这主机虚拟机支持模块安装时产生的虚拟网络接口,也是一个switch和bridge,负责把内容分发到各虚拟机。以此作为NAT虚拟接口。

    #virsh net-list --all
    Name State Autostart
    -----------------------------------------
    default active yes #default是宿主机安装虚拟机支持模块的时候自动安装的。

    #ifconfig
    virbr0 Link encap:Ethernet HWaddr 52:54:00:2A:C3:56
    inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:360864 errors:0 dropped:0 overruns:0 frame:0
    TX packets:429799 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:45356208 (43.2 MiB) TX bytes:250577187 (238.9 MiB)

    NAT原理。

    virbr0是一个桥接器,接收所有到网络192.168.1.*的内容。从下面命令可以验证:

    # brctl show
    bridge name bridge id STP enabled interfaces
    virbr0 8000.525400b9b096 yes virbr0-nic

    # route
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    192.168.1.0 * 255.255.255.0 U 0 0 0 virbr0

    同时,虚拟机支持模块会修改iptables规则,通过命令可以查看:
    # iptables -t nat -L -nv
    Chain PREROUTING (policy ACCEPT 16924 packets, 2759K bytes)
    pkts bytes target prot opt in out source destination
    Chain POSTROUTING (policy ACCEPT 2009 packets, 125K bytes)
    pkts bytes target prot opt in out source destination
    421 31847 MASQUERADE all -- * * 192.168.1.0/24 !192.168.1.0/24 ----------->这条是关键,它配置了NAT功能。
    Chain OUTPUT (policy ACCEPT 2011 packets, 125K bytes)
    pkts bytes target prot opt in out source destination

    # iptables -t filter -L -nv
    Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts bytes target prot opt in out source destination
    1 74 ACCEPT udp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:53 ---->由libvirt脚本自动写入
    0 0 ACCEPT tcp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:53 ---->由libvirt脚本自动写入
    3 984 ACCEPT udp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 udp dpt:67 ---->由libvirt脚本自动写入
    0 0 ACCEPT tcp -- virbr0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:67 ---->由libvirt脚本自动写入
    178K 195M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ---->iptables的系统预设
    2 168 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 ---->iptables的系统预设
    1148 216K ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 ---->iptables的系统预设
    1 60 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 ---->iptables的系统预设
    16564 2721K REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited ---->iptables的系统预设
    Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts bytes target prot opt in out source destination
    3726 3485K ACCEPT all -- * virbr0 0.0.0.0/0 192.168.1.0/24 state RELATED,ESTABLISHED ---->由libvirt脚本自动写入
    3491 399K ACCEPT all -- virbr0 * 192.168.1.0/24 0.0.0.0/0 ---->由libvirt脚本自动写入
    0 0 ACCEPT all -- virbr0 virbr0 0.0.0.0/0 0.0.0.0/0 ---->由libvirt脚本自动写入
    0 0 REJECT all -- * virbr0 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable ---->由libvirt脚本自动写入
    0 0 REJECT all -- virbr0 * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable ---->由libvirt脚本自动写入
    0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited ---->iptables的系统预设
    Chain OUTPUT (policy ACCEPT 181K packets, 138M bytes)
    pkts bytes target prot opt in out source destination

    如果没有default的话,或者需要扩展自己的虚拟网络,可以使用命令重新安装NAT。

    修改/etc/sysctl.conf中参数,允许ip转发:

    [root@VM2CentOS www.esojourn.org]# vim /etc/sysctl.conf
    net.ipv4.ip_forward=1

    进入虚拟机,设置静态IP,hostname

    [root@VM2CentOS www.esojourn.org]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE="eth0"
    BOOTPROTO="static"
    HWADDR="52:54:00:**:**:**"
    NM_CONTROLLED="yes"
    ONBOOT="yes"
    TYPE="Ethernet"
    UUID="426b9729-0d2c-41aa-a29c-...."
    IPADDR=192.168.1.3
    NETMASK=255.255.255.0
    GATEWAY=192.168.1.1

    [root@VM2CentOS www.esojourn.org]# vim /etc/sysconfig/network

    NETWORKING=yes
    HOSTNAME=VM2CentOS

    [root@VM2CentOS www.esojourn.org]# ping 8.8.8.8
    PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
    64 bytes from 8.8.8.8: icmp_seq=1 ttl=45 time=34.6 ms
    64 bytes from 8.8.8.8: icmp_seq=2 ttl=45 time=40.1 ms
    64 bytes from 8.8.8.8: icmp_seq=3 ttl=45 time=36.7 ms
    64 bytes from 8.8.8.8: icmp_seq=4 ttl=45 time=38.0 ms

    网络已经配通。

    更详细的参考
    NAT:http://blog.csdn.net/samlei/article/details/7598700
    Bridge:http://blog.csdn.net/samlei/article/details/7598541

    5. 使用iptables防火墙配置,SSH,FTP
    FTP的设置、安装见本文

    采用NAT方式,各虚拟机分配地址为192.168.1.2,192.168.1.3等。上文libvirt自动加入脚本规则后,从虚拟机已经可以访问公网。但因为本机没有公网IP,所以从公网还无法访问虚拟机。需要使用IP转发,访问虚拟内网主机。

    iptables的设置
    这是比较费劲的一步。需要一些iptables和route基础知识。不多解释了。
    把我的案例贴出来。这东西不能照抄。也千万别图省事用setup之类的图形界面来配置iptables。
    GUI里做配置,会把原来手工写的规则都覆盖掉。
    我就干过几次这种傻事。干完了还不知道为啥全乱了。

    # Generated by iptables-save v1.4.7 on Fri Sep 14 17:42:48 2012
    #
    *mangle
    :PREROUTING ACCEPT [1663:135619]
    :INPUT ACCEPT [1649:135083]
    :FORWARD ACCEPT [3:152]
    :OUTPUT ACCEPT [1243:91918]
    :POSTROUTING ACCEPT [1262:96750]
    -A POSTROUTING -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
    COMMIT

    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [81:6315]
    -A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
    -A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
    -A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
    -A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT

    -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 53 -j ACCEPT
    -A INPUT -p udp -m state --state NEW -m udp --dport 53 -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    #vnc server
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 33900 -j ACCEPT

    -A INPUT -j REJECT --reject-with icmp-host-prohibited

    -A FORWARD -d 192.168.1.0/24 -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
    -A FORWARD -s 192.168.1.0/24 -i virbr0 -j ACCEPT
    #-A FORWARD -i virbr0 -o virbr0 -j ACCEPT
    #-A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
    #-A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable

    -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
    -A FORWARD -p icmp -j ACCEPT
    -A FORWARD -i lo -j ACCEPT
    -A FORWARD -d 192.168.1.2/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    -A FORWARD -d 192.168.1.3/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
    -A FORWARD -d 192.168.1.2/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
    -A FORWARD -d 192.168.1.3/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT

    -A FORWARD -d 192.168.1.2/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
    -A FORWARD -d 192.168.1.3/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT

    -A FORWARD -d 192.168.1.3/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

    # ftp passive port
    -A FORWARD -d 192.168.1.2/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 60200:60299 -j ACCEPT
    -A FORWARD -d 192.168.1.3/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 60300:60399 -j ACCEPT
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT
    # Completed on Fri Sep 14 17:42:48 2012
    # Generated by iptables-save v1.4.7 on Fri Sep 14 17:42:48 2012
    *nat
    :PREROUTING ACCEPT [11:808]
    :POSTROUTING ACCEPT [8:566]
    :OUTPUT ACCEPT [6:466]
    -A PREROUTING -i eth+ -p tcp -m tcp --dport 11256 -j DNAT --to-destination 192.168.1.2:22
    -A PREROUTING -i eth+ -p tcp -m tcp --dport 11356 -j DNAT --to-destination 192.168.1.3:22
    -A PREROUTING -i eth+ -p tcp -m tcp --dport 11221 -j DNAT --to-destination 192.168.1.2:21
    -A PREROUTING -i eth+ -p tcp -m tcp --dport 11321 -j DNAT --to-destination 192.168.1.3:21
    -A PREROUTING -i eth+ -p tcp -m tcp --dport 11220 -j DNAT --to-destination 192.168.1.2
    -A PREROUTING -i eth+ -p tcp -m tcp --dport 11320 -j DNAT --to-destination 192.168.1.3

    #MySQL
    #-A PREROUTING -i eth+ -p tcp -m tcp --dport 13306 -j DNAT --to-destination 192.168.1.3:3306

    -A PREROUTING -i eth+ -p tcp -m tcp --dport 60200:60299 -j DNAT --to-destination 192.168.1.2
    -A PREROUTING -i eth+ -p tcp -m tcp --dport 60300:60399 -j DNAT --to-destination 192.168.1.3

    -A POSTROUTING -s 192.168.1.0/24 ! -d 192.168.1.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535
    -A POSTROUTING -s 192.168.1.0/24 ! -d 192.168.1.0/24 -p udp -j MASQUERADE --to-ports 1024-65535
    -A POSTROUTING -s 192.168.1.0/24 ! -d 192.168.1.0/24 -j MASQUERADE

    COMMIT
    # Completed on Fri Sep 14 17:42:48 2012

    FTP设置
    vi /etc/vsftpd/vsftpd.conf 设置固定的被动链接端口。这样比较容易配合防火墙打开端口。
    见上文# ftp passive port
    -A FORWARD -d 192.168.1.2/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 60200:60299 -j ACCEPT
    -A FORWARD -d 192.168.1.3/32 -i eth+ -p tcp -m state --state NEW -m tcp --dport 60300:60399 -j ACCEPT

    pasv_enable=YES
    pasv_min_port=60000
    pasv_max_port=60100
    pasv_address=0.0.0.0

    6. 使用反向代理(reverse proxy)配置Web server
    因为没有足够的IP地址分给每个虚拟机,我们只能所有域名都设成主机的IP地址。再由反向代理来选择,每个域名访问,应该对应哪个虚拟机。原来考虑直接用iptables想办法检查域名,然后再转发到VM的内网地址。但因为iptables直接检查数据包,获得域名似乎有困难。后来改为反向代理的办法。反向代理常被用于建立web server缓存,或者多服务器负载均衡。

    比较流行的反向代理软件有squid, ngix, apache。因为这里并不需要建立缓存,所以我排除了squid,最终选择了比较熟悉的apache。

    引用
    http://man.chinaunix.net/newsoft/Apache2.2_chinese_manual/mod/mod_proxy.html
    Apache可以被配置为正向(forward)和反向(reverse)代理。

    正向代理是一个位于客户端和原始服务器(origin server)之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端。客户端必须要进行一些特别的设置才能使用正向代理。

    正向代理的典型用途是为在防火墙内的局域网客户端提供访问Internet的途径。正向代理还可以使用缓冲特性(由mod_cache提供)减少网络使用率。

    使用ProxyRequests指令即可激活正向代理。因为正向代理允许客户端通过它访问任意网站并且隐藏客户端自身,因此你必须采取安全措施以确保仅为经过授权的客户端提供服务。

    反向代理正好相反,对于客户端而言它就像是原始服务器,并且客户端不需要进行任何特别的设置。客户端向反向代理的名字空间(name-space)中的内容发送普通请求,接着反向代理将判断向何处(原始服务器)转交请求,并将获得的内容返回给客户端,就像这些内容原本就是它自己的一样。

    反向代理的典型用途是将防火墙后面的服务器提供给Internet用户访问。反向代理还可以为后端的多台服务器提供负载平衡,或为后端较慢的服务器提供缓冲服务。另外,还可以启用高级URL策略和管理技术,从而使处于不同web服务器系统的web页面同时存在于同一个URL空间下。

    可以使用ProxyPass指令激活反向代理(在RewriteRule指令中使用[P]标记也可以)。配置反向代理并不需要打开ProxyRequests指令。

    安装:

    yum install libxml2-devel.x86_64
    yum install httpd-devel.x86_64

    wget http://apache.webthing.com/mod_proxy_html/mod_proxy_html.tar.bz2
    bunzip2 mod_proxy_html.tar.bz2
    tar -xf mod_proxy_html.tar
    cd mod_proxy_html

    ln -s /usr/include/libxml2/libxml /usr/include/libxml

    apxs -I /usr/include/libxml -I . -i -c mod_proxy_html.c
    chmod 755 /usr/lib64/httpd/modules/mod_proxy_html.so

    apxs -I /usr/include/libxml -I . -i -c mod_xml2enc.c
    chmod 755 /usr/lib64/httpd/modules/mod_xml2enc.so

    原文:http://blog.lordfragger.com/?p=12

    reverse proxy主机配置。把www.esojourn.org指向http://192.168.1.3/
    <VirtualHost *:80>
    ServerAdmin office@esojourn.org
    ServerName www.esojourn.org
    ErrorLog logs/error_log
    CustomLog logs/access_log common

    ProxyRequests Off
    <Proxy />
    Order deny,allow
    Allow from all
    ProxyPass http://192.168.1.3/
    ProxyPassReverse http://192.168.1.3/
    ProxyPassReverseCookieDomain 192.168.1.3 www.esojourn.org
    </Proxy>
    ProxyHTMLDoctype XHTML #!!!重要 设置DocType。

    </VirtualHost>

    关于ProxyHTMLDoctype设置,见:http://apache.webthing.com/mod_proxy_html/config.html

    **********这里有个很重要的问题,需要在虚拟机的apache中,启用mod_rpaf模块。

    如果不安装mod_rpaf模块,会有一系列很麻烦的问题。虽然你是用domain.com访问服务器,但是从phpinfo();可以看到,
    Apache Environment里:
    HTTP_HOST 192.168.1.2 #内网地址
    SERVER_NAME 192.168.1.2 #内网地址
    REMOTE_ADDR 192.168.1.1 #内网反向代理地址
    SERVER_SIGNATURE <address>Apache/2.2.15 (CentOS) Server at 192.168.1.2 Port 80</address>

    当然HTTP Headers里也是内网地址:
    Host 192.168.1.2

    这会有什么问题呢?首先你会发现phpMyAdmin安装不了。然后稍微复杂一点的框架也会出错,比如drupal。经常运行到某个页面就跳到内网IP上了。这个问题折磨了我好一阵。虽然phpMyAdmin和drupal都针对反向代理的问题,给出了相应的修改。但是相信我,别费时间跟着那些信息往下进行,都不是什么好办法。比如drupal,核心修改了,上千个第三方模块怎么办?

    问题正解来自Thomas Eibner。他写的mod_rpaf从apache这一层,解决了这些麻烦事。不必再麻烦一行行修改php代码了。安装步骤如下:

    mod_rpaf , 令反向代理后端的 Apache 获取到互联网 IP
    wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
    cd mod_rpaf-0.6
    yum install httpd-devel #没有apxs的,先安装httpd-devel
    apxs -i -a -c mod_rpaf.c Apache 1.3.x 的安装方式
    apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c Apache 2.x 的安装方式

    然后vi /etc/httpd/conf/httpd.conf。
    在LoadModule 区域加了一行:
    LoadModule rpaf_module modules/mod_rpaf-2.0.so

    并在下方添加

    RPAFenable On
    RPAFsethostname On
    RPAFproxy_ips 127.0.0.1 192.168.1.1 # 填写反向代理服务器内网IP。
    RPAFheader X-Forwarded-For

    保存退出后重启apache

    rpaf官网:http://stderr.net/apache/rpaf/
    一篇中文安装说明:http://blog.csdn.net/songerzhou/article/details/5142863

    7. 虚拟机中的Mysql配置

    http://space.itpub.net/9240380/viewspace-665719
    在命令行下,可以有两种大同小异的方法来作此设置:
    (1)mysql>GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'something' WITH GRANT OPTION;
    mysql>GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY 'something' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON *.* TOroot@"%" IDENTIFIED BY '123456' WITH GRANT OPTION;

    How Do I Enable Remote Access To MySQL Database Server?
    http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

    MYSQL PHPMYADMIN无法链接
    setsebool -P httpd_can_network_connect 1

    8. 后续:iptables规则优化,虚拟机自动快照备份
    太长了,分开几篇文章吧。
    虚拟机自动快照备份:http://www.esojourn.org/blog/post/snapshot-to-kvm-qcow2-image.php

    [ 2012-11-09 ] 更新,加入mod_proxy中ProxyHTMLDoctype设置。
    相关日志
    [转载] qcow2、raw、vmdk等镜像格式
    KVM虚拟机快照备份
    vsftpd调试
    OpenVPN服务器及客户端配置

    http://www.esojourn.org/blog/read.php/410.htm

     
  • x x x

    x x x - 2012-12-08

    http地址发生跳转

     
  • x x x

    x x x - 2012-12-08

    Basic authentication establishment (.htaccess)
    In order to better protect your PrestaShop install, we need to establish a basic authentication on the admin directory.

    One of the aims of the .htaccess file is to protect your folders and all its sub-folders (read http://en.wikipedia.org/wiki/Htaccess\). It only works on Apache servers, and a few others. Make sure your web server is Apache before creating a .htaccess file.

    To achieve basic authentication on your admin folder, we need to add a .htaccess file in that folder (for instance, /var/www/prestashop/admin):

    AuthUserFile /var/www/.prestashop_admin
    AuthName "Prestashop Admin Access"
    AuthType Basic
    Require valid-user
    Options -Indexes
    Explanation:

    AuthUserFile: Shows the path to the file containing allowed users and their passwords. .prestashop_admin is a text file.
    AuthName: Defines the message to show when the authentication window pops up.
    AuthType: Defines the authentication type.
    Require: Requires users to log in in order to access the content. valid-user enables multiple users to connect and access the folder.
    Options: Defines the folder's options. -Indexes disables automatic generation of a directory index if no index file is available.
    Here is a sample content for the .prestashop_admin file, with a login and a password:

    login1:$apr1$/wJeliK8$e9OzgRaVL8J8wSsFBXjor1
    login2:$apr1$yV65Kqqz$cFt3sV2.Q7hhLRRUJDo5a/
    This file contains logins and hashed password who are allowed to access to the folder.
    To hash password, you can use .htpasswd file generator: http://aspirine.org/htpasswd_en.html.

    It is strongly recommended to put this file into a directory that is inaccessible to your web applications, so before the /openbase_dir folder. It prevents .htpasswd file injection, in case one of yours web applications is vulnerable.

    It is also possible to perform IP and domain restrictions using your .htaccess file:

    Order Allow, Deny
    Deny from all
    Allow from .myprestashop.com
    Allow from 127.0.0.1
    However, you should not put this kind of directive:

    <LIMIT GET POST>
    Require valid-user
    </LIMIT>

    http://doc.prestashop.com/display/PS15/System+Administrator+Guide

     
  • x x x

    x x x - 2012-12-08

    Setting a shop's URL
    Each shop can have its own URL – or even several URLs – entirely independent from the main shop. You must define at least one URL for each shop.

    Do not create any URL manually, either on your server or your computer: PrestaShop takes care of creating the URL for you on your server. When accessing this URL, PrestaShop will direct visitors to the correct store automatically.
    Two shops cannot share the same URL. If you try to give a new shop a URL that is already in use by another shop, PrestaShop will display an error.
    On the other hand, you can have as many shops on one domain name as you want: http://www.myprestashop.com/men/, http://www.myprestashop.com/women/, http://www.myprestashop.com/kids/, http://www.myprestashop.com/pets/, etc.

    To add a URL to shop, select the shop in the "Multistore tree" selector, and then click on the "Add new URL" button. PrestaShop will load a screen with two sections and height options:

    URL options.
    Shop. A reminder of the shop to which you are adding a URL. You may also simply switch to another shop.
    Main URL. By enabling this, you indicate that you want all of this shop's other URLs to redirect to this new main URL.
    Status. You can disable and enable a URL at any time.
    Shop URL.
    Domain. The URL itself. It does not have to be limited to the domain name: you can indicate a sub-domain if you need to, such as http://www.myprestashop.com/kids/.
    Domain SSL. If your SSL domain is different from your main domain, be sure to indicate it in that field.
    Physical URI. Here you can set the physical path to your shop on your server. If the shop is at the root, leave this field empty.
    Virtual URI. You can make the shop transparently available to customers using this option: without the need to create a sub-folder, you can have your shop be displayed, through the power of URL rewriting. Of course, URL rewriting must be enabled.
    Your final URL will be. Gives you an overview of your URL settings.

    http://doc.prestashop.com/display/PS15/Managing+multiple+shops#Managingmultipleshops-Settingashop'sURL

     
  • Nobody/Anonymous

    XbzRvJ <a href="http://vwejuzryutdp.com/">vwejuzryutdp</a>, [url=http://nhmxpzaochfz.com/]nhmxpzaochfz[/url], [link=http://wkidefzfumrf.com/]wkidefzfumrf[/link], http://atrovwaqwsdp.com/