Linux tips & techniques for developers and system administrators.
21 views
Detecting hardware virtualization in Linux
For historical reasons, most systems which ship have the virtualization flag turned off. If you aren’t expecting this, and try to install KVM in a Linux system, you can get unusual errors which don’t necessarily indicate the problem.
This script performs a few simple tests to see if virtualization is active or not. I can’t guarantee that it is complete, but it works on the systems I’ve tested it on. Please use it, and if you find an exception, please let me know so I can update it.
#!/bin/bash
cpuinfo=`egrep '^flags.*(vmx|svm)' /proc/cpuinfo`
if [ "$cpuinfo" = "" ]; then echo "There doesn't appear to be any hardware support for virtualization" exit fi
hardware=`dmesg | grep kvm | grep -i 'no hardware support'` bios=`dmesg | grep kvm | grep -i 'disabled by bios'`
if [ "$hardware" != "" ]; then echo "No hardware support for KVM" exit fi if [ "$bios" != "" ]; then echo "KVM disabled by bios" exit fi58 views
Zabbix – Automatic Filesystem Discovery Update
On our systems, we use a standard Linux template. However, many of our systems have different filesystem layouts, and I didn’t want to have to customize each system as it was installed into Zabbix.
I wrote the attached script to solve this problem. Once the Zabbix client is installed and configured, simply run the attached script and the host will be updated on the Zabbix server. The script is written in Python, a
It requires that two packages (Redhat packages are listed) be installed, using the following command:
yum -y install python-simplejson python-hashlib
It also requires the following file:
https://github.com/gescheit/scripts/blob/master/zabbix/zabbix_api.py
The script assumes that it and the zabbix_api.py file both live in /etc/zabbix/python; if you install it somewhere else, adjust line 9 appropriately.
This works and has been tested on Zabbix 2.0. It _should_ work on 1.8, but I haven’t tested it there.
It requires a username and password for a Zabbix user who has access to the JSON interface.
You will need to update the three lines near the top of the file which list the username, password and Zabbix server.
zabbix_updatefs.py (1.9 KiB, 23 hits)
Bacula & WeBacula Installation Script
Note: The script was updated on 5/17/2013 due to a typo.
We recently had an issue where we lost 3 drives in a RAID 5 array, causing the entire system to be lost. Unfortunately, some data was lost due to the hosting service’s backups not being complete.
As a result of this, we decided to implement our own backup systems as a secondary backup. We decided to use Bacula to do the backups, and WeBacula for a user interface.
Since we have two sites, we needed to set up a backup server in each location. The main intention of the new systems are to do local backups of all the virtual machines which we’ve set up in the past year. Unfortunately, a production VM was on the server which was lost, and we lost some data permanently.
Our environment is a combination of RHEL5, RHEL6, and the equivilant versions of CentOS. We have a local repository set up, so in order to be able to built RPMs for each environment, I wrote an installation script which builds RPMs for each environment. You have to run the script in each environment in order to build the binaries properly.
The script builds the following RPMs for client installs, they should all be installed:
bacula-client.x86_64 – binaries
bacula-client-conf.noarch – Initial config file
bacula-client-redhat.noarch – Startup scripts
For server installs, it builds the following:
bacula-server.x86_64 – binaries
bacula-server-conf.noarch – Initial config file
bacula-server-redhat.noarch – Startup scripts
Since I use the Checkinstall program (be sure to read this about a problem on 64 bit systems), I set it up to build these three RPMs to make it easier to update the binaries.
It has the following limitations:
- PostreSql is forced, there is no option to install MySql
- It assumes either RedHat or CentOS. Any other RHEL-based system will require modifications, search for “centos” in the code
- The database installation code assumes the database is being built and used on the current system
This script was written and tested on both Redhat and CentOS systems.
installbacula.tar.gz (9.2 KiB, 35 hits)
Ganeti 2.6.2
RPMs for RHEL6/CentOS6/SL6 are available here:
Ganeti 2.6.2 (2.8 MiB, 142 hits)
Ganeti 2.6.2 debug (507.0 KiB, 107 hits)
Also,
I’ve uploaded my set of scripts which I wrote and use in administering Ganeti.
They are available at:
http://code.google.com/p/ganeti-scripts/
I’d appreciate any feedback. Suggestions, patches, etc are welcome.
This is a description of the scripts:
The following are additional shell scripts to support the use of ganeti:
gnt-createins
Create a new instance from an existing variant or by installing from an ISO image.
Call with new instance name on cmd line, if not there you will be prompted for it, as well as all other necessary information
gnt-newvariant
Create a new variant from an existing instance. If necessary, the instance is shut down first. Specify the instance on the command
line
gnt-installos
Install an os from an ISO image onto an existing, not-running instance. You can specify the instance name on the command line, otherwise you will be prompted.
gnt-start
Start an instance, display the VNC info for it, and then start the console.
Specify the instance name on the command line
gnt-sync-cluster
Simple shell script to sync various files across all nodes.
Files and directories to be synced are listed in /etc/ganeti/syncfiles.txt
Currently copies various ganeti files in /etc, as well as the various Ganeti directories and /usr/local.
gnt-diskimage
Create a tarball from a QEMU disk image file
gnt-help
This file. For detailed help on a specific command, type the command name as an option. For example:
gnt-help gnt-createins
284 viewsZabbix install script updated to v1.9
Here is the latest update to my zabbix installation script. It defaults to Zabbix 2.0.1, but it checks to see what the latest version is and gives you the option to install it, along with everything else necessary.
I noticed that when doing an upgrade, that the config files aren’t always updated properly. In some cases, old files get deleted. This usually happens when upgrading from an older set of RPMs where the config files are in different RPMs than the current.
To protect against this, the script will back up the zabbix directories before perform the upgrade.
install_zabbix.zip (16.0 KiB, 0 hits)
Monitoring Memcached servers
If you are using memcached, you may want to know if it is running or not, and if it isn’t, to get it started.
The attached script will do that. Run it as on the server which is running the memcached instance(s), as root, from cron, once a minute, and it will check.
In our case, we run multiple memcached instances on a single server. We run memcached on ports 11211 and 11212. The 11212 is used by PHP for session management. The 11211 is used by our application to cache commonly used information.
An example cron entry for this would be:
* * * * * /usr/local/bin/memcached_server_status.sh
You need to set a few parameters at the top to customize it for your configuration.
The script can monitor memcached instances on both the local and remote systems.
The script was written and tested on Redhat and CentOS systems. For any others, the only line you might have to change is the service restart line, around line 78.
Updated 10/25/2012
Added internal loop & sleep, so that multiple checks can be done in a single minute
memcached_server_status.tar.gz (1.7 KiB, 0 hits)
Updated Zabbix install script 1.8 (for Zabbix 2.0.1)
Here is the latest update to my zabbix installation script. It now installs Zabbix 2.0.1, along with everything else necessary.
I noticed that when doing an upgrade, that the config files aren’t always updated properly. In some cases, old files get deleted. This usually happens when upgrading from an older set of RPMs where the config files are in different RPMs than the current.
To protect against this, the script will back up the zabbix directories before perform the upgrade.
This bug has been fixed in the current script, however, if you are upgrading from previous versions, it may happen since the config files were in the wrong RPMs.
Please note that if you downloaded this on 7/12, it had a bug. The current version has been fixed.
install_zabbix.zip (15.8 KiB, 0 hits)
Disk layout for Zabbix server
If you are using my script to install Zabbix, and don’t intend to add anything else to the Zabbix server, then you can partition your disk as follows:
| Disk Partition | Disk Space |
| /boot> | 500 meg |
| / | 5 gig |
| swap | 2x memory (ie. if 1 gig memory, then 2 gig) |
| /var | all remaining disk space |
Generally I don’t like having data on the root partition, so I put it in /var instead. This has worked pretty well for me in my installations.
Count files in all subdirectories, by directory
This is a quickie. I had a need to see how many files were in each directory (not including files in directories underneath)
This little script will do just that, and save the output in a file called “b.csv” (I was lazy). The file will be formatted as a comma separated csv, which you can load into any spreadsheet:
#!/bin/bash
dir=`pwd` [ $# -ne 0 ] && dir=$1 echo $dir
#echo "ls -1 $1 | wc -l" >b.sh
echo "find . -maxdepth 1 -type f -print | wc -l" >b.sh
chmod +x b.sh
find $dir -type d -print -exec ./b.sh {} \; | awk '{printf("%s%s", $0, (NR%2 ? "," : "\n"))}' >b.csv
60 views
CF-Engine 3 Installation
We are starting to use CF-Engine 3. I didn’t find any RPMs for CentOS that I liked, so I whipped up the attached script to download, compile and install CF-engine 3 for me.
This was developed and tested on a CentOS 6.2 system. It should work on RHEL6, SL6, and probably all the RHEL5 based variants as well.
A quick note about the file. Once you download it, uncompress it with gzip:
gzip -d cfengine.sh.gz
and just run the script. This file is something called a “shar” file, which is a way to put files into text. It’s been slightly modified to run the install script after extracting the included files.
Create a new directory for this, and run it from there, as root.
Udated 7/23/2012, now properly handles both Redhat/CentOS/Scientific Linux 5 & 6 releases
Also can now initialize a local install as a non-policy server
cfengine.sh.gz (11.7 KiB, 110 hits)
