生成centos7 安装脚本
[root@us-1-217 install]# cat gen7.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, crypt
base_path = '/opt/opmgmt/install'
pxe_path = os.path.join(base_path, 'pxelinux.cfg')
kickstart_path = os.path.join(base_path, 'kickstart')
sitename = 'us.install.suntv.tv'
installhost = '10.150.1.217'
yumhost = 'us.yum.suntv.tv'
hosts = 'hosts.txt'
os = 'centos7'
password = 'password'
rootpw = crypt.crypt(password, '$6$MySalt')
def generate_pxe_file(os, mac, sitename, pxe_path):
pxe = '''default menu.c32
prompt 0
timeout 100
LABEL %s
MENU DEFAULT
MENU LABEL %s
KERNEL %s/vmlinuz
APPEND initrd=%s/initrd.img ks=http://%s/kickstart/%s ksdevice=link ramdisk_size=102400 console=ttyS1,115200
''' % (os, mac, os, os, sitename, mac)
filename = pxe_path + '/01-' + '-'.join(mac.split(':'))
with open(filename, 'w') as f:
f.write(pxe)
print 'generate pxe file: %s' % ('01-' + '-'.join(mac.split(':')))
def generate_kickstart_file(os, sitename, rootpw, kickstart_path, dev, prefix, mac, private_ip, private_mask, public_ip, public_mask, default_gw):
# interface
if dev == 'em':
private_interface = '''cat > /etc/sysconfig/network-scripts/ifcfg-%s1 << _EOF_
DEVICE=%s1
ONBOOT=yes
BOOTPROTO=static
IPADDR=%s
NETMASK=%s
_EOF_
''' % (dev, dev, private_ip, private_mask)
if public_ip != '0' and public_mask !='0':
public_interface = '''cat > /etc/sysconfig/network-scripts/ifcfg-%s2 << _EOF_
DEVICE=%s2
ONBOOT=yes
BOOTPROTO=static
IPADDR=%s
NETMASK=%s
_EOF_
''' % (dev, dev, public_ip, public_mask)
else:
public_interface = ''
if dev == 'eth':
private_interface = '''cat > /etc/sysconfig/network-scripts/ifcfg-%s0 << _EOF_
DEVICE=%s0
ONBOOT=yes
BOOTPROTO=static
IPADDR=%s
NETMASK=%s
_EOF_
''' % (dev, dev, private_ip, private_mask)
if public_ip != '0' and public_mask !='0':
public_interface = '''cat > /etc/sysconfig/network-scripts/ifcfg-%s1 << _EOF_
DEVICE=%s1
ONBOOT=yes
BOOTPROTO=static
IPADDR=%s
NETMASK=%s
_EOF_
''' % (dev, dev, public_ip, public_mask)
else:
public_interface = ''
# network
network = '''cat > /etc/sysconfig/network << _EOF_
NETWORKING=yes
HOSTNAME=%s-%s-%s
GATEWAY=%s
_EOF_
''' % (prefix, private_ip.split('.')[2], private_ip.split('.')[3], default_gw)
# dns
dns = '''cat > /etc/resolv.conf << _EOF_
nameserver 8.8.8.8
nameserver 8.8.4.4
_EOF_
'''
# ssh
ssh = '''sed -i 's/#Port 22/Port 29922/g' /etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/g' /etc/ssh/sshd_config
sed -i 's/#GSSAPIAuthentication no/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
'''
# tcp/ip
tcp_ip = '''cat >> /etc/sysctl.conf << _EOF_
fs.file-max = 100000
#net.ipv4.tcp_syncookies = 1
#net.ipv4.tcp_tw_reuse = 1
#net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65000
#net.ipv4.tcp_max_syn_backlog = 8192
#net.ipv4.tcp_max_tw_buckets = 5000
_EOF_
'''
# limit
limit ='''cat >> /etc/security/limits.conf << _EOF_
* soft nofile 100000
* hard nofile 100000
_EOF_
'''
# hosts
hosts ='''cat >> /etc/hosts << _EOF_
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
%s %s
_EOF_
''' % (installhost, yumhost)
# yum
yum ='''
rm -rf /etc/yum.repos.d/*
curl http://%s/centos6.repo -o /etc/yum.repos.d/centos.repo
curl http://%s/epel.repo -o /etc/yum.repos.d/epel.repo
''' % (yumhost, yumhost)
kickstart = '''text
keyboard us
timezone Asia/Shanghai
lang en_US.UTF-8
skipx
auth --enableshadow --passalgo=sha512
rootpw --iscrypted %s
#zerombr
bootloader --boot-drive=sda --location=mbr
ignoredisk --only-use=sda
clearpart --drives=sda --all
#part swap --fstype='swap' --ondisk=sda --size=8000
part biosboot --fstype='biosboot' --size=1
part / --fstype='xfs' --ondisk=sda --size=50000
part /opt --fstype='xfs' --ondisk=sda --size=1 --grow
network --bootproto=dhcp --device=%s --activate
install
url --url='http://%s/%s'
logging level=info
firewall --disabled
selinux --disabled
firstboot --disabled
services --enabled=network,rc-local --disabled=NetworkManager,postfix
reboot
%%packages
@core
%%end
%%pre
/usr/sbin/parted -s /dev/sda mklabel gpt
%%end
%%post
%s
%s
%s
%s
%s
%s
%s
%s
%s
%%end
''' % (rootpw, mac, sitename, os, private_interface, public_interface, network, dns, ssh, tcp_ip, limit, hosts, yum)
filename = kickstart_path + '/' + mac
with open(filename, 'w') as f:
f.write(kickstart)
print 'generate kickstart file: %s ' % mac
with open(hosts, 'r') as f:
for host in f:
dev, prefix, mac, private_ip, private_mask, public_ip, public_mask, default_gw = host.strip('\n').split(' ')
generate_pxe_file(os, mac.lower(), sitename, pxe_path)
generate_kickstart_file(os, sitename, rootpw, kickstart_path, dev, prefix, mac.lower(), private_ip, private_mask, public_ip, public_mask, default_gw)
生成centos7 安装脚本的更多相关文章
- 用python & bat写软件安装脚本 + HM NIS Edit自动生成软件安装脚本
2019-03-11更新:原来NSIS脚本也可以禁用64位文件操作重定向的! 1.在安装脚本的开始处定义 LIBRARY_X64. !include "MUI.nsh"!inclu ...
- Centos7安装Docker CE
每次安装Docker都要去找文档,或者每次安装的都不一样,还是要好好管理自己的这些东西,下次用的时候可以省很多的时间 Docker的早期版本称为docker或docker-engine:现在的 ...
- Centos7搭建pptp一键安装脚本
废话不多说,先上脚本地址:Centos7一键pptp 使用: wget http://files.cnblogs.com/files/wangbin/CentOS7-pptp-host1plus.sh ...
- centos7 安装docker(手动和脚本安装)换源 卸载
centos7 安装docker(手动和脚本安装)换源 卸载 Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker ...
- centos7 lvm合并分区脚本初探-linux性能测试 -centos7修改网卡名字-jdk环境安装脚本-关键字查询文件-批量添加用户
1.#!/bin/bash lvmdiskscan | grep centos > /root/a.txt a=`sed -n '1p' /root/a.txt` b=`sed -n '2p' ...
- Centos7安装Docker 基于Dockerfile 搭建httpd运行环境
Centos7安装Docker 基于Dockerfile 搭建httpd运行环境 docker docker搭建 docker build 本文档完成目标内容如下 使用Docker搭建http服务器一 ...
- Centos7安装jexus,部署asp.net core,asp.net mvc
什么是Jexus 官网解释:https://www.jexus.org/ Jexus是一款Linux平台上的高性能WEB服务器和负载均衡网关,Jexus Web Service,简称JWS,以支持AS ...
- CentOS7安装配置Bacula yum方法
参考: https://www.baidu.com/link?url=o2QIy2YZWjsJPAFJuYFhrH3nPvtyRkSe-o5Q_FqFZ5E1EMOsIOmGeKm0HAonwHOw8 ...
- RHEL7或CentOS7安装11.2.0.4 RAC碰到的问题
RHEL7或CentOS7安装11.2.0.4 RAC碰到的问题 随着Linux 版本的普及,但Oracle数据库主流版本仍是11gR2, 的支持不很完美,在Linux 上安装会遇到几处问题,以此记录 ...
随机推荐
- 最长上升子序列(LIS)的n*log(n)求法
方法: 对于某个序列,设一个数组,将序列第一个数放入,然后再一个一个判断序列下一位,如果大于当前数组的末尾元素,则加入数组,否则利用二分法找到第一个大于等于当前数的元素并替换,最后这个数组的长度len ...
- C++_类继承6-继承和动态内存分配
如果基类使用动态内存分配,并重新定义赋值和复制构造函数,这将怎样影响派生类的实现?这个问题的答案取决于派生类的属性.如果派生类也使用动态内存分配,那就需要注意学习新的小技巧. 派生类不适用new // ...
- Karma+Jasmine测试环境搭建
1.如果你还没安装node的话,去这里下载:http://nodejs.cn/download/,选择跟你电脑匹配的并进行安装,一路next下来就行,路径最好改成自己让自己舒服的,默认的路径可能会很让 ...
- setlocal enabledelayedexpansion 解释
看字面的意思是:设置本地为延迟扩展.其实也就是:延迟变量,全称"延迟环境变量扩展", 在cmd执行命令前会对脚本进行预处理,其中有一个过程是变量识别过程,在这个过程中,如果有两个% ...
- 面向对象中的@classonlymethod 与 @classmethod的区别
如果要使用classonlymethod ,则需要先定义好一个classonlymethod 类. 首先我们需要明白无论是classonlymethod还是classmethod,本质都是一个类,而c ...
- mysql命令查询表的个数
https://blog.csdn.net/xiao__ge/article/details/56671221 语句如下: SELECT count(TABLE_NAME) FROM informat ...
- NodeJS使用SSL证书
[From] https://segmentfault.com/q/1010000004705326 var options = { key: fs.readFileSync('../ssl/priv ...
- js数组去重 javascript版
//js数组去重 //思路: // 1.放入第一个元素 // 2.放入第n个元素,和第n个之前的元素就行比较,如果有重复,则跳过.没有重复就加入数组中 // 3.返回新的去重后数组 Array.pro ...
- Js与标签属性
关于在JS中设置标签属性 2017-10-09 23:04 by 清风221, 12790 阅读, 0 评论, 收藏, 编辑 Attribute 该属性主要是用来在标签行内样式,添加.删除.获取属性. ...
- win10 sshsecureshellclient删除profile保存的信息
C:\Users\joe\AppData\Roaming\SSH