Showing posts with label administration. Show all posts
Showing posts with label administration. Show all posts

2013-12-12

Quickly check serial ports with setserial

When I want to quickly check what serial ports are active on a machine, I use the setserial command:
# which setserial
/usr/bin/setserial
# man setserial
...
# setserial -g /dev/ttyS?
/dev/ttyS0, UART: unknown, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: unknown, Port: 0x02f8, IRQ: 3
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3
/dev/ttyS4, UART: 16550A, Port: 0xf0e0, IRQ: 19
/dev/ttyS5, UART: unknown, Port: 0x0000, IRQ: 0
/dev/ttyS6, UART: unknown, Port: 0x0000, IRQ: 0
/dev/ttyS7, UART: unknown, Port: 0x0000, IRQ: 0
/dev/ttyS8, UART: unknown, Port: 0x0000, IRQ: 0
/dev/ttyS9, UART: unknown, Port: 0x0000, IRQ: 0

This is on my laptop, which of course has no physical serial port. The output of setserial -g shows whatever hardware the kernel thinks it can see. With today's laptops, one typically uses a USB-to-serial adapter. In that case, after connecting the adapter I would do:
# dmesg
... review the last few kernel log messages, which will hopefully confirm 
    that the device was recognized ... 
# setserial -g /dev/ttyUSB?
... hopefully see that the device is present, with UART, Port, and IRQ all 
    set up and ready to use ...

2013-12-09

Cisco SG300: Initial setup (Management VLAN, SSH access)

We recently got our hands on some Cisco SG300 52-port "top-of-rack" switches, and I have started taking some "baby steps" with them. Here are some notes on how I got started provisioning the switches.

2013-10-25

How to resize ext3/ext4 filesystem (including root)?

The other day I had to resize (i.e. shrink) the root filesystem on one of our machines. Today a colleague wrote the following concise HOWTO for the same:
1. Reduce the size the file system on your root partition with the tool
   applicable to the file system you have on that partition, such as
   resize2fs, to a size smaller than you need.

2. Resize the partition to the desired size (it has to be bigger than the
   file system from the previous step) using a tool such as fdisk.

3. Increase the file system size to completely fill the new partition
   size (again resize2fs, depending on your file system).

2013-07-25

Postfix: how to set envelope sender address, Return-Path

This is the kind of thing that only appears difficult at first, but in reality is quite easy.

We run a piece of software that sends out emails. The envelope sender address is wwwrun@ourdomain. This is because the Apache2 process runs as the wwwrun user. I need to change the envelope sender address (and hence the Return-Path: as well) to different_address@ourdomain

The fix turned out to be very easy:
# man canonical
# vim /etc/postfix/canonical
[add line 'wwwrun   rt_internal' at bottom of file]
# postmap /etc/postfix/canonical

What time do scripts in /etc/cron.daily run?

I put a script in /etc/cron.daily and would like to know what time it will run. And, more importantly, how does the system determine this time value?

On SUSE Linux Enterprise and openSUSE, the time is determined by the CRON_DAILY parameter in the /etc/sysconfig/cron file. If this parameter is not set, it defaults to 15 minutes after the time of the last boot.

Because of how the mechanism for running scripts in the /etc/cron.{houry,daily,weekly,monthly} directories works, the time value must be a multiple of 15 minutes (i.e. 0, 15, 30, or 45 minutes past the hour). The exact functioning of this mechanism can be seen by studying the following:
# cat /etc/crontab
SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin
MAILTO=root
#
# check scripts in cron.hourly, cron.daily, cron.weekly, and cron.monthly
#
-*/15 * * * *   root  test -x /usr/lib/cron/run-crons && /usr/lib/cron/run-crons >/dev/null 2>&1

This basic cronjob simply runs /usr/lib/cron/run-crons every 15 minutes. The real magic happens inside that script.

A nice discussion of how cron works in SUSE/openSUSE is available in the Support Data Base (SDB): http://en.opensuse.org/SDB:Cron

2013-07-16

Mount and chroot into a foreign Linux partition

Scenario: I have a Linux root partition that isn't booting properly. I need to chroot into it. How to do that?

Answer:
# mount /dev/[something] /mnt
# cd /mnt
# mount -t proc proc proc/
# mount -t sysfs sys sys/
# mount -o bind /dev dev/

After this, I should be able to chroot in and execute binaries (e.g. Yast), update grub (but watch out for /boot), etc.


2013-06-27

How to secure a vanilla MySQL installation

It may seem complicated, but actually it's extremely easy.

The vanilla installation has no root password, so you can do:
# mysql -u root

However, really securing the installation is more involved than simply setting a root password. To make sure "all the bases are covered" (to use a U.S. idiom), use this command:
# /usr/bin/mysql_secure_installation

This is an easy way to effect basic setup so, for example, root can login only from localhost, etc.

If you're not particularly concerned about security, you can put the root password in /etc/my.cnf -- that way, you won't have to type it manually.

2013-05-23

Request Tracker: set up external authentication via LDAPS

This is a description of how I set up my Request Tracker instance to use external authentication via LDAPS (LDAP over SSL on port 636).

  1. In the previous installment, I already added the devel:languages:perl repository. Now I install the package containing the RT::Authen::ExternAuth RT extension that will provide the external-authentication-against-LDAP functionality.
    # zypper ref
    # zypper in perl-RT-Authen-ExternalAuth
    # zypper in perl-Net-SSLeay
    # zypper in perl-ldap-ssl
    
  2. I set up SSL on my system (beyond the scope of this blog entry). At the very least, the openssl package should be installed and configured, and my LDAP server's certificates should be present in the /etc/ssl/certs directory.
  3. I tweak my openldap configuration for CA CERT as per this blog entry
  4. I read up on the RT::Authen::ExternalAuth extension (plugin). Here are the principal documentation resources I was able to find:
  5. After reading the documentation and protracted trial and error, I finally came up with the following working configuration (in RT_SiteConfig.pm):
    Set($ExternalServiceUsesSSLorTLS,    1);
    Set($ExternalSettings, { 
                             'MY_LDAP' =>  {
                                'type'            =>  'ldap',
                                'server'          =>  'ldaps://ldap.example.com',
                                'tls'             =>  0,
                                'ssl_version'     =>  3,
                                ...
    
  6. At this point, I fire up request-tracker and am able to log in with my LDAP credentials!

2013-05-22

openSUSE 12.3: How I installed and set up Request Tracker

A new version of openSUSE is out and my blog entry describing how I installed and set up Request Tracker on openSUSE 12.2 is now out of date.

This blog entry, then, describes how I installed Request Tracker on openSUSE 12.3.

2013-05-15

openSUSE: video playback, codecs

Installing codecs and other non-free libraries for multimedia, video playback, etc. on openSUSE is very easy:

2013-05-08

PostgreSQL: Check if server is running

Check if PostgreSQL server is running in openSUSE 12.2, 12.3 etc. and possibly other systemd-based distributions:

  1. # systemctl status postgresql.service
  2. # netstat -na | grep 5432
  3. # ps ax | grep postgres
  4. # pgrep -l | grep postgres

If all of these look OK, then the server is probably running.

2013-04-08

openSUSE: force logrotate

Sometimes I want to clear out my logfiles now, instead of waiting for the cronjob to do it. The following worked on openSUSE 12.3:
# man logrotate
# logrotate --force /etc/logrotate.conf

2013-03-23

openSUSE 12.3: How to install 'bumblebee' for NVIDIA Optimus VGA

Note: This historical post was intended for me as a memory aid. If you decide to imitate the steps described, know that you are doing so at your own risk.

Bumblebee, etc. is still officially unsupported in openSUSE, but it is possible to get it working in openSUSE 12.3. However, openSUSE 12.3 itself is also history. Nowadays, I am running openSUSE 13.1 with Bumblebee on my Optimus laptop, and there is a new blog entry: http://smithfarm-thebrain.blogspot.cz/2013/10/opensuse-131-nvidia-optimus-bumblebee.html

2013-03-10

Wide-open NAT firewall script using iptables

A couple years ago, I was trying to set up NAT on my home network's firewall/router using iptables, and I was desperate. It seemed that nothing I could do would convince "it" to work. (Hmm, maybe that's why they used to call it a "notwork" on alt.sysadmin.recovery . . . ) In desperation, I posted to a forum and good denizen Sum1 sent me this handy script, which I reproduce here in good will, but without his/her explicit permission:

#!/bin/sh
#
# Sum1's "wide-open, last-resort" NAT firewall
#
# Breathe, step away for a few, have a snack, and let the frustration level
# decline. You are not alone; I definitely know how you feel.
#
# I reserve the following rules for when I face utter frustration and meltdown:

IPTABLES="/usr/sbin/iptables"
LAN_INTERFACE="eth1"
INET_INTERFACE="eth0"
SUBNET1="192.168.0.0/24"

$IPTABLES -t filter -A INPUT -i $LAN_INTERFACE -j ACCEPT
$IPTABLES -t filter -A OUTPUT -o $LAN_INTERFACE -j ACCEPT
$IPTABLES -t filter -A OUTPUT -o $INET_INTERFACE -j ACCEPT
$IPTABLES -t filter -A FORWARD -i $LAN_INTERFACE -s $SUBNET1 -j ACCEPT
$IPTABLES -t filter -A FORWARD -i $LAN_INTERFACE -o $INET_INTERFACE -j ACCEPT
$IPTABLES -t filter -A FORWARD -i $INET_INTERFACE -o $LAN_INTERFACE -j ACCEPT
$IPTABLES -t nat -A POSTROUTING -o $INET_INTERFACE -s $SUBNET1 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

# Everything is now wide open and this is NOT SECURE, but it should allow
# any/every ethernet device on the subnet to access the internet.
#
# If it works, now add the following rule and see if it still does:

$IPTABLES -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -t filter -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -t filter -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

# If you still cannot ping eth1, eth0, and also your primary DNS address, then
# there's more issues to address like static ip's, dhcp servers, and icmp
# stuff.

By the way, the solution to my problem was hinted at in Sum1's last sentence - the problem with the NAT setup was not in the iptables script at all, it was in the DHCP server configuration. It's all inter-related, you see.

2013-02-28

Postfix: delete message from queue

  1. Use mailq to find out message number.
  2. Use postsuper -d [msg_num] to delete the message.




2013-02-24

openSUSE: how to disable "delta RPM"

In order to save bandwidth, zypper is set by default to download so-called "delta RPMs", which are basically just binary patches. The process of applying the delta RPM can be, and often is, more time-consuming than downloading the full RPM.

To disable this behavior, edit the /etc/zypp/zypp.conf file. There are lots of options there and one can learn quite a bit just by reading the comments. The option we are interested in is:
##
## Whether to consider using a .delta.rpm when downloading a package
##
## Valid values: boolean
## Default value: true
##
## Using a delta rpm will decrease the download size for package updates
## since it does not contain all files of the package but only the binary
## diff of changed ones. Recreating the rpm package on the local machine
## is an expensive operation (memory,CPU). If your network connection is
## not too slow, you benefit from disabling .delta.rpm.
##
download.use_deltarpm = false

As in the example above, set it to false.




2013-02-21

Postfix configuration notes

  • Connection refused: look at inet_interfaces - e.g.
    inet_interfaces = $myhostname, localhost
    






2013-02-20

Request Tracker says config file is locked

Symptom: I openrf Request Tracker in my browser and instead of the login screen, it said:
Config file /etc/request-tracker/RT_SiteConfig.pm is locked 

Since I had no idea what the cause could be, I asked Google. All the forum entries it pointed me to said that it's because request-tracker can't access MySQL. But on my system this wasn't the case -- MySQL was running fine.

Checking the logs, I found this intriguing message:

I checked my RT_SiteConfig.pm and, sure enough, I had a trailing slash in the URL. After removing it and restarting Apache, the error went away.

Later, I found that I shouldn't be setting WebBaseURL anyway -- quoting from the RT 4.0 Documentation:
$WebBaseURL, $WebURL

    Usually you don't want to set these options. The only obvious
    reason is if RT is accessible via https protocol on a non standard 
    port, e.g. 'https://rt.example.com:9999'. In all other cases these 
    options are computed using $WebDomain, $WebPort and $WebPath.

2013-02-19

How to send test email from the command line

$ echo "Body of testing email" | mail -s "Testing 123" person@target-domain.com




2013-02-11

openSUSE 12.2: How I installed and set up Request Tracker

One of my projects at work is to learn Request Tracker. Here's how I installed it and got it running on openSUSE 12.2.