System Integration

May 6, 2011

RAID 0/1 on CentOS

Filed under: CentOS — NyU @ 7:55 am

 

I. Screen 01: RAID in fresh install

Example: 02 hard drive with layout partition ( /boot, swap and “/” )

– After finished setup CentOS, we can check raid by command:

cat /proc/mdstat

– When config Raid CentOS auto config boot from HD 01, we need config boot to another

grup –device-map=/boot/grub/device.map
>>root (hd0,0)
>>setup (hd0)
>>root (hd1,0)
>>setup (hd1)
>>quit

– When one of hard drives and we need to replace another:

Delete all partitions before using
Sync data from old hard drive and new hard rive

sfdisk –d /dev/hd(old) | sfdisk /dev/hd(new)
mdadm /dev/md0 –a /dev/sdb1
mdadm /dev/md1 –a /dev/sdb2
mdadm /dev/md2 –a /dev/sdb3

Add boot to new hard drive

grub –device-map=/boot/grub/device.map
>>root (hd0,0)
>>setup (hd0)
>>root (hd1,0)
>>setup (hd1)
>>quit

II. Screen 02: On running System

This guide explains how to setup software RAID1 on already running CentOS 5.6 systems. The system still able to boot if one of hard drivers fails.

Raid1

fdisk -l

Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         144     1052257+  82  Linux swap / Solaris
/dev/sda3             145         652     4080510   83  Linux

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn’t contain a valid partition table

Load some kernel modules (to avoid reboot)

modprobe linear
modprobe multipath
modprobe raid0
modprobe raid1
modprobe raid5
modprobe raid6
modprobe raid10

cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
unused devices: <none>

This is step by step we will do, prepare sbd for RAID1, copy sda to sdb and add sda to RAID1 array

Copy partition from sda to sdb

sfdisk –dump /dev/sda | sfdisk /dev/sdb
Checking that no-one is using this disk right now …
OK

Disk /dev/sdb: 652 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sdb: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdb1   *        63    208844     208782  83  Linux
/dev/sdb2        208845   2313359    2104515  82  Linux swap / Solaris
/dev/sdb3       2313360  10474379    8161020  83  Linux
/dev/sdb4             0         -          0   0  Empty
Successfully wrote the new partition table

Re-reading the partition table …

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)

fdisk -l

Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         144     1052257+  82  Linux swap / Solaris
/dev/sda3             145         652     4080510   83  Linux

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          13      104391   83  Linux
/dev/sdb2              14         144     1052257+  82  Linux swap / Solaris
/dev/sdb3             145         652     4080510   83  Linux

Change partition type of sbd to Linux Raid autodetect

fdisk /dev/sdb

fdisk

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

Make sure no remain from previous RAID installations on /dev/sdb

[root@localhost ~]# mdadm –zero-superblock /dev/sdb1
mdadm: Unrecognised md component device – /dev/sdb1
[root@localhost ~]# mdadm –zero-superblock /dev/sdb2
mdadm: Unrecognised md component device – /dev/sdb2
[root@localhost ~]# mdadm –zero-superblock /dev/sdb3
mdadm: Unrecognised md component device – /dev/sdb3

Creating RAID arrays

/dev/sdb1 will be add to /dev/md0
/devsdb2 will be add to /dev/md1
/dev/sdb3 will be add to /dev/md2
mdadm –create /dev/md0 –level=1 –raid-disks=2 missing /dev/sdb1
mdadm –create /dev/md1 –level=1 –raid-disks=2 missing /dev/sdb2
mdadm –create /dev/md2 –level=1 –raid-disks=2 missing /dev/sdb3

cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 sdb3[1]
      4080384 blocks [2/1] [_U]

md1 : active raid1 sdb2[1]
      1052160 blocks [2/1] [_U]

md0 : active raid1 sdb1[1]
      104320 blocks [2/1] [_U]

unused devices: <none>

Create filesystems on RAID arrays (ext3 on /dev/md0 and /dev/md2 and swap on /dev/md1)

mkfs.ext3 /dev/md0
mkswap /dev/md1
mkfs.ext3 /dev/md2

Create /etc/mdadm.conf

mdadm –examine –scan > /etc/mdadm.conf
cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=8f21052b:181fd793:b7e843d1:cca7e9d8
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=318b436f:8f651eb2:61d74c09:a3112ebc
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=c360bd08:ce9fd3c6:059b3b51:ce86e085

Mount md0 and md2

mkdir /mnt/{md0,md2}
mount /dev/md0 /mnt/md0
mount /dev/md2 /mnt/md2

mount
/dev/sda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/md0 on /mnt/md0 type ext3 (rw)
/dev/md2 on /mnt/md2 type ext3 (rw)

Modify /etc/fstab. Replace LABEL=/boot with /dev/md0, LABEL=SWAP-sda2 with /dev/md1, and LABEL=/ with /dev/md2

/dev/md2                /                       ext3    defaults        1 1
/dev/md0                /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/md1                swap                    swap    defaults        0 0

Modify /etc/mtab. Replace /dev/sda1 with /dev/md0 and /dev/sda3 with /dev/md2

/dev/md2 / ext3 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
/dev/md0 /boot ext3 rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
/dev/md0 /mnt/md0 ext3 rw 0 0
/dev/md2 /mnt/md2 ext3 rw 0 0

Modify /boot/grub/menu.list add fallback=1 after default=0. Make look like below

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda3
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
fallback=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-238.el5)
        root (hd1,0)
        kernel /vmlinuz-2.6.18-238.el5 ro root=/dev/md2
        initrd /initrd-2.6.18-238.el5.img
title CentOS (2.6.18-238.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-238.el5 ro root=LABEL=/1
        initrd /initrd-2.6.18-238.el5.img

mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_orig
mkinitrd /boot/initrd-`uname -r`.img `uname -r`

Copy sda1 and sda3 to md0 and md2

cp -dpRx / /mnt/md2
cd /boot
cp -dpRx . /mnt/md0

Install GRUB on sdb

grub
Probing devices to guess BIOS drives. This may take a long time.

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists… no
Checking if "/grub/stage1" exists… yes
Checking if "/grub/stage2" exists… yes
Checking if "/grub/e2fs_stage1_5" exists… yes
Running "embed /grub/e2fs_stage1_5 (hd0)"…  15 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/grub/stage2 /grub/grub.conf"… succeeded
Done.
grub> root (hd1,0)
root (hd1,0)
Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd1)
setup (hd1)
Checking if "/boot/grub/stage1" exists… no
Checking if "/grub/stage1" exists… yes
Checking if "/grub/stage2" exists… yes
Checking if "/grub/e2fs_stage1_5" exists… yes
Running "embed /grub/e2fs_stage1_5 (hd1)"…  15 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/grub.conf"… succeeded
Done.
grub> quit
quit

REBOOT system

Update /dev/sda

df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/md2              3.9G  999M  2.7G  27% /
/dev/md0               99M   15M   80M  16% /boot
tmpfs                 501M     0  501M   0% /dev/shm

cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1]
      104320 blocks [2/1] [_U]

md1 : active raid1 sdb2[1]
      1052160 blocks [2/1] [_U]

md2 : active raid1 sdb3[1]
      4080384 blocks [2/1] [_U]

unused devices: <none>

fdisk /dev/sda

Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Add sda1, sda2, sda3 to RAID arrays

mdadm –add /dev/md0 /dev/sda1
mdadm –add /dev/md1 /dev/sda2
mdadm –add /dev/md2 /dev/sda3

watch cat /proc/mdstat

Every 2.0s: cat /proc/mdstat                            Sat May  7 15:59:02 2011

Personalities : [raid1]
md0 : active raid1 sda1[0] sdb1[1]
      104320 blocks [2/2] [UU]

md1 : active raid1 sda2[2] sdb2[1]
      1052160 blocks [2/1] [_U]
        resync=DELAYED

md2 : active raid1 sda3[2] sdb3[1]
      4080384 blocks [2/1] [_U]
      [==>………………]  recovery = 10.3% (423040/4080384) finish=5.0min s
peed=12074K/sec

unused devices: <none>

Finished:

Every 2.0s: cat /proc/mdstat                            Sat May  7 16:09:33 2011

Personalities : [raid1]
md0 : active raid1 sda1[0] sdb1[1]
      104320 blocks [2/2] [UU]

md1 : active raid1 sda2[0] sdb2[1]
      1052160 blocks [2/2] [UU]

md2 : active raid1 sda3[0] sdb3[1]
      4080384 blocks [2/2] [UU]

unused devices: <none>

mdadm –examine –scan > /etc/mdadm.conf
cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=8f21052b:181fd793:b7e843d1:cca7e9d8
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=318b436f:8f651eb2:61d74c09:a3112ebc
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=c360bd08:ce9fd3c6:059b3b51:ce86e085

Edit GRUB menu again

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda3
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
fallback=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-238.el5)
        root (hd1,0)
        kernel /vmlinuz-2.6.18-238.el5 ro root=/dev/md2
        initrd /initrd-2.6.18-238.el5.img
title CentOS (2.6.18-238.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-238.el5 ro root=/dev/md2
        initrd /initrd-2.6.18-238.el5.img

Update ramdisk

mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_orig2
mkinitrd /boot/initrd-`uname -r`.img `uname -r`

REBOOT and FINISHED

April 26, 2011

Samba OpenLDAP PDC on CentOS 5.6

Filed under: CentOS — NyU @ 12:59 am

Packages:
1. Samba 3.0.33
2. OpenLDAP 2.4.25
3. Smbldap-tools 0.9.6

Hostname: pdc-srv.systeminteg.com
Domain: systeminteg.com
IP: 192.168.1.1/24

First: We need setup DNS and DHCP as link below https://systeminteg.wordpress.com/2011/02/13/dynamic-dns-and-dhcp-on-centos-5-x-master-and-slave-failover/

GDS_Network_OpenSource_layout

I use WING repo for packages install

I. Enable Respo WING

cd /etc/yum.repos.d/
wget
http://wing-net.ddo.jp/wing.repo
wget
http://wing-net.ddo.jp/wing-extras.repo
yum –enablerepo=wing update

II. Install OpenLdap, Samba, Smbldap-tools

yum –enablerepo=wing install openlda-servers openldap-clients openldap-servers-overlays nss_ldap samba samba-clients samba-common samba-doc smbldap-tools

II.I. Config Openldap

slappasswd –s {passLDAP}
cp /usr/share/doc/samba-3.0.33/LDAP/samba.schema /etc/openldap/schema/
cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
chown ldap:ldap –R /var/lib/ldap

Edit /etc/openlda/slapd.conf


include        /etc/openldap/schema/samba.schema
include        /etc/openldap/slapd.access.conf

database    bdb
suffix        "dc=systeminteg,dc=com"
checkpoint    1024 15
rootdn        "cn=Manager,dc=systeminteg,dc=com"

rootpw        {passLDAP}

index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub
index entryUUID,entryCSN        eq
index sambaGroupType            eq
index sambaSID                    eq
index sambaSIDList                eq

Edit /etc/openldap/slapd.access.conf

access to attrs=userPassword
        by dn="cn=Manager,dc=systeminteg,dc=com" write
        by self write
        by anonymous auth
        by * none

access to dn.base="" by * read

access to * 
    by dn="cn=Manager,dc=systeminteg,dc=com" write
    by * read

# allow onlu rootdn to read the monitor
access to *
        by dn.exact="cn=Manager,dc=systeminteg,dc=com" read
        by * none

Edit /etc/syslog.conf

Add local4.*   /var/log/slapd.log

Restart syslog:

service syslog restart

Start ldap:

service ldap start
slaptest
chown ldap:ldap –R /var/lib/ldap

Restart ldap:

service ldap restart
chkconfig ldap on

Testing

ldapsearch -x -D ‘cn=Manager,dc=systeminteg,dc=com" -W -s base ‘(onjectclass=*)’ namingContexts

Config authconfig-tui

Choose: Cache Information – Use MD5 Password – Use Shadow Passwords – Use LDAP Authentication – Local authorization is sufficient
Don’t check Use TLS – Server: ldap://192.168.1.1 – Base DN: dc=systeminteg,dc=com

Make an setup.ldif file

# — Start of file —
# Define the top level organization
dn: dc=systeminteg,dc=com
objectClass: dcObject
objectClass: organization
dc: systeminteg
o: SystemInteg
description: System Integration

# Create the organizational unit to hold users
dn: ou=People,dc=systeminteg,dc=com
objectClass: organizationalUnit
ou: People

# Create the organizational unit to hold groups
dn: ou=Group,dc=systeminteg,dc=com
objectClass: organizationalUnit
ou: Group

# Create the organizational units to hold machines
dn: ou=Hosts,dc=systeminteg,dc=com
objectClass: organizationalUnit
ou: Hosts

# Create the organizational unit to hold id mapping
dn: ou=Idmap,dc=systeminteg,dc=com
objectClass: organizationalUnit
ou: Idmap
# — End of file —

Add setup.ldif file

ldapadd -v -D "cn=Manager,dc=systeminteg,dc=com" -x -W -f setup.ldif

Restart Server

chkconfig ldap on
chkconfig nscd on
reboot

II.II Config Samba

Edit /etc/samba/smb.conf

[global]
workgroup = SYSTEMINTEG.COM
netbios name = PDC-SVR
passdb backend = ldapsam:"ldap://pdc-srv.systeminteg.com"
printcap name = cups
printing = cups
security = user
log level = 3

pam password change = yes

ldap ssl = off
ldap passwd sync = yes
ldap admin dn = cn=Manager,dc=systeminteg,dc=com
ldap suffix = dc=systeminteg,dc=com
ldap user suffix = ou=People
ldap group suffix = ou=Group
ldap idmap suffix = ou=Idmap
ldap machine suffix = ou=Hosts

ldap delete dn = Yes
add user script = /usr/sbin/smbldap-useradd -m "%u"
add machine script = /usr/sbin/smbldap-useradd -w "%u"
add group script = /usr/sbin/smbldap-groupadd -p "%g"
add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
set primary group script = /usr/sbin/smbldap-usermod -g "%g" "%u"
delete user script = /usr/sbin/smbldap-userdel "%u"
delete group script = /usr/sbin/smbldap-groupdel "%g"

logon path =
logon drive =
logon home =
#logon script = %U.bat
logon script = startup.bat

domain logons = Yes
os level = 35
preferred master = Yes
domain master = Yes

idmap uid = 15000-20000
idmap gid = 15000-20000

# passwd program = /usr/bin/passwd ‘%u’
unix password sync = no
passwd chat = "*New UNIX password*" %n\n "*Retype new UNIX password*" %n\n "*updated successfully*"
enable privileges = yes
username map = /etc/samba/smbusers
wins support = Yes

server signing = auto
server schannel = auto
#[homes]
#comment = Home Directories
#valid users = %S
#read only = No
#browseable = No

[netlogon]
comment = Network Logon Service
path = /var/lib/samba/netlogon
admin users = root Administrator admin
guest ok = Yes
browseable = No
admin users = Administrator
valid users = %U

#[Profiles]
#comment = Roaming Profile Share
#path = /var/lib/samba/profiles
#read only = No
#profile acls = Yes
#create mask = 0600
#directory mask = 0700

Edit /etc/samba/smbusers

# Unix_name = SMB_name1 SMB_name2 …
root = administrator Administrator admin
nobody = guest pcguest smbguest

testparm
smbpasswd –w {passLDAP}

service smb restart
service winbind restart

chkconfig smb on
chkconfig winbind on

II.III Config smbldap-tools

Get SID:

net getlocalsid

cd /usr/share/doc/smbldap-tools-0.9.6
./configure.pl

Show error

Use of $# is deprecated at configure.pl-org line 313.
  Number found where operator expected at configure.pl-org line 527, near "#  
  Allows not to use smbpasswd (if with_smbpasswd="0"
  (Might be a runaway multi-line "" string starting on line 313)
  (Missing operator before 0?)
  String found where operator expected at configure.pl-org line 532, near "#
  Allows not to use slappasswd (if with_slappasswd=""
  (Might be a runaway multi-line "" string starting on line 527)
  (Missing semicolon on previous line?)
   Number found where operator expected at configure.pl-org line 532, near "#
   Allows not to use slappasswd (if with_slappasswd="0"
  (Missing operator before 0?)
   String found where operator expected at configure.pl-org line 539, near """
  (Might be a runaway multi-line "" string starting on line 532)
  (Missing semicolon on previous line?)
   syntax error at configure.pl-org line 527, near "# Allows not to use
   smbpasswd (if with_smbpasswd="0"
   Execution of configure.pl-org aborted due to compilation errors.

Version-Release number of selected component (if applicable):
  Name        : smbldap-tools
  Version     : 0.9.6       
  Release     : 1.el5      
  Source RPM  : smbldap-tools-0.9.6-1.el5.src.rpm

How reproducible:
  run perl configure.pl

Steps to Reproduce:
1. perl configure.pl
2.
3.

Actual results:

Expected results:

Additional info:
you can solve the problem:
at line 527
  +# Allows not to use smbpasswd (if with_smbpasswd== 0 in smbldap.conf) but
  -# Allows not to use smbpasswd (if with_smbpasswd="0" in smbldap.conf) but

at line 532
  +# Allows not to use smbpasswd (if with_smbpasswd== 0 in smbldap.conf) but
  -# Allows not to use smbpasswd (if with_smbpasswd="0" in smbldap.conf) but

./configure.pl
chmod 600 /etc/smbldap-tools/smbldap_bind.conf

smbldap-populate

mkdir –p /var/lib/samba/{netlogon,profiles}
chmod 2775 /var/lib/samba/profiles
chgrp ‘Domain Users’ /var/lib/samba/profiles
reboot

Testing
Add user: smbldap-useradd -a -m "test01"
Set password: smbldap-passwd test01
ldapsearch -b "ou=People,dc=systeminteg,dc=com" -x "(uid=test01)"

net groupmap list
Joint PDC into domain SYSTEMINTEG.COM
net rpc join -S PDC-SRV Administrator%pass

III. Config SSL/TLS

service ldap stop

cd /etc/pki/tls/misc
./CA -newca
Commonname: exactly hostname

openssl req -newkey rsa:1024 -nodes -keyout newreq.pem -out newreq.pem

./CA -sign

cd /etc/pki/CA
cp cacert.pem /etc/openldap/cacerts/cacert.pem
cd /etc/pki/tls/misc
mv newcert.pem /etc/openldap/cacerts/servercrt.pem
mv newreq.pem /etc/openldap/cacerts/serverkey.pem
chmod 400 /etc/openldap/cacerts/serverkey.pem

Edit /etc/openldap/lapd.conf


TLS_REQCERT demand

Edit /etc/openldap/slapd.conf


TLSCipherSuite HIGH:MEDIUM:+SSLv2
TLSCACertificateFile /etc/openldap/cacerts/cacert.pem
TLSCertificateFile /etc/openldap/cacerts/servercrt.pem
TLSCertificateKeyFile /etc/openldap/cacerts/serverkey.pem
TLSVerifyClient demand

chown ldap:ldap -R /etc/openldap/cacerts/

IV. Config OpenLDAP Mirror Mode

First comment out some lines in slapd.conf (Remember don’t put the space in front of lines)

modulepath    /usr/lib64/openldap
moduleload    syncprov.la

On Node 01

overlay syncprov
syncprov-checkpoint 100 10
syncprov-sessionlog 100

# Global section
serverID 1

# syncrepl directive
syncrepl    rid=001
        provider=ldap://192.168.1.2
        bindmethod=simple
        binddn="cn=Manager,dc=systeminteg,dc=com"
        credentials={passLDAP}
        searchbase="dc=systeminteg,dc=com"
        schemachecking=on
        type=refreshAndPersist
        retry="60 +"

mirrormode on

On Node 02

overlay syncprov
syncprov-checkpoint 100 10
syncprov-sessionlog 100

# Global section
serverID 2

# syncrepl directive
syncrepl        rid=001
         provider=ldap://192.168.1.1
         bindmethod=simple
         binddn="cn=Manager,dc=systeminteg,dc=com"
         credentials={passLDAP}
         searchbase="dc=systeminteg,dc=com"
         schemachecking=on
         type=refreshAndPersist
         retry="60 +"

mirrormode on

Remember move lines to the end of file slapd.conf

# enable monitoring
database monitor

Index:

/etc/openldap/slapd.conf

#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#

include        /etc/openldap/schema/corba.schema
include        /etc/openldap/schema/core.schema
include        /etc/openldap/schema/cosine.schema
include        /etc/openldap/schema/duaconf.schema
include        /etc/openldap/schema/dyngroup.schema
include        /etc/openldap/schema/inetorgperson.schema
include        /etc/openldap/schema/java.schema
include        /etc/openldap/schema/misc.schema
include        /etc/openldap/schema/nis.schema
include        /etc/openldap/schema/openldap.schema
include        /etc/openldap/schema/ppolicy.schema
include        /etc/openldap/schema/collective.schema
include        /etc/openldap/schema/samba.schema
include        /etc/openldap/slapd.access.conf

# Allow LDAPv2 client connections.  This is NOT the default.
allow bind_v2

# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral    ldap://root.openldap.org

pidfile        /var/run/openldap/slapd.pid
argsfile    /var/run/openldap/slapd.args

# Load dynamic backend modules:
modulepath    /usr/lib64/openldap
# or /usr/lib64/openldap
#moduleload accesslog.la
# moduleload auditlog.la
# moduleload back_sql.la
# moduleload denyop.la
# moduleload dyngroup.la
# moduleload dynlist.la
# moduleload lastmod.la
# moduleload pcache.la
# moduleload ppolicy.la
# moduleload refint.la
# moduleload retcode.la
# moduleload rwm.la
moduleload syncprov.la
# moduleload translucent.la
# moduleload unique.la
# moduleload valsort.la

# The next three lines allow use of TLS for encrypting connections using a
# dummy test certificate which you can generate by changing to
# /etc/pki/tls/certs, running "make slapd.pem", and fixing permissions on
# slapd.pem so that the ldap user or group can read it.  Your client software
# may balk at self-signed certificates, however.
# TLSCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
# TLSCertificateFile /etc/pki/tls/certs/slapd.pem
# TLSCertificateKeyFile /etc/pki/tls/certs/slapd.pem

TLSCipherSuite HIGH:MEDIUM:+SSLv2
TLSCACertificateFile /etc/openldap/cacerts/cacert.pem
TLSCertificateFile /etc/openldap/cacerts/servercrt.pem
TLSCertificateKeyFile /etc/openldap/cacerts/serverkey.pem
TLSVerifyClient demand

# Sample security restrictions
#    Require integrity protection (prevent hijacking)
#    Require 112-bit (3DES or better) encryption for updates
#    Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64

# Sample access control policy:
#    Root DSE: allow anyone to read it
#    Subschema (sub)entry DSE: allow anyone to read it
#    Other DSEs:
#        Allow self write access
#        Allow authenticated users read access
#        Allow anonymous users to authenticate
#    Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
#    by self write
#    by users read
#    by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn.  (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!

#######################################################################
# ldbm and/or bdb database definitions
#######################################################################

database    bdb
suffix        "dc=systeminteg,dc=com"
checkpoint    1024 15
rootdn        "cn=Manager,dc=systeminteg,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoided.  See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
# rootpw        secret
# rootpw        {crypt}ijFYNcSNctBYg
rootpw        {passLDAP}

# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory    /var/lib/ldap

loglevel    256

# Indices to maintain for this database
index objectClass                       eq,pres
index ou,cn,mail,surname,givenname      eq,pres,sub
index uidNumber,gidNumber,loginShell    eq,pres
index uid,memberUid                     eq,pres,sub
index nisMapName,nisMapEntry            eq,pres,sub
index entryUUID,entryCSN        eq
index sambaSIDList            eq
index sambaGroupType            eq
index sambaSID                eq

# Replicas of this database
#replogfile /var/lib/ldap/openldap-master-replog
#replica host=ldap-1.example.com:389 starttls=critical
#     bindmethod=sasl saslmech=GSSAPI
#     authcId=host/ldap-master.example.com@EXAMPLE.COM

 

# allow onlu rootdn to read the monitor
#access to *
#        by dn.exact="cn=Manager,dc=my-domain,dc=com" read
#        by * none

overlay syncprov
syncprov-checkpoint 100 10
syncprov-sessionlog 100

# Global section
serverID 1

# syncrepl directive
syncrepl    rid=001
        provider=ldap://192.168.1.2
        bindmethod=simple
        binddn="cn=Manager,dc=systeminteg,dc=com"
        credentials={passLDAP}
        searchbase="dc=systeminteg,dc=com"
        schemachecking=on
        type=refreshAndPersist
        retry="60 +"

mirrormode on

# enable monitoring
database monitor

/etc/openldap/ldap.conf

#
# LDAP Defaults
#

# See ldap.conf(5) for details
# This file should be world readable but not world writable.

#BASE    dc=example, dc=com
#URI    ldap://ldap.example.com ldap://ldap-master.example.com:666

#SIZELIMIT    12
#TIMELIMIT    15
#DEREF        never
URI ldap://192.168.1.1
BASE dc=systeminteg,dc=com
TLS_CACERTDIR /etc/openldap/cacerts

/etc/ldap.conf

# @(#)$Id: ldap.conf,v 1.38 2006/05/15 08:13:31 lukeh Exp $
#
# This is the configuration file for the LDAP nameservice
# switch library and the LDAP PAM module.
#
# The man pages for this file are nss_ldap(5) and pam_ldap(5)
#
# PADL Software
# http://www.padl.com
#

# Your LDAP server. Must be resolvable without using LDAP.
# Multiple hosts may be specified, each separated by a
# space. How long nss_ldap takes to failover depends on
# whether your LDAP client library supports configurable
# network or connect timeouts (see bind_timelimit).
#host 127.0.0.1
host 192.168.1.1

# The distinguished name of the search base.
base dc=systeminteg,dc=com

# Another way to specify your LDAP server is to provide an
# uri with the server name. This allows to use
# Unix Domain Sockets to connect to a local LDAP Server.
#uri ldap://127.0.0.1/
#uri ldaps://127.0.0.1/  
#uri ldapi://%2fvar%2frun%2fldapi_sock/
# Note: %2f encodes the ‘/’ used as directory separator

# The LDAP version to use (defaults to 3
# if supported by client library)
#ldap_version 3

# The distinguished name to bind to the server with.
# Optional: default is to bind anonymously.
#binddn cn=proxyuser,dc=example,dc=com

# The credentials to bind with.
# Optional: default is no credential.
#bindpw secret

# The distinguished name to bind to the server with
# if the effective user ID is root. Password is
# stored in /etc/ldap.secret (mode 600)
#rootbinddn cn=manager,dc=example,dc=com

# The port.
# Optional: default is 389.
#port 389

# The search scope.
#scope sub
#scope one
#scope base

# Search timelimit
#timelimit 30
timelimit 120

# Bind/connect timelimit
#bind_timelimit 30
bind_timelimit 120

# Reconnect policy: hard (default) will retry connecting to
# the software with exponential backoff, soft will fail
# immediately.
#bind_policy hard

# Idle timelimit; client will close connections
# (nss_ldap only) if the server has not been contacted
# for the number of seconds specified below.
#idle_timelimit 3600
idle_timelimit 3600

# Filter to AND with uid=%s
#pam_filter objectclass=account

# The user ID attribute (defaults to uid)
#pam_login_attribute uid

# Search the root DSE for the password policy (works
# with Netscape Directory Server)
#pam_lookup_policy yes

# Check the ‘host’ attribute for access control
# Default is no; if set to yes, and user has no
# value for the host attribute, and pam_ldap is
# configured for account management (authorization)
# then the user will not be allowed to login.
#pam_check_host_attr yes

# Check the ‘authorizedService’ attribute for access
# control
# Default is no; if set to yes, and the user has no
# value for the authorizedService attribute, and
# pam_ldap is configured for account management
# (authorization) then the user will not be allowed
# to login.
#pam_check_service_attr yes

# Group to enforce membership of
#pam_groupdn cn=PAM,ou=Groups,dc=example,dc=com

# Group member attribute
#pam_member_attribute uniquemember

# Specify a minium or maximum UID number allowed
#pam_min_uid 0
#pam_max_uid 0

# Template login attribute, default template user
# (can be overriden by value of former attribute
# in user’s entry)
#pam_login_attribute userPrincipalName
#pam_template_login_attribute uid
#pam_template_login nobody

# HEADS UP: the pam_crypt, pam_nds_passwd,
# and pam_ad_passwd options are no
# longer supported.
#
# Do not hash the password at all; presume
# the directory server will do it, if
# necessary. This is the default.
#pam_password clear

# Hash password locally; required for University of
# Michigan LDAP server, and works with Netscape
# Directory Server if you’re using the UNIX-Crypt
# hash mechanism and not using the NT Synchronization
# service.
#pam_password crypt

# Remove old password first, then update in
# cleartext. Necessary for use with Novell
# Directory Services (NDS)
#pam_password clear_remove_old
#pam_password nds

# RACF is an alias for the above. For use with
# IBM RACF
#pam_password racf

# Update Active Directory password, by
# creating Unicode password and updating
# unicodePwd attribute.
#pam_password ad

# Use the OpenLDAP password change
# extended operation to update the password.
#pam_password exop

# Redirect users to a URL or somesuch on password
# changes.
#pam_password_prohibit_message Please visit http://internal to change your password.

# RFC2307bis naming contexts
# Syntax:
# nss_base_XXX        base?scope?filter
# where scope is {base,one,sub}
# and filter is a filter to be &’d with the
# default filter.
# You can omit the suffix eg:
# nss_base_passwd    ou=People,
# to append the default base DN but this
# may incur a small performance impact.
#nss_base_passwd    ou=People,dc=example,dc=com?one
#nss_base_shadow    ou=People,dc=example,dc=com?one
#nss_base_group        ou=Group,dc=example,dc=com?one
#nss_base_hosts        ou=Hosts,dc=example,dc=com?one
#nss_base_services    ou=Services,dc=example,dc=com?one
#nss_base_networks    ou=Networks,dc=example,dc=com?one
#nss_base_protocols    ou=Protocols,dc=example,dc=com?one
#nss_base_rpc        ou=Rpc,dc=example,dc=com?one
#nss_base_ethers    ou=Ethers,dc=example,dc=com?one
#nss_base_netmasks    ou=Networks,dc=example,dc=com?ne
#nss_base_bootparams    ou=Ethers,dc=example,dc=com?one
#nss_base_aliases    ou=Aliases,dc=example,dc=com?one
#nss_base_netgroup    ou=Netgroup,dc=example,dc=com?one

# Just assume that there are no supplemental groups for these named users
nss_initgroups_ignoreusers root,ldap,named,avahi,haldaemon,dbus,radvd,tomcat,radiusd,news,mailman,nscd,gdm

# attribute/objectclass mapping
# Syntax:
#nss_map_attribute    rfc2307attribute    mapped_attribute
#nss_map_objectclass    rfc2307objectclass    mapped_objectclass

# configure –enable-nds is no longer supported.
# NDS mappings
#nss_map_attribute uniqueMember member

# Services for UNIX 3.5 mappings
#nss_map_objectclass posixAccount User
#nss_map_objectclass shadowAccount User
#nss_map_attribute uid msSFU30Name
#nss_map_attribute uniqueMember msSFU30PosixMember
#nss_map_attribute userPassword msSFU30Password
#nss_map_attribute homeDirectory msSFU30HomeDirectory
#nss_map_attribute homeDirectory msSFUHomeDirectory
#nss_map_objectclass posixGroup Group
#pam_login_attribute msSFU30Name
#pam_filter objectclass=User
#pam_password ad

# configure –enable-mssfu-schema is no longer supported.
# Services for UNIX 2.0 mappings
#nss_map_objectclass posixAccount User
#nss_map_objectclass shadowAccount user
#nss_map_attribute uid msSFUName
#nss_map_attribute uniqueMember posixMember
#nss_map_attribute userPassword msSFUPassword
#nss_map_attribute homeDirectory msSFUHomeDirectory
#nss_map_attribute shadowLastChange pwdLastSet
#nss_map_objectclass posixGroup Group
#nss_map_attribute cn msSFUName
#pam_login_attribute msSFUName
#pam_filter objectclass=User
#pam_password ad

# RFC 2307 (AD) mappings
#nss_map_objectclass posixAccount user
#nss_map_objectclass shadowAccount user
#nss_map_attribute uid sAMAccountName
#nss_map_attribute homeDirectory unixHomeDirectory
#nss_map_attribute shadowLastChange pwdLastSet
#nss_map_objectclass posixGroup group
#nss_map_attribute uniqueMember member
#pam_login_attribute sAMAccountName
#pam_filter objectclass=User
#pam_password ad

# configure –enable-authpassword is no longer supported
# AuthPassword mappings
#nss_map_attribute userPassword authPassword

# AIX SecureWay mappings
#nss_map_objectclass posixAccount aixAccount
#nss_base_passwd ou=aixaccount,?one
#nss_map_attribute uid userName
#nss_map_attribute gidNumber gid
#nss_map_attribute uidNumber uid
#nss_map_attribute userPassword passwordChar
#nss_map_objectclass posixGroup aixAccessGroup
#nss_base_group ou=aixgroup,?one
#nss_map_attribute cn groupName
#nss_map_attribute uniqueMember member
#pam_login_attribute userName
#pam_filter objectclass=aixAccount
#pam_password clear

# Netscape SDK LDAPS
#ssl on

# Netscape SDK SSL options
#sslpath /etc/ssl/certs

# OpenLDAP SSL mechanism
# start_tls mechanism uses the normal LDAP port, LDAPS typically 636
#ssl start_tls
#ssl on

# OpenLDAP SSL options
# Require and verify server certificate (yes/no)
# Default is to use libldap’s default behavior, which can be configured in
# /etc/openldap/ldap.conf using the TLS_REQCERT setting.  The default for
# OpenLDAP 2.0 and earlier is "no", for 2.1 and later is "yes".
#tls_checkpeer yes

# CA certificates for server certificate verification
# At least one of these are required if tls_checkpeer is "yes"
#tls_cacertfile /etc/ssl/ca.cert
#tls_cacertdir /etc/ssl/certs

# Seed the PRNG if /dev/urandom is not provided
#tls_randfile /var/run/egd-pool

# SSL cipher suite
# See man ciphers for syntax
#tls_ciphers TLSv1

# Client certificate and key
# Use these, if your server requires client authentication.
#tls_cert
#tls_key

# Disable SASL security layers. This is needed for AD.
#sasl_secprops maxssf=0

# Override the default Kerberos ticket cache location.
#krb5_ccname FILE:/etc/.ldapcache

# SASL mechanism for PAM authentication – use is experimental
# at present and does not support password policy control
#pam_sasl_mech DIGEST-MD5
uri ldap://192.168.1.1
ssl no
tls_cacertdir /etc/openldap/cacerts
pam_password md5

/etc/samba/smb.conf

[global]
workgroup = SYSTEMINTEG.COM
netbios name = PDC-SVR
passdb backend = ldapsam:"ldap://pdc-srv.systeminteg.com"
printcap name = cups
printing = cups
security = user
log level = 3

pam password change = yes

ldap ssl = off
ldap passwd sync = yes
ldap admin dn = cn=Manager,dc=systeminteg,dc=com
ldap suffix = dc=systeminteg,dc=com
ldap user suffix = ou=People
ldap group suffix = ou=Group
ldap idmap suffix = ou=Idmap
ldap machine suffix = ou=Hosts

ldap delete dn = Yes
add user script = /usr/sbin/smbldap-useradd -m "%u"
add machine script = /usr/sbin/smbldap-useradd -w "%u"
add group script = /usr/sbin/smbldap-groupadd -p "%g"
add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
set primary group script = /usr/sbin/smbldap-usermod -g "%g" "%u"
delete user script = /usr/sbin/smbldap-userdel "%u"
delete group script = /usr/sbin/smbldap-groupdel "%g"

logon path =
logon drive =
logon home =
#logon script = %U.bat
logon script = startup.bat

domain logons = Yes
os level = 35
preferred master = Yes
domain master = Yes

idmap uid = 15000-20000
idmap gid = 15000-20000

# passwd program = /usr/bin/passwd ‘%u’
unix password sync = no
passwd chat = "*New UNIX password*" %n\n "*Retype new UNIX password*" %n\n "*updated successfully*"
enable privileges = yes
username map = /etc/samba/smbusers
wins support = Yes

server signing = auto
server schannel = auto
#[homes]
#comment = Home Directories
#valid users = %S
#read only = No
#browseable = No

[netlogon]
comment = Network Logon Service
path = /var/lib/samba/netlogon
admin users = root Administrator admin
guest ok = Yes
browseable = No
admin users = Administrator
valid users = %U

#[Profiles]
#comment = Roaming Profile Share
#path = /var/lib/samba/profiles
#read only = No
#profile acls = Yes
#create mask = 0600
#directory mask = 0700

/etc/samba/smbusers

# Unix_name = SMB_name1 SMB_name2 …
root = administrator Administrator admin
nobody = guest pcguest smbguest

/etc/smbldap-tools/smbldap.conf

# $Source: /opt/cvs/samba/smbldap-tools/configure.pl,v
# smbldap-tools.conf : Q & D configuration file for smbldap-tools

#  This code was developped by IDEALX (http://IDEALX.org/) and
#  contributors (their names can be found in the CONTRIBUTORS file).
#
#                 Copyright (C) 2001-2002 IDEALX
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place – Suite 330, Boston, MA 02111-1307,
#  USA.

#  Purpose :
#       . be the configuration file for all smbldap-tools scripts

##############################################################################
#
# General Configuration
#
##############################################################################

# Put your own SID. To obtain this number do: "net getlocalsid".
# If not defined, parameter is taking from "net getlocalsid" return
SID="S-1-5-21-2238024752-698867721-3687915981"

# Domain name the Samba server is in charged.
# If not defined, parameter is taking from smb.conf configuration file
# Ex: sambaDomain="IDEALX-NT"
sambaDomain="SYSTEMINTEG.COM"

##############################################################################
#
# LDAP Configuration
#
##############################################################################

# Notes: to use to dual ldap servers backend for Samba, you must patch
# Samba with the dual-head patch from IDEALX. If not using this patch
# just use the same server for slaveLDAP and masterLDAP.
# Those two servers declarations can also be used when you have
# . one master LDAP server where all writing operations must be done
# . one slave LDAP server where all reading operations must be done
#   (typically a replication directory)

# Slave LDAP server
# Ex: slaveLDAP=127.0.0.1
# If not defined, parameter is set to "127.0.0.1"
slaveLDAP="192.168.1.2"

# Slave LDAP port
# If not defined, parameter is set to "389"
slavePort="389"

# Master LDAP server: needed for write operations
# Ex: masterLDAP=127.0.0.1
# If not defined, parameter is set to "127.0.0.1"
masterLDAP="192.168.1.1"

# Master LDAP port
# If not defined, parameter is set to "389"
masterPort="389"

# Use TLS for LDAP
# If set to 1, this option will use start_tls for connection
# (you should also used the port 389)
# If not defined, parameter is set to "1"
ldapTLS="0"

# How to verify the server’s certificate (none, optional or require)
# see "man Net::LDAP" in start_tls section for more details
verify=""

# CA certificate
# see "man Net::LDAP" in start_tls section for more details
cafile=""

# certificate to use to connect to the ldap server
# see "man Net::LDAP" in start_tls section for more details
clientcert=""

# key certificate to use to connect to the ldap server
# see "man Net::LDAP" in start_tls section for more details
clientkey=""

# LDAP Suffix
# Ex: suffix=dc=IDEALX,dc=ORG
suffix="dc=systeminteg,dc=com"

# Where are stored Users
# Ex: usersdn="ou=Users,dc=IDEALX,dc=ORG"
# Warning: if ‘suffix’ is not set here, you must set the full dn for usersdn
usersdn="ou=People,${suffix}"

# Where are stored Computers
# Ex: computersdn="ou=Computers,dc=IDEALX,dc=ORG"
# Warning: if ‘suffix’ is not set here, you must set the full dn for computersdn
computersdn="ou=Hosts,${suffix}"

# Where are stored Groups
# Ex: groupsdn="ou=Groups,dc=IDEALX,dc=ORG"
# Warning: if ‘suffix’ is not set here, you must set the full dn for groupsdn
groupsdn="ou=Group,${suffix}"

# Where are stored Idmap entries (used if samba is a domain member server)
# Ex: groupsdn="ou=Idmap,dc=IDEALX,dc=ORG"
# Warning: if ‘suffix’ is not set here, you must set the full dn for idmapdn
idmapdn="ou=Idmap,${suffix}"

# Where to store next uidNumber and gidNumber available for new users and groups
# If not defined, entries are stored in sambaDomainName object.
# Ex: sambaUnixIdPooldn="sambaDomainName=${sambaDomain},${suffix}"
# Ex: sambaUnixIdPooldn="cn=NextFreeUnixId,${suffix}"
sambaUnixIdPooldn="sambaDomainName=SYSTEMINTEG.COM,${suffix}"

# Default scope Used
scope="sub"

# Unix password encryption (CRYPT, MD5, SMD5, SSHA, SHA, CLEARTEXT)
hash_encrypt="SSHA"

# if hash_encrypt is set to CRYPT, you may set a salt format.
# default is "%s", but many systems will generate MD5 hashed
# passwords if you use "$1$%.8s". This parameter is optional!
crypt_salt_format=""

##############################################################################
#
# Unix Accounts Configuration
#
##############################################################################

# Login defs
# Default Login Shell
# Ex: userLoginShell="/bin/bash"
userLoginShell="/bin/bash"

# Home directory
# Ex: userHome="/home/%U"
userHome="/home/%U"

# Default mode used for user homeDirectory
userHomeDirectoryMode="700"

# Gecos
userGecos="System User"

# Default User (POSIX and Samba) GID
defaultUserGid="513"

# Default Computer (Samba) GID
defaultComputerGid="515"

# Skel dir
skeletonDir="/etc/skel"

# Default password validation time (time in days) Comment the next line if
# you don’t want password to be enable for defaultMaxPasswordAge days (be
# careful to the sambaPwdMustChange attribute’s value)
defaultMaxPasswordAge="45"

##############################################################################
#
# SAMBA Configuration
#
##############################################################################

# The UNC path to home drives location (%U username substitution)
# Just set it to a null string if you want to use the smb.conf ‘logon home’
# directive and/or disable roaming profiles
# Ex: userSmbHome="\\PDC-SMB3\%U"
userSmbHome=""

# The UNC path to profiles locations (%U username substitution)
# Just set it to a null string if you want to use the smb.conf ‘logon path’
# directive and/or disable roaming profiles
# Ex: userProfile="\\PDC-SMB3\profiles\%U"
userProfile=""

# The default Home Drive Letter mapping
# (will be automatically mapped at logon time if home directory exist)
# Ex: userHomeDrive="H:"
userHomeDrive=""

# The default user netlogon script name (%U username substitution)
# if not used, will be automatically username.cmd
# make sure script file is edited under dos
# Ex: userScript="startup.cmd" # make sure script file is edited under dos
userScript="logon.bat"

# Domain appended to the users "mail"-attribute
# when smbldap-useradd -M is used
# Ex: mailDomain="idealx.com"
mailDomain="systeminteg.com"

##############################################################################
#
# SMBLDAP-TOOLS Configuration (default are ok for a RedHat)
#
##############################################################################

# Allows not to use smbpasswd (if with_smbpasswd== 0 in smbldap.conf) but
# prefer Crypt::SmbHash library
with_smbpasswd="0"
smbpasswd="/usr/bin/smbpasswd"

# Allows not to use slappasswd (if with_slappasswd== 0 in smbldap.conf)
# but prefer Crypt:: libraries
with_slappasswd="0"
slappasswd="/usr/sbin/slappasswd"

# comment out the following line to get rid of the default banner
# no_banner="1"

/etc/smbldap-tools/smbldap_bind

############################
# Credential Configuration #
############################
# Notes: you can specify two differents configuration if you use a
# master ldap for writing access and a slave ldap server for reading access
# By default, we will use the same DN (so it will work for standard Samba
# release)
slaveDN="cn=Manager,dc=systeminteg,dc=com"
slavePw="passLDAP"
masterDN="cn=Manager,dc=systeminteg,dc=com"
masterPw="passLDAP"

April 5, 2011

Compile OpenLDAP 2.4 on CentOS 5.5

Filed under: CentOS — Tags: — NyU @ 5:05 am

I want deploy OpenLDAP as mirror mode. CentOS 5.5 was release old version OpenLDAP 2.3 so I must compile it.
OpenLDAP 2.4 support db version >= 4.4
Need package: db-4.8.30.tar.gz, openldap-stable-20100719.tgz

db-4.8.30.tar.gz –> Link http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz
openldap-stable-20100719.tgz –> Link ftp://ftp.openldap.org/pub/OpenLDAP/openldap-stable/openldap-stable-20100719.tgz

mkdir /setup
First install DB Berkeley
cd /setup/db-4.8.30/build_unix
../dist/configure –prefix=/usr/local/db4
make
make install

Second install OpenLDAP
cd /setup/openldap-2.4.23/
./configure –prefix=/usr –libexecdir=/usr/sbin –sysconfdir=/etc –localstatedir=/srv/ldap –disable-debug –disable-ndb –enable-dynamic –enable-crypt –enable-modules –enable-rlookups –enable-backends –enable-overlays  –with-tls –disable-sql –with-system-libtool  –disable-ltdl-install

Error:
checking for ltdl.h… no
configure: error: could not locate libtool ltdl.h
—–> Fix: yum install libtool-ltdl-devel openssl-devel

Error:
checking db.h usability… no
checking db.h presence… no
checking for db.h… no
configure: error: BDB/HDB: BerkeleyDB not available
—–> Fix:
export CPPFLAGS="-I/usr/local/db4/include"
export LDFLAGS="-L/usr/local/db4/lib -R/usr/local/db4/lib"
export LD_LIBRARY_PATH=/setup/db-4.8.30/build_unix/.libs

make
Error:
/usr/lib/libltdl.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[2]: *** [slapd] Error 1
make[2]: Leaving directory `/setup/openldap-2.4.23/servers/slapd’
make[1]: *** [all-common] Error 1
make[1]: Leaving directory `/setup/openldap-2.4.23/servers’
make: *** [all-common] Error 1
—–> Fix: mv /usr/lib/libltdl.so /tmp/ && ln -s /usr/lib64/libltdl.so /usr/lib/

make install
ln -s /usr/lib/libldap_r-2.4.so.2 /usr/lib64/
ln -s /usr/lib/liblber-2.4.so.2 /usr/lib64/

Third make OpenLDAP auto start on booting
http://ltb-project.org/wiki/documentation/openldap-initscript

#!/bin/sh

#====================================================================
# Start/stop script for OpenLDAP (2.2 minimum)
# (
http://www.openldap.org).
# Use BerkeleyDB utilities and save data in LDIF format.
#
# chkconfig: 2345 85 15
# description: OpenLDAP
#
### BEGIN INIT INFO
# Provides:          slapd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Should-Start:      $network $time
# Should-Stop:       $network $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OpenLDAP
# Description:       OpenLDAP init script provided by LTB-project.org
### END INIT INFO
#
# Copyright (C) 2008 Jonathan CLARKE
# Copyright (C) 2007 Olivier LI-KIANG-CHEONG
# Copyright (C) 2007 Thomas CHEMINEAU
# Copyright (C) 2005 Sebastien BAHLOUL
# Copyright (C) 2005 Raphael OUAZANA
# Copyright (C) 2005 Clement OUDOT
# Copyright (C) 2010 LTB-project.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# GPL License:
http://www.gnu.org/licenses/gpl.txt
#
#====================================================================

#====================================================================
# Changelog
#====================================================================
# Version 1.2 (2011)
# – Add debug target (#303)
# Author: Clement OUDOT (LTB-project)
#
# Version 1.1 (2010)
# – Suffix not well displayed instatus (#243)
# Author: Clement OUDOT (LTB-project)
#
# Version 1.0 (05/2010)
# – Possibility to compress saved files
# Author: Clement OUDOT (LTB-project)
# Author: James LEVER
#
# Version 0.9 (10/2009)
# – Get conf values from file or back-config
# – Change parameter name relative to slurpd
# – Refactor some portion of the entire code
# – Add LSB init script informations
# – Add force-reload target (LSB compliance)
# Author: Clement OUDOT (LTB-project)
# Author: Thomas CHEMINEAU
#
# Version 0.8 (07/2009)
# – Don’t require slapd to be stopped to check configuration
# – configtest can use the configuration directory if present
# – BerkeleyDB utils not mandatory to run the script
# – Add status target
# Author: Jonathan CLARKE (jonathan@phillipoux.net)
# Author: Clement OUDOT (LTB-project)
#
# Version 0.7 (06/2009):
# – SSLIP parameter
# Author: Clement OUDOT (LTB-project)
#
# Version 0.6.5 (07/2008):
# – renamed $UID and $GID to $MYUID and $MYGID to enable bash compatibility
# since $UID is read-only in bash
# – do not run "mkdir $BACKUP_PATH" through $SU command, it is unlikely to
# have permission to do that
# – corrected bug in check for slurpd activation in slapd.conf (-ne instead
# of -eq)
# – do not save "slapcat" output through $SU command for backup,
# the SLAPD_USER generally does not have write permission for that
# Author: Jonathan CLARKE (LINAGORA)
#
# Version 0.6.4 (03/2008):
# – changed default PS command to "ps -efww" to avoid truncating
# output, and put it in global variable $PS_COMMAND
# Author: Jonathan CLARKE (LINAGORA)
#
# Version 0.6.3 (01/2008):
# – add SLAPD_CONF_DIR global parameter, so that the directory could be run
# through a configuration directory unless the traditional slapd.conf file
# – replace all ps commands by standard ps commands, for UNIX compatitiblity
# (tested under Linux and Solaris), same with id command (add $MYUID and $MYGID)
# – some correctives measures, so that special characters are escaped in
# $SLAPD_SERVICES global parameter
# – only check if SLURPD_BIN is executable if the config file specifies slurpd
# replication
# Authors: Thomas CHEMINEAU (LINAGORA)
#          Jonathan CLARKE (LINAGORA)
#
# Version 0.6 (08/2007)
# – Check the pidfile directory exists with correct permissions
# – Change the "su command"
# Author: Olivier LI-KIANG-CHEONG
#
# Version 0.5 (05/2007):
# – function to get values of parameters in config file.
# – do backup and restore operations for all databases declared
# in config file (combined with awk and low level of regexp in grep).
# – some correctives measures
# Author: Thomas CHEMINEAU (LINAGORA)
#
# Version 0.4 (10/2005):
# – change init level
# Author: Raphael OUAZANA (LINAGORA)
#
# Version 0.3 (10/2005):
# – check port before killing process, cause several instances can
# be running.
# – If a user is configured, do a su before launching slurpd
# Author: Clement OUDOT (LINAGORA)
#
# Version 0.2 (09/2005):
# – Add chkconfig comments for RedHat
# – If a user is configured, do a su before launching utilities
# Author: Clement OUDOT (LINAGORA)
#
# Version 0.1 (08/2005):
# – First version with all scripts done by LINAGORA
# Author: Clement OUDOT (LINAGORA)
#====================================================================

#====================================================================
# Default parameters (if /etc/default/{script_name} is not present)
#====================================================================
# IP and port to listen (use wildcard * in IP to listen on all interfaces)
IP="*"
SSLIP="*"
PORT="389"
SSLPORT="636"

# OpenLDAP directory and files
SLAPD_PATH="/etc/openldap"
SLAPD_PID_FILE="srv/ldap/openldap/run/slapd.pid"
SLAPD_CONF="/etc/openldap/slapd.conf"
SLAPD_CONF_DIR=""
SLAPD_SERVICES="ldap://$IP:$PORT ldaps://$SSLIP:$SSLPORT"
SLAPD_PARAMS=""
SLAPD_BIN="/usr/sbin/slapd"
SLAPD_USER=""
SLAPD_GROUP=""

DATA_PATH="/srv/ldap/openldap-data"

SLAPCAT_BIN="/usr/sbin/slapcat"
SLAPINDEX_BIN="/usr/sbin/slapindex"
SLAPTEST_BIN="/usr/sbin/slaptest"

#SLURPD_ACTIVATE="0"
#SLURPD_PID_FILE="$SLAPD_PATH/var/run/slurpd.pid"
#SLURPD_PARAMS=""
#SLURPD_BIN="$SLAPD_PATH/libexec/slurpd"

# BerkeleyDB directory and files
BDB_PATH="/usr/local/db4"
DB_ARCHIVE_BIN="$BDB_PATH/bin/db_archive"
DB_RECOVER_BIN="$BDB_PATH/bin/db_recover"
RECOVER_AT_STARTUP="1" # 0 for OpenLDAP 2.3.x

# Backup
BACKUP_AT_SHUTDOWN="1"
BACKUP_PATH="/tmp/openldap"
BACKUP_FILE="$BACKUP_PATH/data_`date +%Y%m%d%H%M%S`.ldif"
BACKUP_SUFFIX="`date +%Y%m%d%H%M%S`.ldif"
BACKUP_COMPRESS_EXT="" # gz, bz2, …
BACKUP_COMPRESS_BIN="" # /bin/gzip, /bin/bzip2, …

# Other
TIMEOUT="60"      # Max time to stop process
FD_LIMIT="2048"   # Max file descriptor
DEBUG_LEVEL="256" # Debug loglevel
SPECIAL_QUOTE="1" # Quote some command line parameters (eg: LDAP filters)

# Script specific
PROG_NAME=`basename $0 | sed ‘s/^[KS][0-9][0-9]//’` # For nice messages
OS=`uname -s`   # To adapt message printing
MYUID=`id -u`     # For UNIX compatibility => modify this command
MYGID=`id -g`     # For UNIX compatibility => modify this command
PS_COMMAND="ps -efww"    # This ensures full width for ps output but doesn’t work on Solaris – use "ps -ef"

# Return functions’ value
RETVAL=""

#====================================================================
# Message function
#====================================================================
message() {
    # $1: syslog level
    # $2: message

    if [ $OS = "Linux" ]
    then
        logger -p "local4.$1" -s -t $PROG_NAME -i "$2"
    else
        # Try without option -s
        logger -p "local4.$1" -t $PROG_NAME -i "$2"
        echo "$PROG_NAME: $2"
    fi
}

#====================================================================
# Specific functions
#====================================================================

get_confvalues() {
    # $1: parameter
    # $RETVAL: list of values

        # Search in conffile or backconfig
    if [ -n "$SLAPD_CONF_DIR" ]; then
        case $1 in
    directory)
        backconfig_get_values "olcDbDirectory"
    ;;
    suffix)
        backconfig_get_values "olcSuffix" "(|(objectclass=olcBdbConfig)(objectclass=olcHdbConfig))"
    ;;
        *)
        RETVAL=""
    ;;
    esac
        else
        conffile_get_values $1
    fi
}

conffile_get_values() {
    # $1: parameter in slapd.conf
    # $RETVAL: list of values

    list=`grep "^$1[[:space:]]" $SLAPD_CONF | grep -v ‘^#’ | sed "s/$1[[:space:]]*//" | sed "s/ /#20/g"| sed -e ‘s/"//g’`

    if [ "$list" ]; then
        RETVAL="$list"
    else
        RETVAL=""
    fi
}

backconfig_get_values() {
    # $1: parameter
    # $2: LDAP filter (optional)
    # $RETVAL: list of returned values

    if [ -z "$SLAPD_CONF_DIR" -o ! -d "$SLAPD_CONF_DIR" ]
    then
        message "alert" "[ALERT] Could not parse configuration directory"
        RETVAL=""
        return
    fi

    slapcat_cmd="$SLAPCAT_BIN -F $SLAPD_CONF_DIR -b cn=config"
    if [ -n "$2" ]
    then
        if [ $SPECIAL_QUOTE -eq 1 ]; then
            slapcat_cmd="$slapcat_cmd -a ‘$2’"
        else
            slapcat_cmd="$slapcat_cmd -a $2"
        fi
    fi
    if [ -z "$SU" ]
    then
        list=`$slapcat_cmd | perl -p0e ‘s/\n //g’ | grep "^$1:" | sed "s/$1: //" | sed "s/ /#20/g"`
    else
        list=`$SU "$slapcat_cmd" | perl -p0e ‘s/\n //g’ | grep "^$1:" | sed "s/$1: //" | sed "s/ /#20/g"`
    fi

    if [ -n "$list" ]; then
        RETVAL="$list"
    else
        RETVAL=""
    fi
}

#====================================================================
# Load specific parameters
#====================================================================
if [ -f /etc/default/$PROG_NAME ]
then
    . /etc/default/$PROG_NAME
    message "info" "[INFO] Using /etc/default/$PROG_NAME for configuration"
else
    message "info" "[INFO] Using built-in configuration – this may cause some problems"
fi

#====================================================================
# Initiate ‘su’ command
#====================================================================
if [ "$SLAPD_USER" -a $MYUID -eq 0 ]
then
    SU="su -s /bin/bash – $SLAPD_USER -c "
fi

#====================================================================
# Initial checks
#====================================================================

# Make sure the pidfile directory exists with correct permissions
piddir=`dirname "$SLAPD_PID_FILE"`
if [ ! -d "$piddir" ]; then
    mkdir -p "$piddir"
    [ -z "$SLAPD_USER" ] || chown -R "$SLAPD_USER" "$piddir"
    [ -z "$SLAPD_GROUP" ] || chgrp -R "$SLAPD_GROUP" "$piddir"
fi

# Rights to execute binaries
for i in "$SLAPD_BIN" "$SLAPCAT_BIN" "$SLAPINDEX_BIN" "$SLAPTEST_BIN"
do
    if [ ! -x $i ]
    then
        message "alert" "[ALERT] can’t execute $i"
        exit 1
    fi
done

# Rights to read files
for i in "$SLAPD_CONF"
do
    if [ ! -r $i ]
    then
        message "alert" "[ALERT] can’t read $i"
        exit 1
    fi
done

# Activate slurpd? (get from configuration file)
if [ -n "$SLAPD_CONF" ]; then
    SLURPD_ACTIVATE=`grep "^replica" $SLAPD_CONF | wc -l`
fi

# Right to execute slurpd, if used
if [ $SLURPD_ACTIVATE -ne 0 -a ! -x "$SLURPD_BIN" ]
then
    message "alert" "[ALERT] can’t not execute $SLURPD_BIN"
    exit 1
fi

# Is there a configuration directory ?
if [ "$SLAPD_CONF_DIR" -a ! -w "$SLAPD_CONF_DIR" ]
then
    message "alert" "[ALERT] can’t write to configuration directory $SLAPD_CONF_DIR"
    exit 1
fi

# Are you root (for port < 1024)?
if [ $PORT -lt 1024 -a $MYUID -ne 0 ]
then
    message "alert" "[ALERT] only root can launch OpenLDAP on port $PORT"
    exit 1
fi

#====================================================================
# Functions
#====================================================================
start_slapd() {

    # $1: debug level

    # Check if db_recover is required
    if [ $RECOVER_AT_STARTUP -eq 1 ]
    then
        db_recover
    else
        message "info" "[INFO] no db_recover done"   
    fi

    # Start message
    message "info" "[INFO] Launching OpenLDAP…"

    # File descriptor limit, only for root
    if [ $MYUID -eq 0 ]
    then
        ulimit -n $FD_LIMIT
        if [ $? -eq 0 ]
        then
            message "info" "[OK] file descriptor limit set to $FD_LIMIT"
        else
            message "warning" "[WARNING] Fail to set file descriptor limit to $FD_LIMIT, going to next step"
        fi
    else
        message "info" "[INFO] file descriptor limit not modified (require root privileges)"
    fi

    # Parameters
    if [ "$SLAPD_CONF_DIR" ]
    then
        SLAPD_PARAMS="$SLAPD_PARAMS -F $SLAPD_CONF_DIR"
    elif [ "$SLAPD_CONF" ]
    then
        SLAPD_PARAMS="$SLAPD_PARAMS -f $SLAPD_CONF"
    fi

    if [  "$SLAPD_USER" -a $MYUID -eq 0 ]
    then
        SLAPD_PARAMS="$SLAPD_PARAMS -u $SLAPD_USER"
    fi

    if [ "$SLAPD_GROUP" -a $MYGID -eq 0 ]
    then
        SLAPD_PARAMS="$SLAPD_PARAMS -g $SLAPD_GROUP"
    fi

    # It’s time to start slapd

    if [ -n "$1" ]; then
        $SLAPD_BIN -h "$SLAPD_SERVICES" $SLAPD_PARAMS -d $1
    else
        $SLAPD_BIN -h "$SLAPD_SERVICES" $SLAPD_PARAMS
        sleep 1

        # Presence of PID file
        if [ ! -r $SLAPD_PID_FILE ]
        then
            message "alert" "[ALERT] no PID file for slapd"
            exit 1
        fi

        # Is slapd launched?
        PID=`cat $SLAPD_PID_FILE`
        if [ ! -e /proc/$PID ]
        then
            message "alert" "[ALERT] slapd not running"
            exit 1
        else
            message "info" "[OK] OpenLDAP started on port $PORT and $SSLPORT"
        fi
    fi
}

#start_slurpd() {
#    # Start message
#    message "info" "[INFO] Launching OpenLDAP replication…"
#
#    if [ $SLURPD_ACTIVATE -eq 0 ]
#    then
#        message "info" "[INFO] no replica found in configuration, aborting lauching slurpd"
#        return 1
#    fi
#
#    # Parameters
#    if [ "$SLAPD_CONF_DIR" ]
#    then
#        SLAPD_PARAMS="$SLAPD_PARAMS -F $SLAPD_CONF_DIR"
#    elif [ "$SLAPD_CONF" ]
#    then
#        SLAPD_PARAMS="$SLAPD_PARAMS -f $SLAPD_CONF"
#    fi
#
#    # It’s time to start slurpd
#    if [ -z "$SU" ]
#    then
#        $SLURPD_BIN $SLURPD_PARAMS
#    else
#        $SU "$SLURPD_BIN $SLURPD_PARAMS"
#    fi
#    sleep 1
#
#    # Presence of PID file
#    if [ ! -r $SLURPD_PID_FILE ]
#    then
#        message "alert" "[ALERT] no PID file for slurpd"
#        exit 1
#    fi
#
#    # Is slurpd launched?
#    PID=`cat $SLURPD_PID_FILE`
#    if [ ! -e /proc/$PID ]
#    then
#        message "alert" "[ALERT] slurpd not running"
#        exit 1
#    else
#        message "info" "[OK] OpenLDAP replication started"
#    fi
#}

stop_slapd() {
    # Stop message
    message "info" "[INFO] Halting OpenLDAP…"

    # Presence of PID file
    if [ ! -r $SLAPD_PID_FILE ]
    then
        message "info" "[INFO] can’t read PID file, to stop slapd try: $0 forcestop"
        return 1
    else
        PID=`cat $SLAPD_PID_FILE`
        kill -INT $PID

        # Waiting loop
        i=0
        while [ -e /proc/$PID ]
        do
            if [ $i -eq $TIMEOUT ]
            then
                # Timeout
                message "alert" "[ALERT] slapd still running (PID $PID), try: $0 forcestop"
                exit 1
            fi
            i=`expr $i + 1`
            sleep 1
        done

        message "info" "[OK] OpenLDAP stopped after $i seconds"
    fi

    # Backup if necessary
    if [ $BACKUP_AT_SHUTDOWN -eq 1 ]
    then
        backup
    else
        message "info" "[INFO] no data backup done"
    fi
}

#stop_slurpd() {
#    # Stop message
#    message "info" "[INFO] Halting OpenLDAP replication…"
#
#    # Desactivate slurpd?
#    if [ $SLURPD_ACTIVATE -eq 0 ]
#    then
#        message "info" "[INFO] no replica found in configuration, aborting stopping slurpd"
#        return 1
#    fi
#
#    # Presence of PID file
#    if [ ! -r $SLURPD_PID_FILE ]
#    then
#        message "warning" "[WARNING] can’t read PID file, to stop slurpd try: $0 forcestop"
#    else
#        PID=`cat $SLURPD_PID_FILE`
#        kill -INT $PID
#
#        # Waiting loop
#        i=0
#        while [ -e /proc/$PID ]
#        do
#            if [ $i -eq $TIMEOUT ]
#            then
#                # Timeout, need to kill
#                message "alert" "[ALERT] slurpd still running (PID $PID), try: $0 forcestop"
#                return 1
#            fi
#            i=`expr $i + 1`
#            sleep 1
#        done
#
#        message "info" "[OK] OpenLDAP replication stopped after $i seconds"
#    fi
#}

forcestop() {
    # Stop message
    message "info" "[INFO] Killing OpenLDAP with force…"

    # Presence of PID file
    if [ ! -r $SLAPD_PID_FILE ]
    then
        # Escape special characters into $SLAPD_SERVICES
        slapd_services="`echo "$SLAPD_SERVICES" | sed ‘s/\*/\\\*/g’`"

        # Check if any slapd process are running
        if [ `$PS_COMMAND | grep $SLAPD_BIN | grep "$slapd_services" | grep -v grep | wc -l` -eq 0 ]
        then
            message "info" "[INFO] Found no slapd process running with $SLAPD_SERVICES"
        else
            # Try a killall
            /usr/bin/killall -KILL $SLAPD_BIN

            if [ $? -eq 0 ]
            then
                message "info" "[OK] all slapd process killed with force"
            else
                message "alert" "[ALERT] Unable to kill slapd with force"
                exit 1
            fi
        fi
    else
        PID=`cat $SLAPD_PID_FILE`
        kill -KILL $PID

        if [ $? -eq 0 ]
        then
            message "info" "[OK] slapd process killed with force (PID $PID)"
        else
            message "alert" "[ALERT] Unable to kill slapd with force (PID $PID)"
            exit 1
        fi
    fi

    # Stop message
    #message "info" "[INFO] Killing OpenLDAP replication with force…"
    #
    # Presence of PID file
    #if [ ! -r $SLURPD_PID_FILE ]
    #then
    #    # Check if any slapd process are running
    #    if [ `$PS_COMMAND | grep $SLURPD_BIN | grep -v grep | wc -l` -eq 0 ]
    #    then
    #        message "info" "[INFO] Found no slurpd process running"
    #    else
    #        # Try a killall
    #        /usr/bin/killall -KILL $SLURPD_BIN
    #
    #        if [ $? -eq 0 ]
    #        then
    #            message "info" "[OK] slurpd process killed with force"
    #        else
    #            message "alert" "[ALERT] Unable to kill slurpd with force"
    #            exit 1
    #        fi
    #    fi
    #else
    #    PID=`cat $SLURPD_PID_FILE`
    #    kill -KILL $PID
    #
    #    if [ $? -eq 0 ]
    #    then
    #        message "info" "[OK] slurpd process killed with force (PID $PID)"
    #    else
    #        message "alert" "[ALERT] Unable to kill slurpd with force (PID $PID)"
    #        exit 1
    #    fi
    #fi
}

slapd_status() {
    # Return 0 if slapd is running, 1 if slapd is stopped, 2 if we can’t say
    if [ ! -r $SLAPD_PID_FILE ]
    then
        # Escape special characters into $SLAPD_SERVICES
        slapd_services="`echo "$SLAPD_SERVICES" | sed ‘s/\*/\\\*/g’`"

        # Check if any slapd process are running
        if [ `$PS_COMMAND | grep $SLAPD_BIN | grep "$slapd_services" | grep -v grep | wc -l` -eq 0 ]
        then
            return 1
        else
            return 2
        fi
    else
        PID=`cat $SLAPD_PID_FILE`
    fi

    if [ ! -e /proc/$PID ]
    then
        return 1
    else
        return 0
    fi
}

display_status() {
    # Get status
    slapd_status

    status=$?

    if [ $status -eq 0 ]
    then
        message "info" "[INFO] Process slapd is running"
    fi

    if [ $status -eq 1 ]
    then
        message "info" "[INFO] Process slapd is not running"
    fi

    if [ $status -eq 2 ]
    then
        message "info" "[INFO] Unable to determine slapd status"
    fi

    # Get detected suffix
    get_confvalues "directory"
    dbdirs=$RETVAL
    get_confvalues "suffix"
    dbsufs=$RETVAL

    if [ ! -z "$dbdirs" -o ! -z "$dbsufs" ]
    then
        i=1
        for dbdir in $dbdirs
        do
            # Table is not allowed, so we use awk
            suf=`echo $dbsufs | awk -v j="$i" ‘BEGIN{OFS=" "} {print $j}’`
            sufprint=`echo $suf | sed "s/#20/ /"`
            if [ ! -z $suf ]
            then
                message "info" "[INFO] Detected suffix: $sufprint"
            fi
            i=`expr $i + 1`
        done
    fi
}

configtest() {
    # Start message
    message "info" "[INFO] Launching OpenLDAP configuration test…"

    SLAPTEST_PARAMS="-u"   

    if [ "$SLAPD_CONF_DIR" ]
    then
        SLAPTEST_PARAMS="$SLAPTEST_PARAMS -F $SLAPD_CONF_DIR"
    elif [ "$SLAPD_CONF" ]
    then
        SLAPTEST_PARAMS="$SLAPTEST_PARAMS -f $SLAPD_CONF"
    fi

    # slaptest
    if [ -z "$SU" ]
    then
        $SLAPTEST_BIN $SLAPTEST_PARAMS > /dev/null 2>&1
    else
        $SU "$SLAPTEST_BIN $SLAPTEST_PARAMS > /dev/null 2>&1"
    fi

    if [ $? -eq 0 ]
    then
        message "info" "[OK] OpenLDAP configuration test successful"
    else
        message "alert" "[ALERT] OpenLDAP configuration test failed"
        exit 1
    fi
}

db_recover() {
    # Start message
    message "info" "[INFO] Launching OpenLDAP database recovery…"

    if [ ! -x $DB_RECOVER_BIN ]
    then
        message "alert" "[ALERT] Cannot execute $DB_RECOVER_BIN, aborting database recovery"
        exit 1
    fi

    # slapd must be stopped
    slapd_status

    if [ $? -ne 1 ]
    then
        message "alert" "[ALERT] slapd is running or was not correctly shut down, aborting database recovery"
        exit 1
    fi

    # Do backup for all databases,
    # except if DATA_PATH is ‘auto’

    dbdirs="$DATA_PATH"

    if [ "$DATA_PATH" = "auto" ]
    then
        get_confvalues "directory"
        dbdirs=$RETVAL

        if [ -z "$dbdirs" ]
        then
            message "alert" "[ALERT] No database directories found"
            exit 1
        fi
    fi

    for dbdir in $dbdirs
    do

        # db_recover
        if [ -z "$SU" ]
        then
            $DB_RECOVER_BIN -h "$dbdir"
        else
            $SU "$DB_RECOVER_BIN -h \"$dbdir\""
        fi

        if [ $? -eq 0 ]
        then
            message "info" "[OK] OpenLDAP $dbdir database recovery successful"
        else
            message "alert" "[ALERT] OpenLDAP $dbdir database recovery failed"
            exit 1
        fi

    done
}

reindex() {
    # Start message
    message "info" "[INFO] Launching OpenLDAP database reindexing…"

    if [ "$SLAPD_CONF_DIR" ]
    then
        SLAPINDEX_PARAMS="-F $SLAPD_CONF_DIR"
    elif [ "$SLAPD_CONF" ]
    then
        SLAPINDEX_PARAMS="-f $SLAPD_CONF"
    fi

    # slapd must be stopped
    slapd_status

    if [ $? -ne 1 ]
    then
        message "alert" "[ALERT] slapd is running or was not correctly shut down, aborting reindexing"
        exit 1
    else
        # slapindex
        if [ -z "$SU" ]
        then
            $SLAPINDEX_BIN $SLAPINDEX_PARAMS
        else
            $SU "$SLAPINDEX_BIN $SLAPINDEX_PARAMS"
        fi

        if [ $? -eq 0 ]
        then
            message "info" "[OK] OpenLDAP database reindexing successful"
        else
            message "alert" "[ALERT] OpenLDAP database reindexing failed"
            exit 1
        fi
    fi
}

removelogs() {
    # Start message
    message "info" "[INFO] Launching OpenLDAP database logs archiving…"

    if [ ! -x $DB_ARCHIVE_BIN ]
    then
        message "alert" "[ALERT] Cannot execute $DB_ARCHIVE_BIN, aborting database archiving"
        exit 1
    fi

    # slapd must be stopped
    slapd_status

    if [ $? -ne 1 ]
    then
        message "alert" "[ALERT] slapd is running or was not correctly shut down, aborting archiving"
        exit 1
    fi

    # Do backup for all databases,
    # except if DATA_PATH is ‘auto’

    dbdirs="$DATA_PATH"

    if [ "$DATA_PATH" = "auto" ]
    then
        get_confvalues "directory"
        dbdirs=$RETVAL

        if [ -z "$dbdirs" ]
        then
            message "alert" "[ALERT] No database directories found"
            exit 1
        fi
    fi

    for dbdir in $dbdirs
    do

        # db_archive
        if [ -z "$SU" ]
        then
            $DB_ARCHIVE_BIN -h "$dbdir" -d
        else
            $SU "$DB_ARCHIVE_BIN -h \"$dbdir\" -d"
        fi

        if [ $? -eq 0 ]
        then
            message "info" "[OK] OpenLDAP $dbdir database logs archiving successful"
        else
            message "alert" "[ALERT] OpenLDAP $dbdir database logs archiving failed"
            exit 1
        fi

    done
}

backup() {
    # Start message
    message "info" "[INFO] Launching OpenLDAP database backup…"

    # Backup directory
    mkdir -p "$BACKUP_PATH"

    if [ "$SLAPD_CONF_DIR" ]
    then
        SLAPCAT_PARAMS="-F $SLAPD_CONF_DIR"
    elif [ "$SLAPD_CONF" ]
    then
        SLAPCAT_PARAMS="-f $SLAPD_CONF"
    fi

    # Do backup for all databases,
    # except if DATA_PATH is ‘auto’

    dbdirs="$DATA_PATH"
    dbsufs=""

    if [ "$DATA_PATH" = "auto" ]
    then
        get_confvalues "directory"
        dbdirs=$RETVAL
        get_confvalues "suffix"
        dbsufs=$RETVAL

        if [ -z "$dbdirs" -o -z "$dbsufs" ]
        then
            message "alert" "[ALERT] No database directories found"
            exit 1
        fi
    fi

    i=1
    for dbdir in $dbdirs
    do
        # Table is not allowed, so we use awk
        suf=`echo $dbsufs | awk -v j="$i" ‘BEGIN{OFS=" "} {print $j}’`

        if [ -z $suf ]; then
            message "info" "No suffix for $dbdir"
        else
            sufprint=`echo $suf | sed "s/#20/ /"`
            dir=`basename $dbdir`
            file="$BACKUP_PATH/$dir-$BACKUP_SUFFIX"

            # slapcat
            if [ -z "$SU" ]
            then
                $SLAPCAT_BIN -b "$sufprint" $SLAPCAT_PARAMS -l "$file"
            else
                $SU "$SLAPCAT_BIN -b \"$sufprint\" $SLAPCAT_PARAMS" > "$file"
            fi

            # alert
            if [ $? -ne 0 ]
            then
                message "alert" "[ALERT] OpenLDAP database backup failed"
                exit 1
            fi

            # compress
            if [ -z $BACKUP_COMPRESS_EXT ]
            then
                message "info" "[OK] data saved in $file"
            else
                if [ -z "$SU" ]
                then
                    $BACKUP_COMPRESS_BIN "$file"
                else
                    $SU "$BACKUP_COMPRESS_BIN $file"
                fi

                # alert
                if [ $? -ne 0 ]
                then
                    message "alert" "[ALERT] OpenLDAP database backup compression failed"
                    exit 1
                fi
                message "info" "[OK] data saved in ${file}.$BACKUP_COMPRESS_EXT"
            fi
        fi

        i=`expr $i + 1`
    done

}

#====================================================================
# Action switch
#====================================================================
case $1 in
    start)
    configtest
#    start_slurpd
    start_slapd
    ;;
    stop)
    stop_slapd
#    stop_slurpd
    ;;
    forcestop)
    forcestop
    ;;
    restart)
    stop_slapd
#    stop_slurpd
    configtest
#    start_slurpd
    start_slapd
    ;;
    debug)
    stop_slapd
#    stop_slurpd
#    start_slurpd
    start_slapd $DEBUG_LEVEL
    ;;
    force-reload)
    forcestop
    configtest
#    start_slurpd
    start_slapd
    ;;
    status)
    display_status
    ;;
    configtest)
    configtest
    ;;
    db_recover)
    db_recover
    ;;
    reindex)
    reindex
    ;;
    removelogs)
    removelogs
    ;;
    backup)
    backup
    ;;
    *)
    echo "Usage: $0 {start|stop|forcestop|restart|debug|force-reload|status|configtest|db_recover|reindex|removelogs|backup}"
    exit 1
    ;;
esac

#====================================================================
# Exit
#====================================================================
exit 0

February 13, 2011

Dynamic DNS and DHCP on CentOS 5.x (Master and Slave failover)

Filed under: CentOS — Tags: — NyU @ 5:41 pm

Distro: CentOS 5.5 64bit 
Domain: systeminteg.com

Master:
IP:
192.168.1.1/24
Hostname: pdc-srv.systeminteg.com

Slave:
IP:
192.168.1.2/24
Hostname: bdc-srv.systeminteg.com

Installation packages:

yum install bind bind-chroot bind-libs bind-utils caching-nameserver dhcp ntp –y

Generate an key for rndc.key:

cd /var/named/chroot/etc
rndc-confgen > rndc.key
chown root:named rndc.key

Configuration:

  1. DHCP
    Master configuration:
    First backup dhcpd.conf

    cp /etc/dhcpd.conf /etc/dhcpd.conf.ori

    Edit /etc/dhcpd.conf as:

    #
    # DHCP Server Configuration file.
    # see /usr/share/doc/dhcp*/dhcpd.conf.sample
    #
    authoritative;
    option domain-name "systeminteg.com";
    option domain-name-servers 192.168.1.1,192.168.1.2;
    option netbios-name-servers 192.168.1.1;
    allow booting;
    allow bootp;
    next-server 192.168.1.1;
    filename "pxelinux.0";
    ddns-update-style interim;
    ddns-updates on;
    ddns-domainname "systeminteg.com;
    failover peer "systeminteg.com" {
       primary;
       address 192.168.1.1;
       port 647;
       peer address 192.168.1.2;
       peer port 647;
       max-response-delay 60;
       max-unacked-updates 10;
       mclt 3600;
       split 128;
       load balance max seconds 3;
    }
    include “/etc/dhcpd.global”;


    Slave configuration:
    Backup dhcpd.conf

    cp /etc/dhcpd.conf /etc/dhcpd.conf.ori

    Edit /etc/dhcpd.conf as:

    #
    # DHCP Server Configuration file.
    # see /usr/share/doc/dhcp*/dhcpd.conf.sample
    #
    authoritative;
    option domain-name "systeminteg.com";
    option domain-name-servers 192.168.1.1,192.168.1.2;
    option netbios-name-servers 192.168.1.1;
    allow booting;
    allow bootp;
    next-server 192.168.1.1;
    filename "pxelinux.0";
    ddns-update-style interim;
    ddns-updates on;
    ddns-domainname "systeminteg.com";
    failover peer "systeminteg.com" {
       secondary;
       address 192.168.1.2;
       port 647;
       peer address 192.168.1.1;
       peer port 647;
       max-response-delay 60;
       max-unacked-updates 10;
       mclt 3600;
       load balance max seconds 3;
    }
    include “/etc/dhcpd.global”;

    Master and Slave configuration
    Edit /etc/dhcpd.global

    include "/etc/rndc.key";
    zone systeminteg.com{ 
       primary 127.0.0.1;
       key rndckey;
    }
    zone 1.168.192.in-addr.arpa {
       primary 127.0.0.1;
       key rndckey;
    }
    subnet 192.168.1.0 netmask 255.255.255.0 {
       pool {
          failover peer "systeminteg.com";
          deny dynamic bootp clients;
          option routers 192.168.1.254;
          range 192.168.1.25 192.168.1.50;
       }
       pool {
          option routers 192.168.1.254;
          range 192.168.1.51 192.168.1.55;
       }
       allow unknown-clients; 
       ignore client-updates;
    }

  2. DNS:
    Master configuration:
    Edit /var/named/chroot/etc/named.conf

    # Start of rndc.conf
    include “/etc/rndc.key”;
    controls {
       inet 127.0.0.1 allow { 127.0.0.1; } keys { "rndckey"; };
       inet 192.168.1.1 allow { 192.168.1.0/24; } keys { "rndckey"; };
    };
    options {
       directory "/var/named";
       pid-file "/var/run/named/named.pid";
       recursion yes;
       allow-recursion {
          127.0.0.1;
          192.168.1.0/24;
       };
       forwarders {
          208.67.222.222;
          208.67.220.220;
       };
       listen-on {
          127.0.0.1;
          192.168.1.1;
          192.168.1.2;
       };
       query-source address * port 53;
       version "REFUSED";
       allow-query {
          127.0.0.1;
          192.168.1.0/24;
       };
    };
    server 192.168.1.1 {
       keys { rndckey; };
    };
    zone "." IN {
       type hint;
       file "named.ca";
    };
    zone "systeminteg.com" IN {
       type master;
       file "data/systeminteg.com.zone";
       allow-transfer { 192.168.1.2; };
       allow-update { key "rndckey"; };
       allow-query { any; };
    };
    zone "1.168.192.in-addr.arpa" IN {
       type master;
       file "data/1.168.192.zone";
       allow-transfer { 192.168.1.2; };
       allow-update { key "rndckey"; };
       allow-query { any;} ;
    };

    chown root:named /var/named/chroot/etc/named.conf

    Slave configuration:
    Edit /var/named/chroot/etc/named.conf

    # Start of rndc.conf
    include “/etc/rndc.key”;
    controls { 
       inet 127.0.0.1 allow { 127.0.0.1; } keys { "rndckey"; }; 
       inet 192.168.1.1 allow { 192.168.1.0/24; } keys { "rndckey"; };
    };
    options { 
       directory "/var/named"; 
       pid-file "/var/run/named/named.pid"; 
       recursion yes; 
       allow-recursion {
          127.0.0.1; 
          192.168.1.0/24; 
       }; 
       forwarders { 
          208.67.222.222; 
          208.67.220.220; 
       }; 
       listen-on { 
          127.0.0.1; 
          192.168.1.1; 
          192.168.1.2; 
       }; 
       query-source address * port 53; 
       version "REFUSED"; 
       allow-query { 
          127.0.0.1; 
          192.168.1.0/24; 
       };
    };
    server 192.168.1.2 { 
       keys { rndckey; };
    };
    zone "." IN { 
       type hint; 
       file "named.ca";
    };
    zone "systeminteg.com" IN { 
       type slave; 
       file "data/systeminteg.com.zone"; 
       masters { 192.168.1.1;};
    };
    zone "1.168.192.in-addr.arpa" IN { 
       type slave; 
       file "data/1.168.192.zone"; 
       masters {192.168.1.1;}; 
    };

    Create zone  files on Master

    Create zone files
    Create /var/named/chroot/var/named/data/systeminteg.com.zone

    $TTL 38400
    @                    IN               SOA        pdc-srv.systeminteg.com. admin.systeminteg.com. (
                                                           20110201        ; serial
                                                           10800             ; refresh (3 hours)
                                                           3600               ; retry (1 hour)
                                                           604800           ; expire (1 week)
                                                           86400             ; minimum (1 day)
    )
                            NS                           pdc-srv.systeminteg.com.
    pdc-srv              A                            192.168.1.1
    bdc-srv              A                            192.168.1.2
    dns1                  A                            192.168.1.1
    dns2                  A                            192.168.1.2
    ns1                    A                            192.168.1.1
    ns2                    A                            192.168.1.2

    Create /var/named/chroot/var/named/data/1.168.192.zone

    $TTL 38400
    @                    IN               SOA        pdc-srv.systeminteg.com. admin.systeminteg.com. (
                                                           20110201        ; serial
                                                           10800             ; refresh (3 hours)
                                                           3600               ; retry (1 hour)
                                                           604800           ; expire (1 week)
                                                           86400             ; minimum (1 day)
    )
                            NS                           pdc-srv.systeminteg.com.
    1                      PTR                         pdc-srv.systeminteg.com.
    2                      PTR                         bdc-srv.systeminteg.com.

    chown named:named /var/named/chroot/var/named/data/*

  3. NTP
    Create /etc/cron.hourly/timesync.sh
  4. #!/bin/bash
    ntpdate –s 0.rhel.pool.ntp.org

    chmod +x /etc/cron.houtly/timesync.sh
    /etc/cron.hourly/timesync.sh

 

Dynamic DNS and DHCP on CentOS 5.x (Stand alone)

Filed under: CentOS — Tags: — NyU @ 7:37 am

Distro: CentOS 5.5 64bit
Domain:
systeminteg.com
Hostname: pdc-srv.systeminteg.com
IP Address: 192.168.1.1/24

Installation packages:

yum install bind bind-chroot bind-libs bind-utils caching-nameserver dhcpd ntp –y

Generate a key for rndc.key

cd /var/named/chroot/etc
rndc-confgen > rndc.key
chown root:named rndc.key

Configuration:

  1. DHCP:
    First backup the curent config file

    cp /etc/dhcpd.conf /etc/dhcpd.conf.ori

    Edit /etc/dhcpd.conf as:

    authoritative;
    option domain-name "systeminteg.com";
    option domain-name-servers 192.168.1.1;
    option netbios-name-servers 192.168.1.1;
    # Allow booting and booting from network
    allow booting;
    allow bootp;
    #Below is TFTP server and kernel for network booting Ex: File server etc…
    next-server 192.168.1.5;
    filename "pxelinux.0";
    ddns-update-style interim;
    ddns-updates on;
    ddns-domainname "systeminteg.com";
    include "/etc/dhcpd.global";


    Edit /etc/dhcpd.global as:

    include "/etc/rndc.key";
    zone systeminteg.com {
       primary 127.0.0.1;
       key rndckey;
    }
    zone 1.168.192.in-addr.arpa {
       primary 127.0.0.1;
       key rndckey;
    }
    subnet 192.168.1.0 netmask 255.255.255.0 {
       pool {
          deny dynamic bootp clients;
          option routers 192.168.1.254;
          range 192.168.1.25 192.168.1.50;
       }
      p
    ool {
          option routers 192.168.1.254;
          range 192.168.1.51 192.168.1.55;
       }
       allow unknown-clients;
       ignore client-updates;
    }

    Example /etc/rndc.key file

    # Start of rndc.conf
    key "rndckey" {
       algorithm hmac-md5;
       secret "v03a9FPqIihkB/Hdg5ke1Q==";
    };
    #options {
    # default-key "rndckey";
    # default-server 127.0.0.1;
    # default-port 953;
    #};
    # End of rndc.conf

  2. DNS:
    Edit /var/named/chroot/etc/named.conf
  3. include "/etc/rndc.key";
    controls {
       inet 127.0.0.1 allow { 127.0.0.1; } keys { "rndckey"; };
       inet 192.168.100.1 allow { 192.168.1.0/24; } keys { "rndckey"; };
    };
    options {
       directory "/var/named";
       pid-file "/var/run/named/named.pid";
       recursion yes;
       allow-recursion {
          127.0.0.1;
          192.168.1.0/24;
       };
       forwarders {
          208.67.222.222;
          208.67.220.220;
       };
       listen-on {
          127.0.0.1;
          192.168.1.1;
       };
       query-source address * port 53;
       version "REFUSED";
       allow-query {
          127.0.0.1;
          192.168.1.0/24;
       };
    };
    server 192.168.1.1 {
       keys { rndckey; };
    };
    zone "." IN {
       type hint;
       file "named.ca";
    };
    zone "systeminteg.com" IN {
       type master;
       file "data/systeminteg.com.zone";
       allow-update { key "rndckey"; };
       allow-query { any; };
    };
    zone "1.168.192.in-addr.arpa" IN {
       type master;
       file "data/1.168.192.zone";
       allow-update { key "rndckey"; };
       allow-query { any;} ;
    };

    chown root:named /var/named/chroot/etc/named.conf

    Create zone files
    Create /var/named/chroot/var/named/data/systeminteg.com.zone

    $TTL 38400
    @                    IN               SOA        pdc-srv.systeminteg.com. admin.systeminteg.com. (
                                                           20110201        ; serial
                                                           10800             ; refresh (3 hours)
                                                           3600               ; retry (1 hour)
                                                           604800           ; expire (1 week)
                                                           86400             ; minimum (1 day)
    )
                            NS                           pdc-srv.systeminteg.com.
    pdc-srv              A                            192.168.1.1
    dns                   A                            192.168.1.1
    ns                     A                            192.168.1.1

    Create /var/named/chroot/var/named/data/1.168.192.zone

    $TTL 38400
    @                    IN               SOA        pdc-srv.systeminteg.com. admin.systeminteg.com. (
                                                           20110201        ; serial
                                                           10800             ; refresh (3 hours)
                                                           3600               ; retry (1 hour)
                                                           604800           ; expire (1 week)
                                                           86400             ; minimum (1 day)
    )
                            NS                           pdc-srv.systeminteg.com.
    1                      PTR                         pdc-srv.systeminteg.com.

    chown named:named /var/named/chroot/var/named/data/*

  4. NTP:
    Create /etc/cron.hourly/timesync.sh

    #!/bin/bash
    ntpdate –s 0.rhel.pool.ntp.org

    chmod +x /etc/cron.houtly/timesync.sh
    /etc/cron.hourly/timesync.sh

February 11, 2011

How to install and configure Apt-Cacher NG on Ubuntu Server 10.04

Filed under: Ubuntu — Tags: — NyU @ 4:06 pm
Technorati Tags: ,,

Description: Apt-Cacher NG  Apt-Cacher NG is a caching proxy for software packages which are downloaded by Unix/Linux system distribution mechanisms from mirror servers accessible via HTTP. If you have many Debian/Ubuntu machines on your network, you just have to download the deb packages (new software, updates, distro upgrades, etc) from the internet once and the rest of the Debian/Ubuntu machines get them from Apt-Cacher NG cache, saving time and internet bandwidth. Follow these steps:

Steps:

  1. Installation: apt-get install apt-cacher-ng

  2. Restart Apt-Cacher-NG: /etc/init.d/apt-cacher-ng restart

  3. There are two ways use apt-cacher-ng

    • Specify the caching machine as HTTP Proxy for APT, E.g. Putting a line like the following into a file like /etc/apt/apt.conf.d/02proxy

Acquire::http { proxy “http://your-apt-cacher-ng-server:3142”; };

    • Edit sources.list and replace

###### Ubuntu Main Repos
deb http://vn.archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb-src http://vn.archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse

      • Now become

###### Ubuntu Main Repos
deb http://your-apt-cacher-ng-server:3142/ubuntu/ maverick main restricted universe multiverse
deb-src http://your-apt-cacher-ng-server:3142/ubuntu/ maverick main restricted universe multiverse

Trick: Use this command to : just change "server" to the name/ip of your machine

sudo perl -i.bak -pe ‘s/http:\/\//http:\/\/server:3142\//g’ /etc/apt/sources.list

Ref: http://www.unix-ag.uni-kl.de/~bloch/acng/html/index.html

Blog at WordPress.com.