Client Installation: Unterschied zwischen den Versionen

Aus Vosp.freesn.de
Zur Navigation springen Zur Suche springen
HK (Diskussion | Beiträge)
HK (Diskussion | Beiträge)
 
(23 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
== MACs der Client-PCs finden ==
Zurück zu [[OPSI]]
===== PXE-Boot =====
= 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.<br>
In diesem HowTo wird TinyCore eingesetzt.<br>
Der große Vorteil liegt im per default eingesetzten dhcp-Clienten, der ein gebootetes TinyCore automatisch mit einer IP versorgt.<br>
Der große Vorteil liegt im per default eingesetzten dhcp-Clienten, der ein gebootetes TinyCore automatisch mit einer IP versorgt.<br>


  apt-get install syslinux nmap
== Auf CentOS ==
=== Notwendige Pakete ===
  yum install -y syslinux-tftpboot nmap


Folgende Verzeichnisse erstellen
=== Struktur erstellen ===
mkdir -p /tftpboot/detect/tinycore-hd
mkdir /tftpboot/detect/pxelinux.cfg


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


cp /usr/lib/syslinux/memdisk /tftpboot/lookmac/
=== tinycore ===
cp /usr/lib/syslinux/pxelinux.0 /tftpboot/lookmac/
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


Im Verzeichniss /tftpboot/lookmac/pxelinux.cfg die Datei ''default'' erstellen.
* Links:
** http://wiki.tinycorelinux.net/wiki:remastering
* Pfade können sich ändern (08.04.2015)
* openssh besteht aus:
gcc_libs.tcz
openssl-1.0.0.tcz
openssh.tcz


  vim /tftpboot/lookmac/pxelinux.cfg/default
==== Auf dem Server ====
  yum install -y squashfs-tools


Inhalt
  mkdir ~/bin/remastertiny
default core
  cd ~/bin/remastertiny
  label core
  wget http://tinycorelinux.net/5.x/x86/release/Core-current.iso -O ~/bin/remastertiny/core.iso
  kernel tinycore/boot/vmlinuz
mount -o loop  core.iso /mnt
  append initrd=tinycore/boot/core.gz
cp -a /mnt/* /tftpboot/detect/tinycore-hd
 
cp /tftpboot/detect/tinycore-hd/boot/core.gz .
Ein TinyCore Iso downloaden.
  wget http://tinycorelinux.net/5.x/x86/release/Core-current.iso -O /tftpboot/lookmac/core.iso


===== ISO bearbeiten =====
chmod 644 core.gz
Der Timeout des Startmenues liegt bei 300 Sekunden, der soll auf 3 Sekunden verkürzt werden.<br>


Mit Tools wie z.B. ''isomaster'' lässt sich ein ISO einfach bearbeiten.
wget http://tinycorelinux.net/5.x/x86/tcz/gcc_libs.tcz
Im Verzeichniss ''/boot/isolinux/'' liegt die Datei ''isolinux.cfg''<br>
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/


''timeout 300'' ändern in ''timeout 3'' oder weniger.<br>
==== Auf dem Clienten ====
''timeout 0'' ist nicht empfehlenswert, immerhin steht uns jetzt ein TinyCore mit allen Möglichkeiten zur Verfügung.<br>
Das sollten wir uns erhalten.


Das ISO mounten
Einen Clienten mit dem neuen core.gz starten
mount -o loop  core.iso /tftpboot/lookmac/tinycore


===== /etc/dhcp/dhcp.conf anpassen =====
sudo su
In der /etc/dhcp/dhcp.conf folgendes Änderung durchführen.
passd
#      range 10.8.190.15 10.8.190.30;
Billiges Passwort vergeben
      range 10.8.190.15 10.8.190.254;
/usr/local/etc/init.d/openssh start
       
Es werden die sshd-keys generiert.
#        filename "linux/pxelinux.0";
        filename "lookmac/pxelinux.0";


===== MACs finden =====
==== 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/ .


  nmap -sP 10.8.190.0/24 -n|grep MAC|awk '{print $3}'
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


Das Ergebniss des Scans wird in /etc/dhcp/dhcp.conf eingetragen.<br>
cd ~/bin/remastertiny/tmp


Der folgende Befehl ersetzt NUR den ERSTEN Treffer des Suchstings.
  echo "/usr/local/etc/init.d/openssh start" >> ~/bin/remastertiny/tmp/etc/init.d/rcS
  sed -i '0,/00:00:00:00:00:00/s//00:1f:16:0d:7d:26/' /etc/dhcp/dhcp.conf


===== /etc/dhcp/dhcp.conf zurück setzen =====
find | cpio -o -H newc | gzip -2 > ../core.gz
In der /etc/dhcp/dhcp.conf folgendes Änderung durchführen.
  cp ../core.gz /tftpboot/detect/tinycore-hd/boot/
        range 10.8.190.15 10.8.190.30;
  #      range 10.8.190.15 10.8.190.254;
       
        filename "linux/pxelinux.0";
#        filename "lookmac/pxelinux.0";


== Auf CentOS ==
Fertig
* Ziel: Erkennen und Einbinden neuer Clients
=== 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 ===
wget http://tinycorelinux.net/5.x/x86/release/Core-current.iso -O /tftpboot/detect/core.iso
mount -o loop  core.iso /mnt
cp -a /mnt/* /tftpboot/detect/tinycore-hd


=== /tftpboot/detect/pxelinux.cfg/default ===
=== /tftpboot/detect/pxelinux.cfg/default ===
Zeile 95: Zeile 106:
* Einfügen
* Einfügen


* Global
# Global
  # filename detect
  # filename detect
  # filename "detect/pxelinux.0";
  # filename "detect/pxelinux.0";
* subnet definition
# in der subnet definition
  #range detect
  #range detect
  #        range <sehr großer range>;
  #        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 ==
* http://www.unix.com/shell-programming-and-scripting/36005-regular-expression-mac-address-validation.html
* http://stackoverflow.com/questions/148451/how-to-use-sed-to-replace-only-the-first-occurrence-in-a-file
* http://linuxcommando.blogspot.de/2008/10/how-to-disable-ssh-host-key-checking.html
*

Aktuelle Version vom 9. April 2015, 15:10 Uhr

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'