Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1351163
  • 博文数量: 632
  • 博客积分: 2778
  • 博客等级: 大尉
  • 技术积分: 3387
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-31 09:09
个人简介

123

文章分类

全部博文(632)

文章存档

2014年(36)

2013年(33)

2012年(563)

分类: 系统运维

2014-04-14 11:22:34

说明:

Kickstart服务器系统:CentOS 5.10 64位

IP地址:192.168.21.128

需要安装部署的Linux系统:CentOS 5.10 64位

eth0(第一块网卡,用于外网)IP地址段:192.168.21.160-192.168.21.200

eth1(第二块网卡,用于内网)IP地址段:10.0.0.160-10.0.0.200

子网掩码:255.255.255.0

网关:192.168.21.2

DNS:8.8.8.8 8.8.4.4

所有服务器均支持PXE网络启动

实现目的:通过配置Kickstart服务器,全自动批量安装部署Linux系统

具体操作:

第一部分:在Kickstart服务器系统操作

一、关闭SELINUX


点击(此处)折叠或打开

  1. vi /etc/selinux/config
  2. #SELINUX=enforcing #注释掉
  3. #SELINUXTYPE=targeted #注释掉
  4. SELINUX=disabled #增加
  5. :wq! #保存退出
  6. setenforce 0 #使配置立即生效
二、配置防火墙,开启TCP:80端口、UDP:69端口

点击(此处)折叠或打开

  1. vi /etc/sysconfig/iptables #编辑
  2. -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #http服务需要此端口
  3. -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 69 -j ACCEPT #tftp服务需要此端口
  4. /etc/init.d/iptables restart #最后重启防火墙使配置生效

     三、安装http服务器

点击(此处)折叠或打开

  1. yum install httpd #安装
  2. chkconfig httpd on #设置开机启动
  3. service httpd start #启动

四、挂载系统安装镜像到http服务器站点目录

上传系统安装镜像文件CentOS-5.10-x86_64-bin-DVD-1of2.iso到/usr/local/src/目录


点击(此处)折叠或打开

  1. mkdir -p /var/www/html/os #创建挂载目录
  2. mount -t iso9660 -o loop /usr/local/src/CentOS-5.10-x86_64-bin-DVD-1of2.iso /var/www/html/os #挂载系统镜像
  3. vi /etc/fstab #添加以下代码。实现开机自动挂载
  4. /usr/local/src/CentOS-5.10-x86_64-bin-DVD-1of2.iso /var/www/html/os iso9660 defaults,ro,loop 0 0
  5. :wq! #保存退出

备注:iso9660使用df -T 查看设备 卸载:umount /var/www/html/os
    五、安装tftp服务器


点击(此处)折叠或打开

  1. yum install tftp tftp-server #安装
  2. vi /etc/xinetd.d/tftp #编辑
  3. service tftp
  4. {
  5. socket_type = dgram
  6. protocol = udp
  7. wait = yes
  8. user = root
  9. server = /usr/sbin/in.tftpd
  10. server_args = -s /var/lib/tftpboot
  11. disable = no
  12. per_source = 11
  13. cps = 100 2
  14. flags = IPv4
  15. }
  16. :wq! #保存退出
  17. service xinetd start #启动
  18. mkdir -p /var/lib/tftpboot
  19. cp /var/www/html/os/images/pxeboot/vmlinuz /var/lib/tftpboot
  20. cp /var/www/html/os/images/pxeboot/initrd.img /var/lib/tftpboot
  21. mkdir -p /var/lib/tftpboot/pxelinux.cfg
  22. cp /var/www/html/os/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #拷贝启动菜单
  23. vi /var/lib/tftpboot/pxelinux.cfg/default #编辑修改
  24. default linux
  25. prompt 0
  26. timeout 600
  27. display boot.msg
  28. F1 boot.msg
  29. F2 options.msg
  30. F3 general.msg
  31. F4 param.msg
  32. F5 rescue.msg
  33. label linux
  34. kernel vmlinuz
  35. append initrd=initrd.img ks= ksdevice=eth0 ip=dhcp
  36. label text
  37. kernel vmlinuz
  38. append initrd=initrd.img text
  39. label ks
  40. kernel vmlinuz
  41. append ks initrd=initrd.img
  42. label local
  43. localboot 1
  44. label memtest86
  45. kernel memtest
  46. append -
  47. :wq! #保存退出
  48. chmod 644 /var/lib/tftpboot/pxelinux.cfg/default #设置文件权限
  49. yum install syslinux #安装引导程序
  50. cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #拷贝引导文件到tftp服务器根目录

六、安装DHCP服务器

点击(此处)折叠或打开

  1. yum install dhcp #安装
  2. cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf #复制配置文件模板
  3. vi /etc/dhcpd.conf #编辑配置文件
  4. ddns-update-style interim; #设置DHCP服务器模式
  5. ignore client-updates; #禁止客户端更新
  6. subnet 192.168.21.0 netmask 255.255.255.0 { #设置网段
  7. option routers 192.168.21.2; #设置网关
  8. option subnet-mask 255.255.255.0; #设置子网掩码
  9. option domain-name-servers 8.8.8.8,8.8.4.4; #设置dns服务器地址
  10. range dynamic-bootp 192.168.21.160 192.168.21.200; #设置dhcp服务器IP地址租用的范围
  11. default-lease-time 21600; #默认租约时间
  12. max-lease-time 43200; #最大租约时间
  13. next-server 192.168.21.128; #tftp服务器地址
  14. filename "pxelinux.0"; #tftp服务器根目录下面的文件名
  15. }
  16. :wq! #保存退出
  17. vi /etc/sysconfig/dhcpd #指定DHCP服务的网络接口
  18. DHCPDARGS=eth0
  19. :wq! #保存退出
  20. dhcpd #测试dhcp服务器配置是否正确
  21. service dhcpd start #启动dhcp服务
  22. chkconfig dhcpd on #设置开机启动
七、配置kickstart自动安装文件

点击(此处)折叠或打开

  1. yum install system-config-kickstart #安装工具包
  2. cd /var/www/html
  3. vi ks.cfg #编辑
  4. # Kickstart file automatically generated by anaconda.
  5. install
  6. url --url=
  7. lang en_US.UTF-8
  8. zerombr yes
  9. key --skip
  10. keyboard us
  11. network --device eth0 --bootproto dhcp --onboot on
  12. #network --device eth0 --bootproto static --ip 192.168.21.250 --netmask 255.255.255.0 --gateway 192.168.21.2 --nameserver 8.8.8.8 --hostname CentOS5.10
  13. rootpw --iscrypted $1$QqobZZ1g$rYnrawi9kYlEeUuq1vcRS/
  14. firewall --enabled --port=22:tcp
  15. authconfig --enableshadow --enablemd5
  16. selinux --disabled
  17. timezone Asia/Shanghai
  18. bootloader --location=mbr --driveorder=sda
  19. # The following is the partition information you requested
  20. # Note that any partitions you deleted are not expressed
  21. # here so unless you clear all partitions first, this is
  22. # not guaranteed to work
  23. #clearpart --linux
  24. clearpart --all --initlabel
  25. part / --bytes-per-inode=4096 --fstype="ext3" --size=2048
  26. part /boot --bytes-per-inode=4096 --fstype="ext3" --size=128
  27. part swap --bytes-per-inode=4096 --fstype="swap" --size=500
  28. part /data --bytes-per-inode=4096 --fstype="ext3" --grow --size=1
  29. reboot
  30. %packages
  31. ntp
  32. expect
  33. @base
  34. @core
  35. @dialup
  36. @editors
  37. @text-internet
  38. keyutils
  39. trousers
  40. fipscheck
  41. device-mapper-multipath
  42. %post
  43. #同步系统时间
  44. ntpdate cn.pool.ntp.org
  45. hwclock --systohc
  46. echo -e "0 1 * * * root /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null" >> /etc/crontab
  47. service crond restart
  48. #添加用户组
  49. groupadd maintain
  50. groupadd develop
  51. mkdir -p /home/maintain
  52. mkdir -p /home/develop
  53. #添加用户
  54. useradd -g maintain user01 -d /home/maintain/user01 -m
  55. echo "123456"|passwd user01 --stdin
  56. useradd -g maintain user02 -d /home/maintain/user02 -m
  57. echo "123456"|passwd user02 --stdin
  58. useradd -g maintain user03 -d /home/maintain/user03 -m
  59. echo "123456"|passwd user03 --stdin
  60. useradd -g maintain user04 -d /home/maintain/user04 -m
  61. echo "123456"|passwd user04 --stdin
  62. #禁止root用户直接登录系统
  63. sed -i "s/#PermitRootLogin yes/PermitRootLogin no/g" '/etc/ssh/sshd_config'
  64. service sshd restart
  65. #禁止开机启动的服务
  66. chkconfig acpid off
  67. chkconfig atd off
  68. chkconfig autofs off
  69. chkconfig bluetooth off
  70. chkconfig cpuspeed off
  71. chkconfig firstboot off
  72. chkconfig gpm off
  73. chkconfig haldaemon off
  74. chkconfig hidd off
  75. chkconfig ip6tables off
  76. chkconfig isdn off
  77. chkconfig messagebus off
  78. chkconfig nfslock off
  79. chkconfig pcscd off
  80. chkconfig portmap off
  81. chkconfig rpcgssd off
  82. chkconfig rpcidmapd off
  83. chkconfig yum-updatesd off
  84. chkconfig sendmail off
  85. #允许开机启动的服务
  86. chkconfig crond on
  87. chkconfig kudzu on
  88. chkconfig network on
  89. chkconfig readahead_early on
  90. chkconfig sshd on
  91. chkconfig syslog on
  92. #禁止使用Ctrl+Alt+Del快捷键重启服务器
  93. sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/g" '/etc/inittab'
  94. telinit q
  95. #优化系统内核
  96. echo -e "ulimit -c unlimited" >> /etc/profile
  97. echo -e "ulimit -s unlimited" >> /etc/profile
  98. echo -e "ulimit -SHn 65535" >> /etc/profile
  99. source /etc/profile
  100. sed -i "s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g" '/etc/sysctl.conf'
  101. echo -e "net.core.somaxconn = 262144" >> /etc/sysctl.conf
  102. echo -e "net.core.netdev_max_backlog = 262144" >> /etc/sysctl.conf
  103. echo -e "net.core.wmem_default = 8388608" >> /etc/sysctl.conf
  104. echo -e "net.core.rmem_default = 8388608" >> /etc/sysctl.conf
  105. echo -e "net.core.rmem_max = 16777216" >> /etc/sysctl.conf
  106. echo -e "net.core.wmem_max = 16777216" >> /etc/sysctl.conf
  107. echo -e "net.ipv4.netfilter.ip_conntrack_max = 131072" >> /etc/sysctl.conf
  108. echo -e "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180" >> /etc/sysctl.conf
  109. echo -e "net.ipv4.route.gc_timeout = 20" >> /etc/sysctl.conf
  110. echo -e "net.ipv4.ip_conntrack_max = 819200" >> /etc/sysctl.conf
  111. echo -e "net.ipv4.ip_local_port_range = 10024 65535" >> /etc/sysctl.conf
  112. echo -e "net.ipv4.tcp_retries2 = 5" >> /etc/sysctl.conf
  113. echo -e "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
  114. echo -e "net.ipv4.tcp_syn_retries = 1" >> /etc/sysctl.conf
  115. echo -e "net.ipv4.tcp_synack_retries = 1" >> /etc/sysctl.conf
  116. echo -e "net.ipv4.tcp_timestamps = 0" >> /etc/sysctl.conf
  117. echo -e "net.ipv4.tcp_tw_recycle = 1" >> /etc/sysctl.conf
  118. echo -e "net.ipv4.tcp_tw_len = 1" >> /etc/sysctl.conf
  119. echo -e "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
  120. echo -e "net.ipv4.tcp_keepalive_time = 120" >> /etc/sysctl.conf
  121. echo -e "net.ipv4.tcp_keepalive_probes = 3" >> /etc/sysctl.conf
  122. echo -e "net.ipv4.tcp_keepalive_intvl = 15" >> /etc/sysctl.conf
  123. echo -e "net.ipv4.tcp_max_tw_buckets = 36000" >> /etc/sysctl.conf
  124. echo -e "net.ipv4.tcp_max_orphans = 3276800" >> /etc/sysctl.conf
  125. echo -e "net.ipv4.tcp_max_syn_backlog = 262144" >> /etc/sysctl.conf
  126. echo -e "net.ipv4.tcp_wmem = 8192 131072 16777216" >> /etc/sysctl.conf
  127. echo -e "net.ipv4.tcp_rmem = 32768 131072 16777216" >> /etc/sysctl.conf
  128. echo -e "net.ipv4.tcp_mem = 94500000 915000000 927000000" >> /etc/sysctl.conf
  129. /sbin/sysctl -p
  130. #执行外部脚本
  131. cd /root
  132. wget
  133. sh /root/autoip.sh
  134. :wq! #保存退出

八、添加脚本,自动设置Linux系统静态IP地址、DNS、网关、计算机名称

点击(此处)折叠或打开

  1. cd /var/www/html
  2. vi autoip.sh #编辑
  3. #!/bin/sh
  4. ROUTE=$(route -n|grep "^0.0.0.0"|awk '{print $2}')
  5. BROADCAST=$(/sbin/ifconfig eth0|grep -i bcast|awk '{print $3}'|awk -F":" '{print $2}')
  6. HWADDR=$(/sbin/ifconfig eth0|grep -i HWaddr|awk '{print $5}')
  7. IPADDR=$(/sbin/ifconfig eth0|grep "inet addr"|awk '{print $2}'|awk -F":" '{print $2}')
  8. NETMASK=$(/sbin/ifconfig eth0|grep "inet addr"|awk '{print $4}'|awk -F":" '{print $2}')
  9. cat >/etc/sysconfig/network-scripts/ifcfg-eth0<
  10. DEVICE=eth0
  11. BOOTPROTO=static
  12. BROADCAST=$BROADCAST
  13. HWADDR=$HWADDR
  14. IPADDR=$IPADDR
  15. NETMASK=$NETMASK
  16. GATEWAY=$ROUTE
  17. ONBOOT=yes
  18. EOF
  19. IPADDR1=$(echo $IPADDR|awk -F"." '{print $4}')
  20. cat >/etc/sysconfig/network-scripts/ifcfg-eth1<
  21. DEVICE=eth1
  22. BOOTPROTO=static
  23. BROADCAST=10.0.0.255
  24. HWADDR=$(/sbin/ifconfig eth1|grep -i HWaddr|awk '{print $5}')
  25. IPADDR=10.0.0.$IPADDR1
  26. NETMASK=255.255.255.0
  27. ONBOOT=yes
  28. EOF
  29. HOSTNAME=OsYunWei_HZ_$(echo $IPADDR|awk -F"." '{print $4}')
  30. cat >/etc/sysconfig/network<
  31. NETWORKING=yes
  32. NETWORKING_IPV6=no
  33. HOSTNAME=$HOSTNAME
  34. GATEWAY=$ROUTE
  35. EOF
  36. echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
  37. hostname=$HOSTNAME
  38. echo "nameserver 8.8.8.8" > /etc/resolv.conf
  39. echo "nameserver 8.8.4.4" >> /etc/resolv.conf
  40. :wq! #保存退出

备注:系统安装完成之后,第一启动请设置为硬盘,否则系统重新之后又自动安装系统了!

至此,Kickstart+HTTP+DHCP+TFTP全自动批量安装部署Linux系统安装完成!






阅读(660) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~