Showing posts with label solaris. Show all posts
Showing posts with label solaris. Show all posts

Monday, 1 August 2011

Very slow log in to Solaris Server

Error keywords seen:  None - just exceptionally slow login

Operating System: Solaris variants

Software: default ssh daemon

Keywords:  solaris stop suppress reverse dns lookup ssh

I've googled many times to find the answer to this one, and read through many man pages.

It's very easy to discover that slow log ins are almost always due to sshd trying to do an nslookup on the login client.  This is a perfectly reasonable security measure, but if the lookup fails it can take a while to timeout, giving the impression that the login is very slow.  In Linux, you change sshd_config and add 'UseDNS no' - this I found recommended many times.

In Solaris, the answer is just as easy, though harder to find:

Add the following line to /etc/ssh/sshd_config:

LookupClientHostnames=no
Restart sshd:

svcadm restart ssh

Check that ssh is running okay - do this before you log out:
svcs -l ssh

If sshd is in maintenance mode, revert your changes and restart ssh:

svcadm clear ssh

Check your change for a typo, and debug as usual.

You should now be able to log in much faster.

Sunday, 10 April 2011

Solaris/OpenIndiana NFS server to Ubuntu NFS host - 4294967294 problem

Error keywords seen:  User and Group set to 4294967294 instead of UID/GID expected

Operating System: Open Indiana oi_148 (Solaris) and Ubuntu 11.04 (Natty Narwhal)

Software: NFS v4


When mounting an nfs shared directory from an OpenIndiana home server, the directory ownership was set to 4294967294:4294967294, despite the ownership on the server being 1000:1000, and the equivalent UID / GID being set up on the client machine.


The solution is to edit the config file /etc/default/nfs-common - the two lines required are:


NEED_STATD="no"
NEED_IDMAPD="yes"



This is enough to change the reported ownership from 4294967294 to 'nobody:nogroup' - which is progress, of a sort.



Our next requirement is to make sure that the nfs client and the nfs server are both using the same domain name.  On the client, change /etc/idmapd.conf so that the domain parameter is correct - in my case, 'homenetwork'.

Domain = homenetwork

Secondly, on the server, make sure that the domainname is correctly set.  As this is running a Solaris(-based) OS, it's very easy - just create or edit the contents of /etc/defaultdomain so that it contains (nothing more than) the correct domain:

homenetwork

And you're done - reboot both sides for luck, and everything should now appear as you expect.

Wednesday, 27 October 2010

Migrating a zone between two global hosts

One feature of Solaris zones is the ability to migrate a non-global zone from one global host to another. In the case of zones built on zfs filesystems, this can be done as follows. (If you're using UFS, substitute tar commands for the zfs commands).

The rationale for this move is that the zone has an interface on VLAN101, but needs a second interface on VLAN102. The global host it is currently attached to (mars) does not have an interface on VLAN102. Another global host (venus) has interfaces on both VLANs, and is therefore an appropriate (in fact the only) candidate for receiving the zone.

Global1=mars
Global2=venus
zone=scorpio

First, let's check the Solaris 10 release level on each box.

(cat /etc/release)
mars: Solaris 10 10/08 s10s_u6wos_07b SPARC
venus: Solaris 10 10/09 s10s_u8wos_08a SPARC

And architecture:
(uname -m)
mars: sun4v
venus: sun4v



Moving from a lower release to a higher one will certainly involve some packages being upgraded, but Solaris will handle most of that automatically. Hopefully.



So, first, let's halt the zone and detach it:
mars# zoneadm -z scorpio halt
mars# zoneadm -z scorpio detach


The zone is now ready for transfer, which we will do with the convenient zfs commands available. If you are not using zfs, tar and ssh will work just as well.


First we'll take a snapshot of the zone filesystem:
mars# zfs snapshot -r rootpool/zones/scorpio@mars

We also have a zfs dataset allocated to the zone, so we'll snapshot that too:
mars# zfs snapshot -r datapool/zones/scorpio@mars

Just quickly check those snapshots have been taken:
mars# zfs list -t snapshot|grep scorpio
rootpool/zones/scorpio@mars
datapool/zones/scorpio@mars
datapool/zones/scorpio/zonedata@mars
datapool/zones/scorpio/zonedata/opt@mars

Great. Now for sending them. Firstly, we'll need to allow a root login (temporarily) on venus:
venus# vi /etc/ssh/sshd_config
change
PermitRootLogin no
to
PermitRootLogin yes
venus# svcadm restart ssh:default

let's send them:
mars# zfs send rootpool/zones/scorpio@mars | ssh root@venus "zfs recv rootpool/zones/scorpio"
Password:
mars# zfs send datapool/zones/scorpio/zonedata@mars | ssh root@venus "zfs recv rootpool/zones/scorpio/zonedata"
Password:
mars# zfs send datapool/zones/scorpio/zonedata/opt@mars | ssh root@venus "zfs recv rootpool/zones/scorpio/zonedata/opt"
Password:

Note that they're being received to the rootpool on venus, as it does not have a datapool configured.

Obviously now change the root login permission back to 'no':
venus# vi /etc/ssh/sshd_config
change
PermitRootLogin yes
to
PermitRootLogin no
venus# svcadm restart ssh:default

Now the datasets are transferred, we can attach the detached zone to the new global host. This is done with zonecfg, as with creating a new zone, but using create -a to specify that we are attaching a zone.
venus# zonecfg -z scorpio
scorpio: No such zone configured
Use 'create' to begin configuring a new zone.
zonecfg:scorpio; create -a /zones/scorpio
Now let's check that has imported all the zone config:
zonecfg:scorpio; info
zonename: scorpio
zonepath: /zones/scorpio
brand: native
autoboot: true
bootargs:
pool:
limitpriv:
scheduling-class: FSS
ip-type: shared
[cpu-shares: 1]
inherit-pkg-dir:
dir: /lib
inherit-pkg-dir:
dir: /platform
inherit-pkg-dir:
dir: /sbin
inherit-pkg-dir:
dir: /usr
net:
address: 10.278.28.35
physical: e1000g101001
defrouter not specified
capped-memory:
physical: 4G
[swap: 4G]
dataset:
name: datapool/zones/scorpio/zonedata
rctl:
name: zone.max-swap
value: (priv=privileged,limit=2147483648,action=deny)
rctl:
name: zone.cpu-shares
value: (priv=privileged,limit=1,action=none)
We'll need to make some changes here, as the zfs dataset is no longer part of datapool, but rootpool, because the interface on VLAN 101 is named differently on venus, and because we need the zone to have a new interface on VLAN 102.

Change interface name:
zonecfg:scorpio; select net address=10.278.28.35
zonecfg:scorpio:net; info
net:
address: 10.278.28.35
physical: e1000g101001
defrouter not specified
zonecfg:scorpio:net; set physical=aggr101001
zonecfg:scorpio:net; end
Add new interface:
zonecfg:scorpio; add net
zonecfg:scorpio:net; set address=10.278.38.35
zonecfg:scorpio:net; set physical=aggr102001
zonecfg:scorpio:net; end
Change dataset name:
zonecfg:scorpio:dataset; set dataset rootpool/zones/scorpio/zonedata/opt@mars
zonecfg:scorpio:dataset; set name=rootpool/zones/scorpio/zonedata/opt
zonecfg:scorpio:dataset; end
Commit these changes and exit:
zonecfg:scorpio; commit
zonecfg:scorpio; exit

The zone is now configured and ready to be attached. But (as we read in the zoneadm manpages):
By default, zoneadm checks package and patch levels on
the machine to which the zone is to be attached. If the
packages/patches that the zone depends on from the glo-
bal zone are different (have different revision numbers)
from the dependent packages/patches on the source
machine, zoneadm reports these conflicts and does not
perform the attach.
Adding a '-u' flag tells Solaris to attempt to upgrade any packages/patches at a lower version in the new zone, though it cannot downgrade packages/patches.

Running without '-u' gives you a long list of package and patch inconsistencies, as we are moving from update 6 to update 8.
root@venus# zoneadm -z scorpio attach -u
zoneadm: zone 'scorpio': ERROR: attempt to downgrade package SUNWlucfg, the source had patch 121430-43 but this system only has 121430-42
zoneadm: zone 'scorpio': ERROR: attempt to downgrade package SUNWlur, the source had patch 121430-43 but this system only has 121430-42
zoneadm: zone 'scorpio': ERROR: attempt to downgrade package SUNWluu, the source had patch 121430-43 but this system only has 121430-42
zoneadm: zone 'scorpio': ERROR: attempt to downgrade package SUNWservicetagr 1.1.4,REV=2008.04.25.09.06 to version 1.0,REV=2007.05.21.20.36
zoneadm: zone 'scorpio': ERROR: attempt to downgrade package SUNWservicetagu 1.1.4,REV=2008.04.25.09.06 to version 1.0,REV=2007.05.21.20.36
zoneadm: zone 'scorpio': ERROR: attempt to downgrade package SUNWstosreg 1.1.4,REV=2008.04.25.09.06 to version 1.0,REV=2007.05.21.20.36
Somewhere along the line, someone has upgraded these packages, and patch 121430 on the u6 box, and they are at a higher level on the zone than they are on the new target global_host.

If this happens to you, it's likely that you'll have a completely different set of patches and packages, and you should proceed accordingly. Here, the Services Tools Bundle has been installed, and the aforementioned patch 121430. I downloaded and applied these to venus.
# zoneadm -z scorpio attach -u
Getting the list of files to remove
Removing 326 files
Remove 24 of 24 packages
Installing 189 files
Add 15 of 15 packages
Updating editable files
The file within the zone contains a log of the zone update.

# zoneadm list -iv | grep scorpio
- scorpio installed /zones/scorpio native shared

# zoneadm -z scorpio boot
# zoneadm list -iv | grep scorpio
81 scorpio running /zones/scorpio native shared
Success!

Thursday, 2 April 2009

Compiling mod_security

Apache version: 2.0.63 / 2.2.11
mod_security version: 2.5.9
Operating System: Solaris 10 (Generic_120011-14 on Sun T2000) non-global zone
Error keywords seen:
configure: *** pcre library not found.;
configure: error: pcre library is required;
configure: *** apr library not found.;
configure: error: apr library is required;
configure: *** apu library not found.;
configure: error: apu library is required;
./configure: line 5518: /app/apache_2.0.63/bin/apr-config/apr-config: Not a directory



Installing mod_security as a shared object should be a simple, straight-forward task - and indeed, the last time I had to do it, I had no problems. However, today I had to compile mod_security on a Solaris 10 zone, and I ran into some unusual problems - partly due to an error in the configure script.

Running through the basic instructions, everything proceeded as expected:

download modsecurity-apache_2.5.9.tar.gz from http://sourceforge.net/project/showfiles.php?group_id=68846&package_id=67646

cp
download modsecurity-apache_2.5.9.tar.gz /tmp
gunzip modsecurity-apache_2.5.9.tar.gz
tar -xf modesecurity-apache_2.5.9.tar
cd /tmp/modsecurity-apache_2.5.9

Check that mod_unique_id is installed and that /usr/lib/libxml2.so is present. Ensure that gcc and ar are present in the PATH.

Okay - ready to run configure:

# ./configure --with-apxs=/app/apache_2.0.63/bin/apxs
checking for g++... g++
...
REDACTED
...
configure: looking for Apache module support via DSO through APXS
configure: found apxs at /app/apache_2.0.63/bin/apxs
configure: checking httpd version
configure: httpd is recent enough
Use of uninitialized value in concatenation (.) or string at /app/apache_2.0.63/bin/apxs line 237.

checking for libpcre config script... no
configure: *** pcre library not found.
configure: error: pcre library is required


So - we pop over to sunfreeware, download pcre-7.8-sol10-sparc-local.gz - transfer this to the global zone, and as root install it:

pkgadd -d ./pcre-7.8-sol10-sparc-local


On with the show:

# ./configure --with-apxs=/app/apache_2.0.63/bin/apxs
checking for g++... g++
...
REDACTED
...
Use of uninitialized value in concatenation (.) or string at /app/apache_2.0.63/bin/apxs line 237.
checking for libpcre config script... /usr/local/bin/pcre-config
configure: using '-L/usr/local/lib -R/usr/local/lib -lpcre' for pcre Library
checking for libapr config script... /app/apache_2.0.63/bin/apxs/apxs
./configure: line 5509: /app/apache_2.0.63/bin/apxs/apxs: Not a directory
./configure: line 5512: /app/apache_2.0.63/bin/apxs/apxs: Not a directory
./configure: line 5515: /app/apache_2.0.63/bin/apxs/apxs: Not a directory
./configure: line 5518: /app/apache_2.0.63/bin/apxs/apxs: Not a directory
configure: *** apr library not found.
configure: error: apr library is required

What's that? Whoever said anything about
/app/apache_2.0.63/bin/apxs/apxs? Where did that come from?

Well, let's address the missing apr library issue first, but adding --with-apr=/app/apache_2.0.63/bin/apr-config to the configure settings:

# ./configure --with-apxs=/app/apache_2.0.63/bin/apxs --with-apr=/app/apache_2.0.63/bin/apr-config
checking for g++... g++
...
REDACTED
...
./configure: line 5509: /app/apache_2.0.63/bin/apr-config/apr-config: Not a directory
configure: apr CFLAGS:
./configure: line 5512: /app/apache_2.0.63/bin/apr-config/apr-config: Not a directory
configure: apr LDFLAGS:
./configure: line 5515: /app/apache_2.0.63/bin/apr-config/apr-config: Not a directory
configure: apr LIBS:
./configure: line 5518: /app/apache_2.0.63/bin/apr-config/apr-config: Not a directory
configure: apr LINK_LD:
configure: *** apr library not found.
configure: error: apr library is required

And we have it again - we've got a doubled apr-config/apr-config - where did that come from?

So I had a look at configure, and we can fix the problem by finding the line:

APR_CONFIG="${with_apr}/${APR_CONFIG}"

and replace with,

APR_CONFIG="${with_apr}"

while we're at it, we note the the same is true of apu-config, so:

find the line:

APU_CONFIG="${with_apu}/${APU_CONFIG}"

and replace with:

APU_CONFIG="${with_apu}"

The bug for this is actually earlier in the code, where the ${withval} parameter isn't stripped down right, but this fix will work well enough for our requirements.

Now we run configure as:

./configure --with-apxs=/app/apache_2.0.63/bin/apxs --with-apr=/app/apache_2.0.63/bin/apr-config --with-apu=/app/apache_2.0.63/bin/apu-config

and it works.

make && make install

- will now finish the installation



------

I've reported this bug to the mod_security project, (https://www.modsecurity.org/tracker/browse/MODSEC-51) - and the bug is known and will be fixed in the 2.5.10 release.

Tuesday, 27 January 2009

How to discover whether Solaris is running in 32- or 64-bit mode

The command is:

isainfo -v

If the following line is present, then Solaris is running in 64-bit mode:

64-bit sparcv9 applications

If only the following line is present, Solaris is running in 32-bit mode:

32-bit sparc applications

Thursday, 8 January 2009

NFS mount a remote directory with solaris

Let's say we have a directory /hiro on server nakamura, which we need to mount as directory /claire on server bennet. We're going to assume that both servers are aware of the other by name (either as an entry in the /etc/hosts file, or dns, etc.) - but if not, you can replace the server names by ip addresses.

If this is a one-off requirement, then on nakamura, we issue the command:
share -F nfs -o rw,public,anon=root /hiro

This will make the directory /hiro available for nfs-mounting.

On bennet, we issue the command:
mount -F nfs nakamura:/hiro /claire

This will make the /hiro directory from nakamura available as the /claire directory on bennet.


However, all of this is transient, and will be lost on a reboot. To make this permanent, edit /etc/nfs/dfstab on nakamura, and add the line:

share -F nfs -o rw,public,anon=root /hiro

You can now share the directory as before, or by the command shareall

On bennet, edit /etc/vfstab and add in the line:

nakamura:/hiro - /claire nfs - yes rw,hard,bg

You can now mount the directory as before, or by the command mount -a, or mount /claire

Tuesday, 6 January 2009

How to rename a zone

Operating System: Solaris 10 (Generic_125100-10 on Sun T2000) global zone


# zoneadm -z oldname halt
# zonecfg -z oldname
zonecfg:oldname> set zonename=newname
zonecfg:oldname> commit
zonecfg:oldname> exit
# zoneadm -z newname boot

To a great extent, that's it - you're done. But it is a good idea also to edit the /etc/hosts and the /etc/inet/ipnodes files, and update them with the new name also.

Friday, 21 November 2008

How to change the name of a Solaris server

This script was written for Solaris 10, but it checks for the presence of all the files it wants to change and allows you to quit or continue if it doesn't find all of them. It was also written for a T2000, hence the interface name being e1000g0, but you can change that easily.


#Change oldname -> newname in the following files:
#
#/etc/hosts
#/etc/hostname.e1000g0 (or bge0)
#/etc/nodename
#/etc/dumpadm.conf
#/etc/inet/ipnodes
#/etc/inet/hosts
#/etc/mnttab
#/etc/sysidcfg

#Accomplish this with...

OLDNAME=old_name_of_server
NEWNAME=new_name_of_server
INTERFACE=e1000g0 (or bge0 and so on)

for FILE in /etc/hosts /etc/hostname.$INTERFACE /etc/nodename /etc/dumpadm.conf /etc/inet/ipnodes /etc/inet/hosts /etc/mnttab /etc/sysidcfg; do

count=0
if [[ ! -f $FILE ]]; then
echo $FILE not found
$count=$(( $count + 1 ))
fi

if [[ $count -gt 0 ]];then
GO="false"
while [[ $GO == "false" ]];do
print -n 'Continue anyway? y/n'
read ANSWER
if [[ "$ANSWER" == "y" ]] || [[ "$ANSWER" == "Y" ]]; then
echo "Okay."
GO="true"
elsif [[ "$ANSWER" == "n" ]] || [[ "$ANSWER" == "Y" ]]; then
echo "Quitting."
exit 0
else
echo "Sorry?"
fi
done
fi


sed s/$OLDNAME/$NEWNAME/g /etc/hosts > /etc/hosts_new
sed s/$OLDNAME/$NEWNAME/g /etc/hostname.$INTERFACE > /etc/hostname.$INTERFACE_new
sed s/$OLDNAME/$NEWNAME/g /etc/nodename > /etc/nodename_new
sed s/$OLDNAME/$NEWNAME/g /etc/dumpadm.conf > /etc/dumpadm.conf_new
sed s/$OLDNAME/$NEWNAME/g /etc/inet/ipnodes > /etc/inet/ipnodes_new
sed s/$OLDNAME/$NEWNAME/g /etc/inet/hosts > /etc/inet/hosts_new
sed s/$OLDNAME/$NEWNAME/g /etc/mnttab > /etc/mnttab_new
sed s/$OLDNAME/$NEWNAME/g /etc/sysidcfg > /etc/sysidcfg_new


#Make sure you back up the current settings...

cp hosts hosts_orig
cp hostname.$INTERFACE hostname.$INTERFACE_orig
cp nodename nodename_orig
cp dumpadm.conf dumpadm.conf_orig
cp inet/ipnodes inet/ipnodes_orig
cp inet/hosts inet/hosts_orig
cp mnttab mnttab_orig
cp sysidcfg sysidcfg_orig



#Feeling brave?

mv hosts_new hosts
mv hostname.$INTERFACE_new hostname.$INTERFACE
mv nodename_new nodename
mv dumpadm.conf_new dumpadm.conf
mv inet/ipnodes_new /inet/ipnodes
mv inet/hosts_new inet/hosts
mv mnttab_new mnttab
mv sysidcfg_new sysidcfg


#Now set the new name:

uname -S $NEWNAME


#Finally, restart:

shutdown -i 6 -g 0 -y