How to quickly create a RPM package in CentOS 6.5

Imagine that you want the latest build from your favorite program and you wan’t to keep an installation package whenever you need to revert your virtual machine.

In order to create a RPM package out of a built source you will need checkinstall. This is the easiest and quickest way to create and RPM package. This will keep you from having to compile it everytime you want to use it.

Install rpm handlers:

[root@yourvm home]# yum install -y rpm-build rpmdevtools

After this you will need to create the RPM Source trees

[root@yourvm home]# rpmdev-setuptree

After this step download checkinstall and install it.

[root@yourvm home]# wget ftp://ftp.pbone.net/mirror/ftp5.gwdg.de/pub/opensuse/repositories/home:/ikoinoba/CentOS_CentOS-6/x86_64/checkinstall-1.6.2-3.el6.1.x86_64.rpm
[root@yourvm home]# rpm -i checkinstall-1.6.2-3.el6.1.x86_64.rpm
warning: checkinstall-1.6.2-3.el6.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID f3dbb1a7: NOKEY

After installing checkinstall just run it inside your built tree.

[root@yourvm built_source_tree]# checkinstall --install=no
...
**********************************************************************

 Done. The new package has been installed and saved to

 /root/rpmbuild/RPMS/x86_64/asterisk-1.8.25.0-1.x86_64.rpm
 You can install it in your system anytime using:

      rpm -i asterisk-1.8.25.0-1

**********************************************************************

Setup a DNS proxy in CentOS

Today we are going to learn how to install a DNS server and client using CentOS. The DNS server is perhaps the most important part of the deal. However, there are plenty of support client OSs which can be either Windows, Linux, or Mac.

Server:

So first we go to the server and install iodine. Make sure you don’t have any other process that is using 53. If you do just change it so something else and use -b option in iodined server to relay any

yum search iodine
yum install iodine.x86_64

Then run the command

# iodined -P mypass 172.16.0.1 ns1.yourserver.com
Opened dns0
Setting IP of dns0 to 172.16.0.1
Setting MTU of dns0 to 1130
Opened UDP socket
Listening to dns for domain ns1.yourserver.com
Detaching from terminal…

To make iodined a service just write this to /etc/init/iodined.conf

start on runlevel [2345]
stop on runlevel [S016]

respawn
respawn limit 150 25
expect daemon
exec iodined -P mypass 172.16.0.1 ns1.yourserver.net 2>&1 >/tmp/iodine_boot.log

Client

Run the same command to install iodine. I’ll assume CentOS is the clients platform

yum install iodine.x86_64

Then start iodine

iodine -r -f -P mypass ns1.yourserver.com

To automaticly start it in the client side use this upstart job in file /etc/init/iodine.conf

start on runlevel [2345]
stop on runlevel [S016]
respawn
respawn limit 150 25
exec iodine -r -f -P mypass 1.2.3.4 ns1.yourserver.net >/tmp/iodine_boot.lo

And that’s it. To run the client side just type start iodine. After you run your client you just need to ping 172.16.0.1, which is the server ip address.

Make a very simple link webcrawler in CentOS

This WebCrawler will be made in Python using Beautiful Soup. It will simple collect data form a webpage and store every “href” inside that webpage. In order to work you must install python and BS. Normally Python should be installed already so theres BeautifulSoup missing.

yum install python-BeautifulSoup.noarch

Afterwards all you need is to make a file program.py and save this source in it.

#!/usr/bin/python

import urllib2,os,sys
import BeautifulSoup

if len(sys.argv) > 1 :
 origin_url = str(sys.argv[1])
else :
 # Must have http://
 origin_url = "http://www.stupidness.com/"

request = urllib2.Request(origin_url)
response = urllib2.urlopen(request)

soup = BeautifulSoup.BeautifulSoup(response)
href_array=[]

for a in soup.findAll('a'):
 link=a['href']
 if len(link) > 0 :
 if 'http://' in link :
 href_array.append(a['href'])
 else :
 href_array.append(os.path.dirname(origin_url)+a['href'])

print href_array

With this simple scraper/crawler you will get any href from a webpage.

To use this just type

python program.py