Archive for the ‘Linux’ tag
Fast backup and restore of MySQL databases
I use MySQL version 5 for a number of databases and have been looking for a fast way to back them up and restore them.
What I wanted was the fastest possible way to create a copy of my databases and a relatively easy way to restore them.
I soon found mysqlhotcopy, but when copying all databases at once, it locks all tables during the copy operation. To circumvent this, I wrote a small Bash script that will execute mysqlhotcopy for every database separately, so the others remain accessible during the backup.
To speed things up, I tell mysqlhotcopy not to include indices, as I can easily recreate those when I need to restore a database.
The script runs from cron on a daily basis, is fairly simple and looks like this: Read the rest of this entry »
How to change console resolution on Linux ( RHEL / CentOS / Fedora / etc)
If, like me, you use Linux for your server, you might not have a graphical (X) console.
So, out of the box, you’re stuck with a large screen and very big characters on it. It’s the all time standard 80×25 text console.
I wanted to make that a bit more useful for daily work, so I decided to change the resolution so I could get lots more text on the console.
This is quite simple. All you have to do is add an extra kernel parameter for the Linux kernel when booting.
On RHEL derivates this done by editing the /boot/grub/grub.conf file and adding vga=791 to the kernel line. That will give you a so called frame buffer console with a 1024×786 resolution after the next boot. Read the rest of this entry »
Disable APIPA ( 169.254.x.x ) on RHEL 5 / CentOS 5
So your “route -n” shows a route to some strange network and you want to get rid of it? Here’s how
The 169.254.0.0 network is the so called APIPA or “zero config” network that Microsoft introduced with Windows (I forget with which version).
If you want to disable that, simply add “NOZEROCONF=yes” to your “/etc/sysconfig/network” and do “service network restart” to restart the network services.
That’s it. Route gone
How to roll back packages on CentOS 5 / RHEL 5
CentOS 5 / RHEL 5 preferably uses yum as the program to update, install and remove packages.
When you’ve installed/updates packages with yum or rpm, you can quite easily roll back the updates/installations using rpm.
For this, yum and rpm need to save roll back information, which they do not do by default.
To enable the roll back feature, do the following:
Add tsflags=repackage to /etc/yum.conf.
Add %_repackage_all_erasures 1 to /etc/rpm/macros. If /etc/rpm/macros does not exist, just create it.
You can now install, erase and update packages with yum and/or rpm, and they will save roll back information.
When you want to roll back, use rpm to do so.
You do this by specifying the --rollback switch and a date/time, like the examples below:
rpm -Uhv --rollback '19:00'
rpm -Uhv --rollback '8 hours ago'
rpm -Uhv --rollback 'december 31'
rpm -Uhv --rollback 'yesterday'
Happy rolling
How to create an ethernet subinterface on RHEL 5 / CentOS 5
Having one ethernet adapter with multpile IP addresses is sometimes handy. For instance, when you want to have more than one SSL web site running.
Assuming you have a functioning interface, here is how to set this up for RHEL 5 / CentOS 5.
In the example I use eth0 as the existing “main” device.
The process:
Go to the directory with the networking scripts
cd /etc/sysconfig/network-scripts
Copy the original network script for the interface
cp ifcfg-eth0 ifcfg-eth0:1
Edit ifcfg-eth0:1 and:
Change the device name
change DEVICE=eth0 to DEVICE=eth0:1
Change the IP address
change IPADDR=[current value] to IPADDR=[ip address for subinterface]
Save the file
Restart the network service.
service network restart
When all went well, you should now have an extra interface showing in ifconfig.
Good luck!
Realtek Linux driver automatic compile for kernel
Sometimes you’ll have to update your Linux kernel. Not very often, but sometimes anyway ![]()
If, like me, you use a mainboard with a builtin Realtek ethernet controller, chances are that after installing your new kernel, the ethernet controller doesn’t come up. The problem is that your Linux kernel doesn’t have the correct module/driver.
You can very easily compile and install the driver by hand, but I tend to forget that and start wondering why things aren’t working
I’ve written a small script that checks to see if the correct kernel module exists. If not, it compiles the module and restarts the network services.
It’s compatible with CentOS 4(.5) and 5, but will most likely work with all Red Hat derivates.
Download the drivers and extract them in /usr/src like this:
cd /usr/src
tar xzf where-you-put-the-tgz-file/realtek_r1000.tgz
Copy the script to a location that makes sense to you (the script assumes /usr/src/LAN):
cp where-you-put-the-script/r1000.sh /usr/src/LAN
Edit your /etc/rc.d/rc.local to execute the r1000.sh file on system boot.
That should do the trick!
The drivers I’ve included with this post will work for RTL8169S/SB/SC, RTL8168B and RTL8101E chipsets.
MailScanner / MailWatch problem: Could not use Custom Function code MailScanner::CustomConfig::InitMailWatchLogging
One for the archives
When using MailScanner together with MailWatch and getting the error:
“Could not use Custom Function code MailScanner::CustomConfig::InitMailWatchLogging ……”
the most likely cause is not having Perl DBD installed.
How to change your systems hostname (RHEL / CentOS / Fedora)
Not being one to read documentation, I had a hard time finding this ![]()
Hope this helps someone.
I had to change the hostname for one of my CentOS 5 systems. On most Linux systems, this can be done through the “hostname” command, but that didn’t appear to be permanent. After a reboot the hostname would be reset to the former value.
To permanently change the hostname, edit the “/etc/sysconfig/network” file. It has a line that says “HOSTNAME=”. Change that, and you’ll be happy
This should work for all RHEL / CentOS and Fedora systems.
Automatic email on Yum updates (RHEL / CentOS / Fedora)
I’ve written a small Perl script that sends me an email whenever there are updates for my CentOS 5 system.
I run it from cron every week. Change the email variables and use it to your liking.
Using a MySQL db efficiently from SEC
SEC (Simple Event Correlator) is a great tool developed by Risto Vaarandi that you’ll find here: http://kodu.neti.ee/~risto/sec/
It is a tool that allows you to scan one or multiple log files and act upon events. See the forementioned link for more info.
I wanted to insert records into a MySQL database when Postfix refuses an email. I used to do this by calling a PHP script from SEC with the shellcmd action, but that has two main drawbacks:
I found out that this can be done a lot more efficient with the following method:
This can be done by creating two rules. One that uses the internal startup event to create the database connection and one for detecting and acting upon the event.
Here are the rules:
type=Single
desc=Load DBI and connect to DB at SEC startup or HUP
ptype=RegExp
pattern=(SEC_STARTUP|SEC_RESTART)
context=[SEC_INTERNAL_EVENT]
action=assign %a 0; \
eval %a (use DBI; \
$dbconn = DBI->connect("dbi:mysql:[database name]:localhost", "[db_user]", "[db_pwd]"); 1;); \
eval %a (exit(1) unless %a);
type=Single
ptype=RegExp
desc=$0
pattern=[your pattern here]
action=eval %a (my $query = "[your MySQL query here]";\
$dbconn->do($query);)
Off course, these are examples. You’ll have to fill in your own specific data, especially replacing the “[descriptions]“.
Important note: you’ll have to start SEC with the “-intevents” switch for these rules to work!
The first rule is triggered at SEC startup and connects to the database. The database connection is stored in $dbconn. In the second rule, the connection is reused.
In both rules, SECs eval action is used to execute a bit of Perl code.
I hope the examples are clear enough to reuse for your own purposes