Jul 02

Fedora 15 下安装 Openfetion 2.2

本文简要描述在Fedora 15系统下编译安装Openfetion 2.2的办法

在Linux下编译安装软件,做多了就会知道,常见问题无非就是缺少依赖的库(头文件或者共享库)。下面给出的命令假设你以普通用户登录系统,并且这个用户具有sudo成root的权限。

1. 安装所需软件开发包


sudo yum install cmake libnotify-devel gstreamer-devel \
	NetworkManager-develgtk2-devel openssl-devel libXScrnSaver-devel

Read the rest of this entry »

Jun 17

Create new KVM guest from template

Most of us don’t like to install guest OS repeatedly, instead, we often install one guest OS, then do some setup and customization. After that, we make a backup of the disk image(We use it as a template). If we want to install the same OS later, we only need to copy that template disk image and create a new guest config file.

When create a new guest config file, we need to give it a unique name, a unique uuid, and a unique MAC address. Also, we need to change it’s disk file path. We can do this kind of changes manually, hower, according to the rule “automate all that can be automated”, we can use a script to do this.
Read the rest of this entry »

May 30

A convenient Bash function to backup configuration file

For sysadmins, it’s a good practice to backup configuration files before changing them. We normally do it via cp. eg:

cp named.conf named.conf.bak
cp named.conf named.conf.orig

I personally like to use the date time as the file name suffix, so that I can tell from the file name when I did that backup. Also, with this method, multiple version of the config file can be kept.

Because I use this method frequently, I wrote a Bash function to do this:

b(){
        for f in "$@"
                do cp -a "$f" "$f".$(date +%Y%m%d%H%M)
        done
}

Add it to my ~/.bash_profile . And run

source ~/.bash_profile

Then every time I need to backup a file, I just need to do this

b /etc/mail/sendmail.mc
#this will create a backup file named like /etc/mail/sendmail.mc.201105301420
cd /var/named/chroot/etc/
b named.conf #relative file name also works
b /etc/postfix # you can also backup a whole directory

In fact, its usage is not limited to configuration file, you can use it to backup whatever you like.

May 29

Install fedora 15 from usb

This assumes that the capacity your USB drive is no less than 4GB.

  1. Install grub4dos to the USB.
    Use grubinst to install grub4dos MBR to the USB, then copy the grldr file in grub4dos package to the root directory of the USB drive. See DoIT’s post for instructions.
  2. Put Installation media to the USB
    Download the fedora DVD iso image, extract vmlinuz and initrd.img in the isolinux directory to the root of the USB drive, and then put the iso itself to the root of the USB drive
  3. Boot from the USB
    Boot from the USB, you will be dropped into a grub shell, type the following command to start the install.

    root (hd0,0)
    kernel /vmlinuz askmethod
    initrd /initrd.img
    boot
    

    The will start the fedora installer, when it comes to the install method selection, select Local drive, and select your usb drive partition to continue.

Discussion: Why not simply use UNetbootin? 1st, Fedora 15 is not yet listed on the homepage, maybe it is not supported yet. 2nd, the most important reason, UNetbootin will copy the contents of the ISO image file by file to USB, which is quite slow. If drop the iso image itself to USB, it will be much faster.

Reference: Official Fedora 15 Installation Guide

May 27

Sendmail relay to non standard smtp port via mailertable

The Sendmail mailertable is used to route email. By default, the Sendmail smtp delivery agents used to relay mail will connect to other host through the standard SMTP port 25. From the Sendmail FAQ How do I send using an alternate port, we know that it’s possible to relay to other port by define the **MAILER_ARGS, however, that will work for all relay. What if we want to relay to one host running SMTP on port 26, and another host running SMTP on port 8825? We can implement this by adding other mailer.

Edit /etc/mail/sendmail.cf, Add the following two mailer definition to the enf of the file

#########esmtp on port 26####
Mesmtp26,               P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,
                T=DNS/RFC822/SMTP,
                A=TCP $h 26
#########esmtp on port 8825####
Mesmtp8825,             P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,
                T=DNS/RFC822/SMTP,
                A=TCP $h 8825

Here we defined two mailer called esmtp26 and esmtp8825 . What we do here is to copy the definition of the esmtp mailer, give it a new name, and change its argument( the A=TCP .. line, the port number is defined after $h ) to use whichever port we want.

Now, in mailertable, we can configure email route to use the two mailers like this.

#relay all mail for asia.example.com to srv1.example.com on port 26
asia.example.com    esmtp26:[srv1.example.com]
#relay all mail for euro.example.com to srv2.example.com on port 8825
euro.example.com    esmtp8825:[srv2.example.com]
#relay mail for example.org to srv3.example.com on standard port 25
example.org    smtp:[srv3.example.com]

May 23

php security: disable functions

Case Study:
Some small hosting company provides web hosting service to its clients. The machine runing web server also acts as an email server, which function very well. Then one day, one of its client wrote some php scripts, which allow users to upload a file containing a list of email addresses, and send email to these thousands of addresses. As a result, system load increased ,server responsiveness lowered, normal email transaction slows down.

This kind of abuse have a great impact on the overall server performance and mail server reputation(may make it blacklisted by other mail server). So, if service policy with client allow, mail function(maybe other) can be disabled to prevent this. A php.ini configuration directive called disable_functions can help.

disable_functions = mail,exec,shell_exec,passthru,system,proc_open,popen

Note: This directive must be set in php.ini. For example, you cannot set this in httpd.conf.

The above example will disable the mail function, also, it will disable other exec related functions so that user will not be able to run command to send email. In fact, disabling these other functions may help to reduce possible damages when web site is exploited by script-kiddies.

Furthermore, when use php with FastCGI, each virtual host can has its different php.ini, which allows one site to disable some functions, and others enable them.

In fact, this is not the sole solution to this case, neither the best. We can, for example, change the mail server configuration to accomplish the same target.

May 19

Build vanilla linux kernel on CentOS 5

Building a Linux kernel itself is not complicated. In normal case, we just download the latest Linux kernel from http://www.kernel.org, extract the tarball, cd to the kernel source tree, then run a series of command:

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.38.6.tar.bz2
tar -xjf linux-2.6.38.6.tar.bz2
cd linux-2.6.38.6
make mrproper
make menuconfig
make -j2 > /dev/null
sudo make modules_install
sudo make install

In order for the newly built kernel to be able to boot successfully, we need to configure it with required driver modules, this includes, but not limited to, filesystem drivers, block device drivers, network device drivers, …etc.
Read the rest of this entry »

May 09

KVM: 安装Windows virtio半虚拟化驱动

Install KVM Windows virtio para-virtualized dirver

If you can’t read Chinese, there’s an English version on the Internet, click Here

本文测试环境: KVM主机: sl6(Scientific Linux 6). 虚拟机: (win2k3)Windows Server 2003.

安装半虚拟化驱动有助于提高网络和IO性能,下面我们来看看如何在sl6下为win2k3安装virtio半虚拟化驱动。Fedora和CentOS下的操作大体相似。

1. 下载win-virtio驱动包.
可以到这里去下载iso格式的光盘镜像,之后挂载到win2k3.

2. 关闭win2k3虚拟机

3. 创建一个临时磁盘镜像,我们之后会将它作为virtio磁盘添加到win2k3(为的是让win2k3能检查到新硬件,然后安装驱动)这个镜像用完后可以删掉。

qemu-img create -f qcow2 tmp.qcow2 1G

Read the rest of this entry »

May 02

Intall multiple version of php on one server

This article is about how to install php-5.1, php-5.2 and php-5.3 on one server, and use them simultaneously

Based on CentOS 5.6, for Apache only

1. Enable rpmforge and epel yum repository

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
sudo rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
sudo rpm -ivh epel-release-5-4.noarch.rpm

2. Install php-5.1

CentOS/RHEL 5.x series have php-5.1 in box, simply install it with yum, eg:

sudo yum install php php-mysql php-mbstring php-mcrypt

Compile and install php 5.2 and 5.3 from source

For php 5.2 and 5.3, we can find many rpm packages on the Internet. However, they all conflict with the php which comes with CentOS, so, we’d better build and install them from soure, this is not difficult, the point is to install php at different location.
However, when install php as an apache module, we can only use one version of php at the same time. If we need to run different version of php on the same server, at the same time, for example, different virtual host may need different version of php. Fortunately, the cool FastCGI and PHP-FPM can help.
Read the rest of this entry »

Apr 19

Install linux KVM guest from console

The point is: Let the guest use serial port 0 as its default console.

In linux, this can be achieved by passing the console= kernel parameter. For example, we can start a CentOS 5.6 install like this:

virt-install --name testvm \
        --ram 1024 \
        --vcpus 2 \
        --os-type linux \
        --os-variant rhel5.4 \
        --disk path=/vmrepo/disk/testvm.img,size=12 \
        --location http://ftp.twaren.net/Linux/CentOS/5/os/x86_64/ \
        --network bridge=br1 \
        --extra-args console=ttyS0

Notes:

  • Here, I use rhel6 as the KVM host, if you use other Linux distribution/version as host, the option of virt-install may be slightly different
  • use the –extra-args to pass kernel parameter, tell kernel to set serial port 0 as console.
  • Use the –location option to specify an installation URL, this is important and required. You may want to use the –cdrom option and install from DVD, but that will not work, because if you use cdrom instead of URL, there will be no way for virt-install to pass the console= parameter.

Run this command, then you can continue the installation as usual(use text mode/or start VNC based installation)

Older posts «

» Newer posts