Showing posts with label solaris 10. Show all posts
Showing posts with label solaris 10. 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.

Monday, 7 March 2011

Configure a lofs (LOopback virtual FileSystem) shared area between zones

Operating System: Solaris 10 & variants

Create area to be shared on global zone, e.g. /share

mkdir /share

Configure the zones to use the shared area:

# zonecfg -z zone1
zonecfg:zone1> add fs
zonecfg:zone1> set dir=/share
zonecfg:zone1> set special=/share/sharex
zonecfg:zone1> set type=lofs
zonecfg:zone1> end
zonecfg:zone1> verify
zonecfg:zone1> commit
zonecfg:zone1> exit
# zonecfg -z zone2
zonecfg:zone2> add fs
zonecfg:zone2> set dir=/share
zonecfg:zone2> set special=/share/sharex
zonecfg:zone2> set type=lofs
zonecfg:zone2> end
zonecfg:zone2> verify
zonecfg:zone2> commit
zonecfg:zone2> exit
#

Reboot both zones

# zoneadm -z zone1 reboot
# zoneadm -z zone2 reboot

The filesystems will now be available and fully writeable for both zones.  There is no limit to the number of zones that can share the filesystem.

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.