Wednesday 23 May 2012

How To Clear /var/adm/wtmpx

On Solaris if /var/adm/wtmpx has got so big as to break the last command or fill up all your disk space, here's how to fix it:

This will create a new wtmpx file with only the last 100 entries in it.
# /usr/lib/acct/fwtmp < /var/adm/wtmpx | tail -100 > /tmp/wtmpx.ascii
# /usr/lib/acct/fwtmp -ic < /tmp/wtmpx.ascii > /var/adm/wtmpx
# rm /tmp/wtmpx.ascii
fwtmp parses the wtpmx file and dumps out the last 100 entries in ascii to a file.
Rerun fwtmp with the -ic params will read this file and create an equivalent binary wtmpx file to replace yours.

Note: If fwtmp is not available on your system you'll need to install the system accounting packages SUNWaccu & SUNWaccr.

Monday 21 May 2012

How To Share A Disk Using iSCSI

Here's how to share a disk using iSCSI from a RHEL 6 server.
Note that this is the most basic way of setting iSCSI up and is really only useful for familiarisation of using iSCSI clients.

  • Create an LVM logical volume on the desired disk. In this example /dev/sdb 
pvcreate /dev/sdb
vgcreate vg_sdb /dev/sdb
lvcreate --extents 100%FREE --name lv_sdb vg_sbd 
  • Install the iSCSI apps & daemon and start it up 
yum install scsi-target-utils
service tgtd start
chkconfig tgtd on 
  • Add an entry to /etc/tgt/targets.conf to make the disk available.
<target iqn.2012.05.net.home:san.target1>
backing-store /dev/vg_sdb/lv_sdb
</target> 
  • Open the iSCSI ports on the firewall
tcp / udp 3260 & tcp / udp 860

That's it, the disk should now be discoverable as iqn.2012.05.net.home:san.target1.
There is no security set on the disk so you should be able to just log into it.

Friday 11 May 2012

Cisco Network Registrar via the CLI

Can't get the GUI running then use the command line.
/export1/nwreg2/usrbin/nrcmd 
List the zones available:
nrcmd> zone list 
List the records in the knon.dtv zone:
nrcmd> zone knon.dtv listrr 
List the records in a reverse lookup zone:
nrcmd> zone 10.in-addr.arpa listrr 
This example adds myhost.knon.dtv / 10.2.3.4.
Add the hostname to the knon.dtv zone:
nrcmd> zone knon.dtv. addhost myhost 10.2.3.4 
Add the corresponding PTR record (done automatically with the GUI):
nrcmd> zone 10.in-addr.arpa. addrr 4.3.2 PTR myhost.knon.dtv
Tip: To remove resource records
nrcmd> zone 10.in-addr.arpa. removerr 4.3.2.10.in-addr.arpa

Save your records & reload the DNS to activate:
nrcmd> save
nrcmd> dns reload
To force the secondary DNS to update the zone with your new records, log onto it and execute:
nrcmd> zone knon.dtv forceXfer secondary
nrcmd> zone 10.in-addr.arpa forceXfer secondary
 Don't forget to refresh the secondary DNS caches to pick up the new records:
rndc reload lang.dtv
rndc reload 10.in-addr.arpa



Tuesday 1 May 2012

Help! I'm locked out of my Cacti server

There's two stages of locked out.

  • You've forgotten just the admin password to the Cacti web interface
  • You've forgotten the admin password and you've forgotten the mysql database password.
The first is relatively easy to sort

Log into the cacti database and run this
mysql -u root -p <cacti db>
update user_auth set password=md5('newadminpassword') where username='admin';

Now of course you might now know which what the cacti database is called in which case
mysql -u root -p
mysql> show databases;

Look for the database which has some snmp tables in it
mysql> connect <database>;
mysql> show tables;

Now if you can't remember the root password to your Cacti database you need to reset that first. It's not the same as the root password on the server. This is how to reset it.

Create a new ini file, let's call it mysql-ini containing
UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
FLUSH PRIVILEGES;

Shutdown mysql if it is running and restart it directly with this ini file:
mysqld_safe --init-file=mysql-ini &

Now login with the new root password then shut down mysql again. It can now be restarted with the original start script (and ini file) and you can log in with the new root password.