无人值守安装系统及lamp和storage架构的搭建【Linux运维之道之脚本案例】

主要思路为在default中设置menu.c32中为两个,lampstorage。其中让它们分别指向不同的ks.cfg文件,ks.cfg1ks.cfg2。其中ks.cfg1后边添加上执行lamp架构的脚本命令,ks.cfg2后边添加上执行storage架构的脚本命令。在新安装的服务器上就选择lampstorage就能完成想要的服务器架构。具体步骤如下:


、批量部署

1./home/test下新建文件default  ks.cfg1 ks.cfg2  tftp  dhcp.conf 1


dhcpd.conf 文件内容为


ddns-update-style interim;

ignore client-updates;


option domain-name-servers 192.168.18.101;


default-lease-time 600;

max-lease-time 7200;



subnet 192.168.18.0 netmask 255.255.255.0 {

range 192.168.18.100 192.168.18.200;

option routers 192.168.18.1;

filename "pxelinux.0";

next-server 192.168.18.101;

}


tftp 文件内容为


# default: off

# description: The tftp server serves filesusing the trivial file transfer \

#      protocol.  The tftp protocol isoften used to boot diskless \

#      workstations, download configuration files to network-aware printers, \

#      and to start the installation process for some operating systems.

service tftp

{

      socket_type             = dgram

      protocol                = udp

      wait                    = yes

      user                    = root

      server                  =/usr/sbin/in.tftpd

      server_args             = -s/tftpboot

      disable                 = no

      per_source              = 11

      cps                     = 100 2

      flags                   = IPv4

}



ks.cfg1 文档内容为


#platform=x86, AMD64, Intel EM64T

# System authorization information

auth --useshadow  --enablemd5

# System bootloader configuration

bootloader --append="rhgb quiet"--location=mbr --driveorder=sda

# Partition clearing information

clearpart --all --initlabel

# Use graphical install

graphical

# Firewall configuration

firewall --disabled

# Run the Setup Agent on first boot

firstboot --disable

# System keyboard

key --skip

keyboard us

# System language

lang zh_CN

# Installation logging level

logging --level=info

# Use network installation

url --url=ftp://192.168.18.101/pub

# Network information

network --bootproto=dhcp --device=eth0--onboot=on

# Reboot after installation

reboot

#Root password

rootpw --iscrypted$1$ULKGMluB$h0wf90w2mrp43giBywbkT.


# SELinux configuration

selinux --disabled

# System timezone

timezone --isUtc Asia/Shanghai

# Install OS instead of upgrade

install

# X Window System configuration information

xconfig --defaultdesktop=GNOME --depth=8 --resolution=1024x768 --startxonboot

# Disk partitioning information

part /boot --bytes-per-inode=4096--fstype="ext3" --size=100

part swap --bytes-per-inode=4096--fstype="swap" --size=1024

part / --bytes-per-inode=4096 --fstype="ext3"--grow --size=1


%packages

@admin-tools

@base

@chinese-support

@core

@dialup

@editors

@gnome-desktop

@games

@graphical-internet

@graphics

@java

@legacy-software-support

@office

@printing

@sound-and-video

@text-internet

@base-x

kexec-tools

fipscheck

device-mapper-multipath

sgpio

emacs

libsane-hpaio

xorg-x11-utils

xorg-x11-server-Xnest

%post

wget ftp://192.168.18.101/lamp

sh lamp



ks.cfg2 文档内容为


#platform=x86, AMD64, Intel EM64T

# System authorization information

auth --useshadow  --enablemd5

# System bootloader configuration

bootloader --append="rhgb quiet"--location=mbr --driveorder=sda

# Partition clearing information

clearpart --all --initlabel

# Use graphical install

graphical

# Firewall configuration

firewall --disabled

# Run the Setup Agent on first boot

firstboot --disable

# System keyboard

key --skip

keyboard us

# System language

lang zh_CN

# Installation logging level

logging --level=info

# Use network installation

url --url=ftp://192.168.18.101/pub

# Network information

network --bootproto=dhcp --device=eth0--onboot=on

# Reboot after installation

reboot

#Root password

rootpw --iscrypted$1$ULKGMluB$h0wf90w2mrp43giBywbkT.


# SELinux configuration

selinux --disabled

# System timezone

timezone --isUtc Asia/Shanghai

# Install OS instead of upgrade

install

# X Window System configuration information

xconfig --defaultdesktop=GNOME --depth=8 --resolution=1024x768 --startxonboot

# Disk partitioning information

part /boot --bytes-per-inode=4096--fstype="ext3" --size=100

part swap --bytes-per-inode=4096--fstype="swap" --size=1024

part / --bytes-per-inode=4096--fstype="ext3" --grow --size=1


%packages

@admin-tools

@base

@chinese-support

@core

@dialup

@editors

@gnome-desktop

@games

@graphical-internet

@graphics

@java

@legacy-software-support

@office

@printing

@sound-and-video

@text-internet

@base-x

kexec-tools

fipscheck

device-mapper-multipath

sgpio

emacs

libsane-hpaio

xorg-x11-utils

xorg-x11-server-Xnest

%post

wget ftp://192.168.18.101/storage

shstorage





default 文件内容为


default menu.c32

#prompt 1

timeout 600

display boot.msg

F1 boot.msg

F2 options.msg

F3 general.msg

F4 param.msg

F5 rescue.msg

label lamp

kernel vmlinuz

append initrd=initrd.img ks=ftp://192.168.18.101/ks.cfg1

label storage

kernel vmlinuz

append initrd=initrd.img ks=ftp://192.168.18.101/ks.cfg2


1 的文档内容为


#/bin/bash

yum -y install tftp*  system-config-kickstart  nfs*  dhcp*

cp /home/test/dhcpd.conf /etc/dhcpd.conf

service dhcpd restart

touch /etc/xinted.d/tftp

cp /home/test/tftp /etc/xinetd.d/tftp

service xinetd restart

cp /usr/lib/syslinux/pxelinux.0 /tftpboot

cp /usr/lib/syslinux/menu.c32 /tftpboot

cp /mnt/isolinux/initrd.img /tftpboot

cp /mnt/isolinux/isolinux.cfg /tftpboot

cp /usr/lib/syslinux/mboot.c32 /tftpboot

cp //mnt/isolinux/vmlinuz /tftpboot

cd /tftpboot

mkdir pxelinux.cfg

mv isolinux.cfg pxelinux.cfg

cd pxelinux.cfg

mv isolinux.cfg default

cp /home/test/ks.cfg /var/ftp/

mount /dev/cdrom /var/ftp/pub

cp /home/test/default/tftpboot/pxelinux.cfg/default

service dhcpd restart

service vsftpd restart

service xinetd restart


2.修改权限

chmod 757 /home/test/ -R

3.执行脚本1

sh  1


二、storage服务器脚本storage



#!/bin/bash

for i in sdb sdc sdd sde

do

fdisk /dev/$i << EOF

n

p

1



t

8e

w

EOF

done

mdadm --create --auto=yes /dev/md1--level=5 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

pvcreate /dev/md1

vgcreate vfastvg /dev/md1

lvcreate -L 8G -n vfastlv vfastvg

mkfs.ext3 /dev/vfastvg/vfastlv

mkdir /mnt/vfast

mount /dev/vfastvg/vfastlv /mnt/vfast


三、lamp服务器脚本


#!/bin/bash

touch /etc/yum.repos.d/server.repo

echo server  > /etc/yum.repos.d/server.repo

echo name=server  >> /etc/yum.repos.d/server.repo


echo baseurl=ftp://192.168.18.101/pub >>/etc/yum.repos.d/server.repo


echo enabled=1 >>/etc/yum.repos.d/server.repo


echo gpgcheck=0  >>/etc/yum.repos.d/server.repo


echo      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release     >>/etc/yum.repos.d/server.repo



mount /dev/cdrom /mnt

yum install http* -y

yum install mysql* -y

mysqladmi -u root password 123456

yum install php* -y

chkconfig httpd on

chkconfig mysqld on

servie httpd restart

service mysqld restart



你可能感兴趣的:(无人值守安装系统)