CentOS 6.5 system customization and encapsulation quick implementation script

Source: Internet
Author: User

Users who work in O & M for large enterprises or IDCs often have such requirements. Some people may not be very familiar with the advantages of Linux's secondary encapsulation, that is, when you need to perform one operation repeatedly, for example, to deploy 300 WEB servers, if you want to install one server, and then configure the WEB application after installing the system, how long does it take! However, if you have installed a server and then encapsulated the system twice, you will need to deploy the same WEB server with the encapsulated system next time, this is much simpler. At this time, some people may doubt whether there will be any driver problems. Of course, the system itself is OK. It is OK unless you are a special hardware. In fact, a simple understanding is that a windows ghost package is similar. If you still don't quite understand it, you may need to read the text several more times. I have tested some online tutorials in the early stage and found that CentOS6.0 and above are not very easy to use. Due to time reasons, I only paste the encapsulated shell here, in fact, there still needs to be a complicated process. You may need to carefully understand the shell in the kernel. If you need it, contact me. Of course, I often use it to encapsulate servers such as openvpn, vsftpd, and web, so that it can be fully automated and quickly deployed to improve my work efficiency, we will have the opportunity to share with you the encapsulation package of the last vsftpd server! The header is bleeding.

#! /Bin/bash
# Web: www.linuxidc.com
SYSTEM_DIR =/home/linuxidc
SYSTEM_NAME = linuxidc
Mount_ISO (){
Mkdir-p/home/linuxidc/Packages
Mkdir-p/home/source
Mkdir-p/mnt/cdrom1
Mkdir-p/mnt/cdrom2
Echo "Please make sure there is an ISO file in the optical drive and it can be mounted"
Echo "Enter Y/y to continue. Any key is used to exit the operation"
Read ret
[$ {Ret }! = "Y"-a $ {ret }! = "Y"] & exit 1
Echo "echo by default, the mount is/dev/cdrom to/mnt/cdrom1"
Mount/dev/cdrom/mnt/cdrom1
Mount/dev/cdrom1/mnt/cdrom2
Ls/mnt/cdrom2 | grep Packages
If ["$? "! = 0]
Then
Echo "the disk is not mounted successfully. Manually Remount the disk or try to mount the local ISO file"
Echo "Enter the local ISO path :"
Read ret
Ls $ {ret}
["$? "! = 0] & echo "The local ISO does not exist or the path is incorrect. exit running" & exit 1
["$? "= 0] & mount-o loop ${ret}/mnt/cdcom1
Fi
}
Copy_ISO_file (){
# Awk '/install/{print $2}' install. log | sed-e '/^ $/d'-e's/^ // G' | grep-v FINISHED | grep-v ": ">/home/source/packges. list
Mkdir-p/home/source
Cp-p/root/packges. list/home/source/packges. list
Mkdir-p/home/linuxidc/Packages/conf/
Cp-p/root/PS/*/home/linuxidc/Packages/conf/
For packges in $ (cat/home/source/packges. list)
Do
Cp/mnt/cdrom1/Packages/$ packges */home/linuxidc/Packages
[$? ! = 0] & echo "copy $ packges is faied! "& Cp/mnt/cdrom2/Packages/$ packges */home/linuxidc/Packages
Done
Rsync-a -- exclude = Packages -- exclude = repodata/mnt/cdrom2 // home/linuxidc/
Cp-p/root/initrd. img/home/linuxidc/isolinux/initrd. img
Mv/home/linuxidc/CentOS_BuildTag/home/linuxidc/linuxidc_BuildTag
}
Rebuild_repo_xml (){
Cd $ {SYSTEM_DIR}
Rm-fv $ {SYSTEM_DIR}/repodata /*
Mkdir-p $ {SYSTEM_DIR}/repodata/
Cp-fv/mnt/cdrom2/repodata/*-c6-x86_64-comps.xml $ {SYSTEM_DIR}/repodata/comps. xml
Createrepo-u "media: // $(head-1. discinfo)"-g $ {SYSTEM_DIR}/repodata/comps. xml $ {SYSTEM_DIR }/
Find $ {SYSTEM_DIR}/repodata/-type f-name TRANS. TBL | xargs/bin/rm-fv
}
Isolinux_cfg (){
Cat >$ {SYSTEM_DIR}/isolinux. cfg <EOF
Default auto
Timeout 600
# Default vesamenu. c32
# Prompt 1
Display boot. msg
Menu background splash.jpg
Menu title Welcome to linuxidc 6.4!
Menu color border 0 # ffffffff #00000000
Menu color sel 7 # ffffffff # ff000000
Menu color title 0 # ffffffff #00000000
Menu color tabmsg 0 # ffffffff #00000000
Menu color unsel 0 # ffffffff #00000000
Menu color hotsel 0 # ff000000 # ffffffff
Menu color hotkey 7 # ffffffff # ff000000
Menu color scrollbar 0 # ffffffff #00000000
Label auto
Menu label ^ Auto Install system
Menu default
Kernel vmlinuz
Append ks = cdrom:/isolinux/ks. cfg initrd = initrd. img
Label linux
Menu label ^ Install or upgrade an existing system
Kernel vmlinuz
Append initrd = initrd. img
Label vesa
Menu label Install system with ^ basic video driver
Kernel vmlinuz
Append initrd = initrd. img xdriver = vesa nomodeset
Label rescue
Menu label ^ Rescue installed system
Kernel vmlinuz
Append initrd = initrd. img rescue
Label local
Menu label Boot from ^ local drive
Localboot 0 xffff
Label memtest86
Menu label ^ Memory test
Kernel memtest
Append-
EOF
}
Ks_file (){
Cat >$ {SYSTEM_DIR}/isolinux/ks. cfg <EOF
# Kickstart file automatically generated by anaconda.
# Linuxidc
# Date 2013-07-20
# Version = V6.4
Install
Text
Cdrom
Lang zh_CN.UTF-8
Keyboard us
Skipx
Network -- device eth0 -- bootproto static -- ip 192.168.50.1 -- netmask 255.255.255.0 -- gateway 192.168.50.254 -- hostname linuxidc-FTP
Rootpw -- iscrypted/gvPu5dZM6eis
Firewall -- service = ssh
Authconfig -- enableshadow -- passalgo = sha512
Selinux -- enforcing
Timezone -- utc Asia/Shanghai
Bootloader -- location = mbr -- driveorder = sda -- append = "rhgb crashkernel = auto quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# Here so unless you clear all partitions first, this is
# Not guaranteed to work
# Clearpart -- none
Clearpart -- all -- initlabel
Zerombr yes
Part/boot -- fstype = ext4 -- size = 100
Part swap -- size = 4000
Part/-- fstype = ext4 -- size = 10000
Part/opt -- fstype = ext4 -- grow -- size = 1000
Reboot
# Repo -- name = "linuxidc IDC" -- baseurl = cdrom: sr0 -- cost = 100
% Packages -- nobase
@ Base
% Packages
@ Chinese-support
@ Core
Glibc-2.12-1.107.el6.i686
Lrzsz
% Post -- nochroot
Cp/mnt/source/Packages/conf/settings. sh/mnt/sysimage/tmp/settings. sh
Mv/mnt/sysimage/etc/vsftpd. conf/mnt/sysimage/etc/vsftpd. conf. back
Mv/mnt/sysimage/etc/pam. d/vsftpd/mnt/sysimage/etc/pam. d/vsftpd. back
Cp/mnt/source/Packages/conf/vsftpd. conf/mnt/sysimage/etc/vsftpd. conf
Cp/mnt/source/Packages/conf/ftpmgt.exe/mnt/sysimage/etc/vsftpd/ftpmgt.exe
Cp/mnt/source/Packages/conf/vsftpd/mnt/sysimage/etc/pam. d/vsftpd
Cp/mnt/source/Packages/conf/moban/mnt/sysimage/etc/vsftpd/moban
Cp/mnt/source/Packages/conf/xianzhi/mnt/sysimage/etc/vsftpd/xianzhi
Chmod 750/mnt/sysimage/tmp/settings. sh
% Post
/Tmp/settings. sh
EOF
}
Build_new_ISO (){
Cd $ {SYSTEM_DIR}
Mkisofs-o $ {SYSTEM_NAME }. iso-B isolinux/isolinux. bin-c isolinux/boot. cat-no-emul-boot-load-size 4-boot-info-table-R-J-v-V linuxidc-T $ {SYSTEM_DIR}
}
Main (){
Mount_ISO
Copy_ISO_file
Isolinux_cfg
Ks_file
Rebuild_repo_xml
Build_new_ISO
}
Main


This article from the Linux community website (www.linuxidc.com) original link: http://www.linuxidc.com/Linux/2014-03/98376.htm
This article from the Linux community website (www.linuxidc.com) original link: http://www.linuxidc.com/Linux/2014-03/98376.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.