Nombre total de pages vues

lundi 7 mars 2011

Customize CentOS



This is the method that I use to customize CentOS x86_64 distro. The objective of this operation is reducing image install used for server. We need those two ISO: CentOS x86_64 netinstall and CentOS x86_64 CD1. CentOS netinstall permits you to install a fresh mini install but there's yet in this way some packages that are useless for using on a server. On netinstall install, where only the vim package is selected , all the following packages are useless for me: wireless-tools xorg-x11-filesystem Deployment_Guide-fr-FR libXcursor rhpl libpng libjpeg libtiff cups-libs bitstream-vera-fonts fontconfig libXft libXext libXcursor libXrandr libXdmcp libXinerama ecryptfs-utils gtk2 libX11 libXi libXrender cairo trousers libXau libXfixes But some others useful packages for server were not installed: slocate autoconf automake rsync make imake m4 man yum-utils elinks telnet First, you have to do this fresh mini netinstall for create a local repository, because customising an ISO, for reducing it, essentially requires the removal of unnecessary packages. So when install is done. We create a mini local repository, with packages installed on this fresh install. Those that will be included into the custom ISO. How to:
# remove useless packages
yum remove wireless-tools xorg-x11-filesystem Deployment_Guide-fr-FR libXcursor rhpl libpng libjpeg libtiff cups-libs bitstream-vera-fonts fontconfig libXft
libXext libXcursor libXrandr libXdmcp libXinerama ecryptfs-utils gtk2 libX11 libXi libXrender cairo trousers libXau libXfixes -y

# install required packages
yum install slocate autoconf automake rsync make imake m4 man yum-utils elinks telnet yum-utils -y

# listing all packages and download them into temp directory
rpm -qa > /home/rpm.log && mkdir /tmp/rpm
for i in $(cat /home/rpm.log) ; do yumdownloader "$i" -y --destdir /tmp/rpm ; done

# To create repo (useless for customize CentOS ISO)
yum install createrepo -y
createrepo /tmp/rpm/
cd /etc/yum.repos.d/

vi local.repo

[localrepo]
name= CentOS Server $releasesever - My Local Repo
baseurl=file:///tmp/rpm/
enabled=1
gpgcheck=0
#gpgkey=file:////etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

:wq
Now packages are downloaded and we can start to build new ISO. To customize CentOS distro, we only need of the first CentOS CD among eight medias CD for normal install. Thus after downloading, mount the iso on this linux server and customise your distro. How to Second part :
# Create directories
mkdir /mnt/cdimages/
mkdir /mnt/cdimages/CentOS-5.5-x86_64
mkdir /mnt/cdimages/CentOS-5.5-x86_64-core

# Mount ISO
mount -t iso9660 -oloop,ro /home/CentOS-5.5-x86_64-bin-1of8.iso /mnt/cdimages/CentOS-5.5-x86_64

# Install needed packages
yum install mkisofs cdrecord

# Rsync ISO content to new CentOS minimal core 
rsync -av --exclude CentOS/ /mnt/cdimages/CentOS-5.5-x86_64/ /mnt/cdimages/CentOS-5.5-x86_64-core/
mkdir /mnt/cdimages/CentOS-5.5-x86_64-core/CentOS
cp -r /tmp/rpm/* /mnt/cdimages/CentOS-5.5-x86_64-core/CentOS/

# Edit comps.xml
cd /mnt/cdimages/CentOS-5.5-x86_64-core
wc -l repodata/comps.xml # 11418 repodata/comps.xml
grep "xml:lang" repodata/comps.xml | wc -l # 8811
grep -v "xml:lang" repodata/comps.xml > /tmp/no-lang.comps.xml
wc -l /tmp/no-lang.comps.xml # 2607 /tmp/no-lang.comps.xml
rm repodata/* -f
cp /tmp/no-lang.comps.xml repodata/comps.xml

# Test RPM dependencies
cd /mnt/cdimages/CentOS-5.5-x86_64-core/CentOS
mkdir /tmp/testrpmdb
rpm --initdb --dbpath /tmp/testrpmdb/
rpm --test --dbpath /tmp/testrpmdb/ -ivh *.rpm

echo $? # 0
du -sh /tmp/testrpmdb/ # 644K /tmp/testrpmdb/
rm -rf /tmp/testrpmdb

# Create repo
yum install createrepo -y
cd /mnt/cdimages/CentOS-5.5-x86_64-core
cat .discinfo
export discinfo=$(head -1 /mnt/cdimages/CentOS-5.5-x86_64-core/.discinfo)
echo $discinfo
createrepo -u "media://$discinfo" -g repodata/comps.xml /mnt/cdimages/CentOS-5.5-x86_64-core

# Create bootable ISO
export isofilename=/mnt/cdimages/CentOS-5.5-x86_64-core.iso

mkisofs -r -R -J -T -v \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-V "CentOS-5u5-core 64 bit" -p "CentOS_Custom" -A "CentOS-5u5-core 64 bit-2011/01/01" \
-b isolinux/isolinux.bin -c isolinux/boot.cat -x "lost+found" \
-o $isofilename /mnt/cdimages/CentOS-5.5-x86_64-core 
# 213685 extents written (417 MB)

# Implant MD5SUM in the ISO file
yum install mkcdrec
updatedb
locate implantisomd5
/var/opt/mkcdrec/bin/implantisomd5 $isofilename

## Use New CentOS ISO: /mnt/cdimages/CentOS-5.5-x86_64-core.iso
You can now try to install new virtual machine with this new ISO media boot to check that everything works perfectly.

mercredi 19 janvier 2011

Automatically load kernel modules at boot time

If you need to load some modules when server boot, you have to do the following:
echo "modprobe [module_name]" > /etc/sysconfig/modules/[module_name].modules
chmod +x /etc/sysconfig/modules/[module_name].modules
Here is an example with fuse module:
echo "modprobe fuse" > /etc/sysconfig/modules/fuse.modules
chmod +x /etc/sysconfig/modules/fuse.modules
On the next reboot, /etc/rc.sysinit script will load all scripts that located into /etc/sysconfig/modules directory.

How to compile MySQL 5.5 from sources

MySQL released 5.5 version in December 2010. This version seems to be more efficient with improvements like better improved scalability on multi-core CPU, InnoDB storage engine becomes the default engine for new tables or integration of semisynchronous replication. This version is recommended for production environments. It's interesting for administrator to thinking about upgrading. Much systems executes 5.1 version and sometimes the upgrade can be scary ... Here we are going to see how to install 5.5 version on new systems. First we need to install some packages that are needed by MySQL. So installs (or be sure that they all have been installed): bison, bzr, cmake, gcc-c++ ncurses-devel.
yum install -y bison bzr cmake gcc-c++ ncurses-devel
Then add new mysql account and group:
groupadd mysql
useradd -r -g mysql mysql
Now we need download last mysql 5.5 tar.gz archive, choose the mirror directly on mysql website.
wget http://URL_OF_MIRROR/mysql-5.5.16.tar.gz
Extracting tar.gz archive
tar -xvzf /downloads/mysql-5.5.16.tar.gz
Now go into extracted directory and execute cmake:
cd /downloads/mysql-5.5.16/
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql \
-DMYSQL_DATADIR=/var/lib/mysql \
-DSYSCONFDIR=/etc \
-DINSTALL_PLUGINDIR=/opt/mysql/lib/mysql/plugin
Note that I use /opt/mysql for basedir /var/lib/mysql for datadir, you can use others directories by specifing them with 'DCMAKE_INSTALL_PREFIX' and '-DMYSQL_DATADIR' options. When cmake finish to work, we can launch the make .
make
Next, if we don't encounter errors, we launch the install:
make install
Now, we create symbolic links to have mysql commands in shell:
ln -s /opt/mysql/bin/* /usr/bin/
Assign owner and group:
cd /opt/mysql/
chgrp -R mysql .
chown -R root .
chown -R mysql data
Default database installation:
scripts/mysql_install_db --user=mysql \
--datadir=/var/lib/mysql/
Copy a mysql default configuration file:
cp support-files/my-medium.cnf /etc/my.cnf
Copy mysql init.d script and make it executable:
cp support-files/mysql.server /etc/init.d/mysql.server
chmod 755 /etc/init.d/mysql.server
Now edit this init.d script for customize both basedir and datadir paths:
vim /etc/init.d/mysql.server
## replace
basedir=
basedir=

## by
basedir=/opt/mysql
datadir=/var/lib/mysql

## save and exit
:wq
Finally, we can launch mysql server and begin to use it:
/etc/init.d/mysql.server start

samedi 15 janvier 2011

Download RPM packages with yum

Yum don't keeps RPM packages when you install from itself. So when you need to backup those packages locally, it's interesting to have a way for do this. There is few methods that permit to do it. First method is to configure yum.conf with keepcache=1, packages will be archived into path who is specified into cachedir parameter. Problem is that system will download packages for the future but packages that have already been installed will be not stocked in the cachedir path.
vi /etc/yum.conf

cachedir=/var/cache/yum
keepcache=1
Second method is to use yum-downloadonly. This is a yum plugin that adds --downloadonly flag to yum. With this method yum is going to download RPM packages without install or update them. Plugin adds two options to yum: --downloadonly : indicates to yum to just download without install or update packages. --downloaddir=/path/to/dir : specifies directory for storing packages. Here we are going to download and install this yum plugin:
yum install yum-downloadonly -y
Now we can use two news flags that were added to yum: Here we donwload vsftpd in the current directory (we can use install or update, done the same):
yum install vsftpd -y --downloadonly
Or we can download vsftpd to home directory:
yum update vsftpd -y --downloadonly --downloaddir=/home
vsftpd package is now stored into /home:
ls /home/*
Same problem for this second method: if packages are already installed on this CentOS server, yum don't downloads packages and says "already installed and latest version" or "No Packages maked for Update". Third method consists to use yumdownloader which is included into yum-utils. yum-utils is a collection of tools that permit yum to be most complete. So we have to install yum-utils with:
yum install yum-utils -y
Now we can download easily packages from CentOS repositories. This method is more fun because we can now download packages that are already installed on server. For example we check that vsftpd is already installed:
rpm -qa | grep vsftpd
vsftpd-2.0.5-16.el5_5.1
And now we download this package from repository to store it into home directory:
yumdownloader vsftpd --destdir /home
Then:
ls /home/*
vsftpd-2.0.5-16.el5_5.1.i386.rpm
Possibles options for yumdownloader are: --destdir : to specify where to store packages --urls : list the urls it would download instead of downloading --resolve : resolve dependancies and download required packages --source: operate on source packages --archlist: only download packages of certain architectures (i386,i686,x86_64,noarch) Last method can be an alternative method, but it's not the better way. It consists to use wget. With wget we can download directly packages from an url but we have to know exactly where packages are stored on the web. Sometimes it's difficult to guess if package come from base repo or from updates repo, so this method is useful in some context. If wget command isn't available you have to install it with:
yum install wget -y
Then you can download package from url with wget:
wget http://mirror.ate.info/ftp.centos.org/5.5/updates/i386//RPMS/vsftpd-2.0.5-16.el5_5.1.i386.rpm
Package will be stored into current directory. To store it into another directory, use this command instead:
wget http://mirror.ate.info/ftp.centos.org/5.5/updates/i386//RPMS/vsftpd-2.0.5-16.el5_5.1.i386.rpm -P /home
It will be stored into home directory. I hope this article can help you and it will give you better way to handle RPM packages with the powerful yum.

dimanche 11 avril 2010

Welcome

This blog has been created to exchange some linux knowledges and others informations about music, travel, events, web links and more ... Linux articles are always based on CentOS 5.5, so if you work on other distros you have to adapt them with your environment. Messages are generally in english but sometime messages could be in french. I apologize that I don't speak Japanese or Dutch languages. If you need help about some subjects you can contact me for more explications. Best regards, Djill.