XiZi's Blog

QEMU Service on Centos

1.先放个配置文件上来

# /etc/qemu.conf
# VMs that should be started on boot
# use the ! prefix to disable starting/stopping a VM
# QEMU_MACHINES=(kms)
QEMU_MACHINES=(kms)

# NOTE: following options will be prepended to qemu_${vm}
# -name ${vm} -pidfile /var/run/qemu/${vm}.pid -daemonize -nographic

qemu_kms_type="system-x86_64"

qemu_kms="-enable-kvm -hda /opt/qemu/kmsm4WOen.rom \
  -smbios type=1,manufacturer=Intel,version=1.01234,uuid=564d81c6-cd3a-d8e4-db29-756df139acb9 \
  -uuid 564d81c6-cd3a-d8e4-db29-756df139acb9 \
  -net nic -net user,hostfwd=tcp::1688-:1688 \
  -m 256 -rtc base=localtime,clock=host -M pc \
  -monitor telnet:localhost:7100,server,nowait,nodelay"
qemu_kms_haltcmd="echo 'system_powerdown' | nc localhost 7100" # or netcat/ncat

2.服务所需文件。

#!/bin/sh
# /etc/init.d/qemu

. /etc/rc.d/init.d/functions

[ -f /etc/qemu.conf ] && source /etc/qemu.conf

piddir=/var/run/qemu
lock='/var/lock/subsys/qemu-1.5rc1'
QEMU_PATH=/opt/qemu/qemu-1.5rc1
QEMU_DEFAULT_FLAGS='-name ${vm} -pidfile ${piddir}/${vm}.pid -daemonize -vga none -display none'
# -nographic
QEMU_HALTCMD_WAIT=30

case "$1" in
  start)
    [ -d "${piddir}" ] || mkdir -p "${piddir}"
    if [ -f $lock ]; then 
        # we were not shut down correctly 
        for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do 
          if [ -s $pidf ]; then 
            kill `cat $pidf` >/dev/null 2>&1 
          fi 
          rm -f $pidf 
        done 
        rm -f $lock 
        sleep 2 
    fi 
    rm -f $piddir/*.pid 
    errors=0
    sucesses=0
    for vm in "${QEMU_MACHINES[@]}"; do
        if [ "${vm}" = "${vm#!}" ]; then
        echo -n $"Starting QEMU VM: ${vm}"
        eval vm_cmdline="\$qemu_${vm}"
        eval vm_type="\$qemu_${vm}_type"

        if [ -n "${vm_type}" ]; then
           vm_cmd="${QEMU_PATH}/bin/qemu-${vm_type}"
        else
           vm_cmd="${QEMU_PATH}/bin/qemu"
        fi

        eval "qemu_flags=\"${QEMU_DEFAULT_FLAGS}\""

        ${vm_cmd} ${qemu_flags} ${vm_cmdline} >/dev/null

        if [ $? = 0 ]; then
            successes=1
        else
            errors=1
        fi
       fi
    done
    
    if [ $errors = 1 ]; then
        failure; echo
    else
        success; echo
    fi
    if [ $successes = 1 ]; then
        touch $lock
    fi

    ;;

  stop)
    for vm in "${QEMU_MACHINES[@]}"; do
      if [ "${vm}" = "${vm#!}" ]; then
        # check pidfile presence and permissions
        if [ ! -r "${piddir}/${vm}.pid" ]; then
          continue
        fi

        echo -n $"Stopping QEMU VM: ${vm}"

        eval vm_haltcmd="\$qemu_${vm}_haltcmd"
        eval vm_haltcmd_wait="\$qemu_${vm}_haltcmd_wait"
        vm_haltcmd_wait=${vm_haltcmd_wait:-${QEMU_HALTCMD_WAIT}}
        vm_pid=$(cat ${piddir}/${vm}.pid)
  
        # check process existence
        if ! kill -0 ${vm_pid} 2>/dev/null; then
          stat_done
          rm -f "${piddir}/${vm}.pid"
          continue
        fi

        # Try to shutdown VM safely
        _vm_running='yes'
        if [ -n "${vm_haltcmd}" ]; then
          eval ${vm_haltcmd} >/dev/null

          _w=0
          while [ "${_w}" -lt "${vm_haltcmd_wait}" ]; do
            sleep 1
            if ! kill -0 ${vm_pid} 2>/dev/null; then
              # no such process
              _vm_running=''
              break
            fi
            _w=$((_w + 1))
          done

        else
          # No haltcmd - kill VM unsafely
          _vm_running='yes'
        fi

        if [ -n "${_vm_running}" ]; then
            # kill VM unsafely
            kill ${vm_pid} 2>/dev/null
            sleep 1
        fi

        # report status
        if kill -0 ${vm_pid} 2>/dev/null; then
          # VM is still alive
          #kill -9 ${vm_pid}
          failure; echo
        else
          success; echo
        fi

        # remove pidfile
        rm -f "${piddir}/${vm}.pid"
      fi
    done
    rm -f $lock
    ;;

  restart)
    $0 stop
    sleep 1
    $0 start
    ;;

  *)
    echo "usage: $0 {start|stop|restart}"

esac

PS:

# 如果你没安装过nc的话,就yum一下要么nc用不了,无法关闭服务器。
# 
yum install -y nc

SAMBA在CentOS6上出现NT_STATUS_ACCESS_DENIED错误的解决方法

 

NT_STATUS_ACCESS_DENIED listing \*
在CENTOS上配了个SAMBA与WINDOW共享文件。
 
一访问共享目录就”NT_STATUS_ACCESS_DENIED listing \*“ ,找了好久,发现是SELINUX阻挡了。
 
 
 
[root@linux tmp]# smbclient //127.0.0.1/sambar -U sambar%sambar
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.5.10-114.el6]
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
 
                52265 blocks of size 1048576. 48406 blocks available
 
解决方法一:
 
关闭SELIUNX
 
[root@linux /]# getenforce   ;查看当前状态
Enforcing 
 
[root@linux /]# setenforce 0;
 
 
 
SELINUX几种状态表示:
 
enforcing:强制模式,代表 SELinux 运行中,且已经正确的开始限制 domain/type 了;
permissive:宽容模式:代表 SELinux 运行中,不过仅会有警告信息并不会实际限制 domain/type 的存取。这种模式可以运来作为 SELinux 的 debug 之用;
disabled:关闭,SELinux 并没有实际运行。
 
 
 
解决方法二:
 
更改selinux的策略
 
chcon -t samba_share_t  共享目录(/var/www/html)

CentOS 修改系统字体

1、添加字体

 

#创建新的字体存放文件夹
mkdir /usr/share/fonts/chinese
#拷贝新字体到新文件夹
cp newfont.ttf /usr/share/fonts/chinese
cd /usr/share/fonts/chinese
#修复字体字体权限(这里比较重要,否则可能字体访问出错)
chmod 644 *.ttf
#更新字体
mkfontscale
mkfontdir
fc-cache -fv

2、配置字体,下面是/etc/fonts/local.conf的一个示例,这里替换字体为微软雅黑

 

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
	<match target="pattern">
		<test qual="any" name="family">
			<string>serif</string>
		</test>
		<edit name="family" mode="prepend" binding="strong">
			<string>DejaVu Serif</string>
			<string>YaHei Consolas Hybrid</string>
			<string>AR PL UMing CN</string>
			<string>AR PL ShanHeiSun Uni</string>
			<string>WenQuanYi Bitmap Song</string>
			<string>Bitstream Vera Serif</string>
			<string>AR PL UKai CN</string>
			<string>AR PL ZenKai Uni</string>
		</edit>
	</match>
	<match target="pattern">
		<test qual="any" name="family">
			<string>sans-serif</string>
		</test>
		<edit name="family" mode="prepend" binding="strong">
			<string>DejaVu Sans</string>
			<string>YaHei Consolas Hybrid</string>
			<string>Bitstream Vera Sans</string>
			<string>WenQuanYi Zen Hei</string>
			<string>AR PL UMing CN</string>
			<string>AR PL ShanHeiSun Uni</string>
			<string>WenQuanYi Bitmap Song</string>
			<string>AR PL UKai CN</string>
			<string>AR PL ZenKai Uni</string>
		</edit>
	</match>
	<match target="pattern">
		<test qual="any" name="family">
			<string>monospace</string>
		</test>
		<edit name="family" mode="prepend" binding="strong">
			<string>DejaVu Sans Mono</string>
			<string>YaHei Consolas Hybrid</string>
			<string>Bitstream Vera Sans Mono</string>
			<string>WenQuanYi Zen Hei</string>
			<string>AR PL UMing CN</string>
			<string>AR PL ShanHeiSun Uni</string>
			<string>WenQuanYi Bitmap Song</string>
			<string>AR PL UKai CN</string>
			<string>AR PL ZenKai Uni</string>
		</edit>
	</match>
</fontconfig>

Build Firefox zh-CN Under CentOS6

Touch .mozconfig

# My first mozilla config 
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-@CONFIG_GUESS@
mk_add_options MOZ_MAKE_FLAGS="-j6"
mk_add_options MOZ_CO_LOCALE="zh-CN"
#export L10NBASEDIR=@TOPSRCDIR@/l10n
mk_add_options L10NBASEDIR=@TOPSRCDIR@/l10n

ac_add_options --prefix=/usr
ac_add_options --disable-tests
ac_add_options --enable-ui-locale=zh-CN 
ac_add_options --with-system-zlib
ac_add_options --with-system-jpeg
ac_add_options --enable-official-branding
#ac_add_options --with-l10n-base=@TOPSRCDIR@/l10n

Packages Needed:

	yum install mesa-libGL-devel libXt-devel libcurl-devel \
        alsa-lib-devel yasm dbus-glib-devel dbus-devel gtk2-devel \
        zip unzip autoconf213 patch




Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee