Client Installation

Aus Vosp.info
Wechseln zu:Navigation, Suche

Zurück zu OPSI

MACs der Client-PCs finden

  • Ziel: Erkennen und Einbinden neuer Clients.
    • Automatisiert wird:
      • /etc/dhcp/dhcpd.conf schreiben
      • OPSI-Client hinzufügen
      • OPSI-Client mit Software versorgen

In diesem HowTo wird TinyCore eingesetzt.
Der große Vorteil liegt im per default eingesetzten dhcp-Clienten, der ein gebootetes TinyCore automatisch mit einer IP versorgt.

Auf CentOS

Notwendige Pakete

yum install -y syslinux-tftpboot nmap

Struktur erstellen

mkdir -p /tftpboot/detect/tinycore-hd
mkdir /tftpboot/detect/pxelinux.cfg
cp -v /usr/share/syslinux/pxelinux.0 .
cp -v /usr/share/syslinux/memdisk .

tinycore

Ziel: tinycore soll sich per ssh steuern lassen.

tinycore remastern

  • Das remastern kann auch auf einem anderen Rechner stattfinden.
  • Das core.gz muss auf einem Clienten startbar sein
gcc_libs.tcz
openssl-1.0.0.tcz
openssh.tcz

Auf dem Server

yum install -y squashfs-tools
mkdir ~/bin/remastertiny
cd ~/bin/remastertiny
wget http://tinycorelinux.net/5.x/x86/release/Core-current.iso -O ~/bin/remastertiny/core.iso
mount -o loop  core.iso /mnt
cp -a /mnt/* /tftpboot/detect/tinycore-hd
cp /tftpboot/detect/tinycore-hd/boot/core.gz .
chmod 644 core.gz
wget http://tinycorelinux.net/5.x/x86/tcz/gcc_libs.tcz
wget http://tinycorelinux.net/5.x/x86/tcz/openssl-1.0.0.tcz
wget http://tinycorelinux.net/5.x/x86/tcz/openssh.tcz
mkdir tmp
cd tmp
zcat ../core.gz | cpio -i -H newc -d
cd ..
unsquashfs -f gcc_libs.tcz
unsquashfs -f openssl-1.0.0.tcz
unsquashfs -f openssh.tcz
cp -a squashfs-root/usr/ ../tmp
cd ../tmp/usr/local/etc/ssh/
cp sshd_config.example sshd_config
cd ~/bin/remastertiny/tmp
find | cpio -o -H newc | gzip -2 > ../core.gz
cp ../core.gz /tftpboot/detect/tinycore-hd/boot/

Auf dem Clienten

Einen Clienten mit dem neuen core.gz starten

sudo su
passd

Billiges Passwort vergeben

/usr/local/etc/init.d/openssh start

Es werden die sshd-keys generiert.

Auf dem Server

Das ganze ssh-Verzeichniss vom Clienten kopieren

cd ~/bin/remastertiny/tmp/usr/local/etc
scp -r root@<Client-IP>:/usr/local/etc/ssh/ .

Das Homeverzeichniss des users tc kopieren

scp -r root@<Client-IP>:/home/tc /home
cat ~/.ssh/id_rsa.pub > ~/bin/remastertiny/tmp/home/tc/.ssh/authorized_keys
chown 1001:50 -R /~/bin/remastertiny/tmp/home/tc
cd ~/bin/remastertiny/tmp
echo "/usr/local/etc/init.d/openssh start" >> ~/bin/remastertiny/tmp/etc/init.d/rcS
find | cpio -o -H newc | gzip -2 > ../core.gz
cp ../core.gz /tftpboot/detect/tinycore-hd/boot/

Fertig

/tftpboot/detect/pxelinux.cfg/default

vim /tftpboot/detect/pxelinux.cfg/default
default core
label core
 kernel tinycore-hd/boot/vmlinuz
 append  initrd=tinycore-hd/boot/core.gz

/etc/dhcp/dhcpd.conf

vim /etc/dhcp/dhcpd.conf
  • Einfügen
# Global
# filename detect
# filename "detect/pxelinux.0";

# in der subnet definition
#range detect
#        range <Network>.30 <Network>.200;

Für den detect mode den range und filename in der dhcpd.conf umschalten.

systemctl restart dhcpd.service

Scripte

delete-host <HOSTNAME>

#!/bin/bash 
__HOST=$1
__FQDN=$__HOST.$(hostname -d)
__DHCPD_CONFIG=/etc/dhcp/dhcpd.conf

echo "Deleting $__FQDN from OPSI and dhcpd.conf"

opsi-admin -d method deleteClient $__FQDN

sed -i "s#$(grep $__FQDN $__DHCPD_CONFIG)#$(grep $__FQDN $__DHCPD_CONFIG |  sed  "s#\([0-9A-Z][0-9A-Z]:\)\{5\}[0-9A-Z][0-9A-Z]#00:00:00:00:00:00#")#"   $__DHCPD_CONFIG 

detect-setup

#!/bin/bash
  
# __PKGS sourcen aus ~/bin/PKGS.conf
# Example: __PKGS="win7 cool-software uncool-software"

if [ -f ~/bin/PKGS.conf ]
       then
               . ~/bin/PKGS.conf
       else
               echo "Pakage config ist missing"
               exit
       fi

__NETWORK=<NETWORK>/24
__DHCPD_CONF=/etc/dhcp/dhcpd.conf
__MAC=""
__HOSTNAME=""
__DOMAIN=$(hostname -d)


if [ -d new_clients ]
       then
               echo "new_clients exists"
               exit
       else
               mkdir new_clients
       fi

cp -a $__DHCPD_CONF $__DHCPD_CONF-$(date +%Y-%m-%d_%H-%M)
 
for __MAC in $(nmap -n -sP $__NETWORK |grep MAC|awk '{print $3}')
       do
               # Setup dhcpd.conf
               echo $__MAC 
               sed -i "0,/00:00:00:00:00:00/s//$__MAC/" $__DHCPD_CONF
               # grep new Hostname
               __HOSTNAME=$(grep $__MAC $__DHCPD_CONF |grep -oE win[0-9]*[0-9][0-9].$__DOMAIN|cut -d. -f1)
               echo $__HOSTNAME
               touch new_clients/$__HOSTNAME
               # Create new OPSI-Client
               __FQDN=$__HOSTNAME.$__DOMAIN
               opsi-admin -d method createClient "${$__HOSTNAME}" "${$__DOMAIN}"
               opsi-admin -d method setMacAddress "${$__FQDN}" "${$__MAC}"
               # Setup software for new Client
               for __PKG in $__PKGS
                       do
                               opsi-admin -d method setProductActionRequest $__PKG "${__FQDN}" setup
                       done
       done

echo "/etc/dhcp/dhcpd.conf mit "vimd" anpassen und "systemctl restart dhcpd.service""
echo "Clienten mit "ssh-reboot" neustarten
exit 0

ssh-reboot

Der ssh-key muss zum core.gz eingetragene pub-key passen.

#!/bin/bash

__NET="<Network ohne 0> "

__IP_START="30"
__IP_END="200"

while [ "$__IP_START" -le "$__IP_END" ]
       do
               ssh -i ~/.ssh/id_tiny_rsa  tc@$__NET.$__IP_START sudo reboot 2> /dev/null &
               __IP_START=$(( $__IP_START + 1 ))
       done

echo "Reboot of clients is done"
exit 0

aliase in der .bashrc

vim ~/.bashrc
alias catd='cat /etc/dhcp/dhcpd.conf'
alias catf='cat /etc/named/<domain>.local.zone'
alias catr='cat /etc/named/<netmask>.in-addr.arpa.zone'
alias cath='echo catd catf catr'

alias vimd='vim /etc/dhcp/dhcpd.conf'

Links