Centos下配置KVM

准备

在Centos下检查cpu是否支持VT,没Ubuntu那么方便,输入下面命令,有内容输出,就表示支持,没任何显示,表明不支持。

egrep '(vmx|svm)' --color=always /proc/cpuinfo
# modprobe kvm_intel
# modprobe kvm
# lsmod | grep kvm
kvm_intel              54285  0 
kvm                   333172  1 kvm_intel

装载完成后kernel就已经转换成hypervisor;可以使用kvm虚拟机
查看Selinux状态

# sestatus
SELinux status:                 disabled

如果是启用状态

# vi /etc/sysconfig/selinux
SELINUX=disabled
reboot

安装 KVM

yum install kvm libvirt python-virtinst qemu-kvm virt-viewer tunctl bridge-utils avahi dmidecode qemu-kvm-tools virt-manager qemu-img  -y

启动libvirt服务

/etc/init.d/libvirtd start

查看kvm服务是否正常,目前没任何虚拟机,所以没有内容显示

virsh -c qemu:///system list

Bridge
我们需要对网卡进行设置一下
备份

mv /etc/sysconfig/network-scripts/ifcfg-eth0 /root/ifcfg-eth0.bak

创建一个文件 /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=static
IPADDR=10.1.199.138
NETMASK=255.255.255.0
ARPCHECK=no

另一种配置也行,某些服务器必须加上GATEWAY

DEVICE=br0
TYPE=Bridge
BOOTRPOTO=static
IPADDR=27.255.67.117
NETMASK=255.255.255.224
GATEWAY=27.255.67.97
ONBOOT=yes

修改 /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
BRIDGE=br0

重启网络服务

/etc/init.d/network restart

查看桥接网络

# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.00e081de016c       no              eth0
virbr0          8000.5254009219a2       yes             virbr0-nic

修改 qemu.conf 配置,把下面几个地方的注释去掉,然后把 dynamic_ownership 的值改成0,禁止 libvirtd 动态修改文件的归属:
这个时候 vnc 默认绑定的是本机 127.0.0.1,如果其他机器想用 vnc 客户端访问这台 kvm 服务器正在安装的 ubuntu 的话需要把 vnc 绑定到服务器的 IP 地址或者绑定到全局 0.0.0.0. 修改 qemu.conf 文件取消 vnc_listen 一行前面的注释,记得重启 libvirtd:

# vi /etc/libvirt/qemu.conf
...
user = "root"
group = "root"
dynamic_ownership = 0
vnc_listen = "0.0.0.0"
vnc_password = "XYZ12345"
...

service libvirtd restart 

重启 libvirtd 服务再用上面的 virt-install 命令安装就应该可以了。
安装虚拟机

# virt-install \
--name VM1 \
--ram 1024 \
--vcpus=2 \
--disk path=/home/img/debian.img,size=20 \
--accelerate \
--cdrom /root/iso/debian-7.4.0-amd64-CD-1.iso \
--graphics vnc,listen=0.0.0.0,port=5920, \
--network bridge=br0  \
--force  --autostart

Virsh语法参考:

Autostart                         自动开始一个域
Create                            从一个 XML 文件创建一个域
Define                            从一个 XML 文件定义(但不开始)一个域
edit                              编辑某个域的 XML 配置
shutdown                          关闭一个域
start                             开始一个(以前定义的)非活跃的域
reboot                            重新启动一个域
suspend                           挂起一个域
resume                            重新恢复一个域
vncdisplay                        vnc 显示
undefine                          删除虚拟机,只是删除VM的配置文件,并不删除虚拟磁盘文件

查看虚拟机列表。

virsh -c qemu:///system list

重启虚拟机

virsh reboot VM1

虚拟机宿主机开机自启动

virsh autostart VM1

取消

virsh autostart --disable VM1

删除虚拟机

virsh undefine VM1
RemoveFolder "/var/lib/libvirt/images/VM1/"  
RemoveFile "/etc/libvirt/qemu/VM1"

虚拟机的配置文件在这里

/etc/libvirt/qemu/*.xml

一个一个安装虚拟机太麻烦,我们来克隆吧!
首先关闭虚拟机

virsh shutdown VM1
virsh -c qemu:///system list
virt-clone -o oeltest01 -n oeltest02 -f /home/img/test02.img
virt-clone -o VM1 -n VM2 -f /home/img/VM2.img --connect=qemu:///system
chown qemu.qemu VM05.img

修改一些配置,把 vnc 的端口号修改一下,避免两个产生冲突,并记录一下这里面的 MAC 地址备用。

virsh edit VM2

先启动 VM2,目前两个虚拟机还不能同时启动。

virsh start VM2
virsh -c qemu:///system list

连接VNC

rm -rf /etc/udev/rules.d/70-persistent-net.rules
rm -rf /etc/udev/rules.d/70-persistent-cd.rules
vi /etc/network/interfaces
hwaddress ether 52:54:00:4b:04:bb 添加mac地址
/etc/init.d/networking restart
virsh reboot VM2
virsh start VM1

在Debian/Ubuntu 配置PPTP VPN

一、安装 pptpd

apt-get update && apt-get upgrade -y
apt-get -y install pptpd gcc make vnstat
modprobe ip_gre && modprobe ip_conntrack_pptp && modprobe ip_nat_pptp
sed -i '$i\modprobe ip_gre && modprobe ip_conntrack_pptp && modprobe ip_nat_pptp' /etc/rc.local

二、编辑 pptpd.conf

rm -rf /etc/pptpd.conf
cat >>/etc/pptpd.conf<<EOF
option /etc/ppp/pptpd-options
localip 10.6.0.1
remoteip 10.6.0.2-254
#logwtmp
EOF

三、编辑 pptpd-options

继续阅读→

Linux Bash Shell 寻找PHP(网站)挂马,后门

一.php后门木马常用的函数大致上可分为四种类型:

1. 执行系统命令: system, passthru, shell_exec, exec, popen, proc_open
2. 代码执行与加密: eval, assert, call_user_func,base64_decode, gzinflate, gzuncompress, gzdecode, str_rot13
3. 文件包含与生成: require, require_once, include, include_once, file_get_contents, file_put_contents, fputs, fwrite
4. .htaccess: SetHandler, auto_prepend_file, auto_append_file

二.想找一个 关键词是“hellow word” 在哪些文件中有,我们用grep命令

grep –color -i -r -n “hellow word”  /data/www/

这样就能搜索出来 文件中包含关键词的文件

继续阅读→

iptables 添加,删除,查看,修改

iptables是linux系统自带的防火墙,功能强大,学习起来需要一段时间,下面是一些习iptables的时候的记录。

一,安装并启动防火墙

[root@linux ~]# /etc/init.d/iptables start  

当我们用iptables添加规则,保存后,这些规则以文件的形势存在磁盘上的,以centos为例,文件地址是/etc/sysconfig/iptables,我们可以通过命令的方式去添加,修改,删除规则,也可以直接修改/etc/sysconfig/iptables这个文件就行了。

二,添加防火墙规则

继续阅读→