一键安装cobbler脚本
#!/bin/bash
#
# Install Cobbler(Kickstart) Tools for CentOS-/
# Created by OceanHo(gzhehai@foxmail.com) AT -- #
# 操作系统发型主版本
os_release_ver=`sed -r 's#[a-zA-Z ]+(5|6|7)\..*#\1#g' /etc/redhat-release` #
# cobbler settings 文件中的server参数
# auto:表示自动 从 net_bind_device 指定的设备中获取
# 也可以手动指定
cobbler_server_ip="auto"
#
# cobbler settings 文件中的next-server参数
# auto:表示自动 从 net_bind_device 指定的设备中获取
# 也可以手动指定
cobbler_next_server_ip="auto" #
# cobbler 安装系统可以使用的默认密码(盐 / 密码:)
password_salt="`openssl rand -base64 32`"
default_password_crypted=`openssl passwd - -salt "${password_salt}" ''` # #
# 定义一个变量,用来表示cobbler涉及到网络参数自动获取网卡设备名称
# 比如:dhcpd,cobbler的settings文件中涉及到的IP地址等等
#
net_auto_dev="eth1"
dhcpd_template_geturl="https://raw.githubusercontent.com/oceanho/my-shell/master/scripts/cobbler/dhcpd_172-16-1-0_24.template" dhcpd_bind_net_prefix="172.16.1"
dhcpd_bind_net_subnet="172.16.1.0"
dhcpd_bind_net_netmask="255.255.255.0" # 显示帮助
function help()
{
echo -e `
clear
cat <<EOF
\n
\[36m
\n
功能\n
实现Cobbler程序一键安装和部署
\n
\n 参数\n
cobbler-server-ip,指定cobbler settings的server-ip参数,默认从net-auto-dev网卡设备中自动获取\n
cobbler-next-server-ip,指定cobbler settings的next-server-ip参数,默认从net-auto-dev网卡设备中自动获取\n
net-auto-dev,指定自动获取cobbler网络参数相关的配置参数网卡设备,默认eth1
\n
\n 举例\n
、使用ens34网卡设备安装并绑定cobbler的服务(dhcp/tftp)\n
----------------------------------------------------\n
sh $# cobbler-server-ip=auto cobbler-next-server-ip=auto net-auto-dev=ens34
\n
\n
、手动指定cobbler-server-ip 与 next-server-ip,dhcp.template 的子网,掩码等信息自动从eth1网卡上获取 \n
--------------------------------------------------------------------------------------------------------
\n
sh $# cobbler-server-ip=172.16.1.200 cobbler-next-server-ip=172.16.1.200 net-auto-dev=ens34 \n
\[0m
EOF
`
} case "$1" in
-h|--help|help|-help )
help
exit
;;
esac #
# 处理参数
# 参数格式要求
# key=value,比如 net-auto-dev=eth1
until [ $# -eq ]
do
if egrep -q "[a-z-]+=.*"<<<"$1"
then
k=$(sed -r 's#([a-z-]+)=.*#\1#g' <<<"$1")
v=$(sed -r 's#[a-z-]+=(.*)#\1#g' <<<"$1")
case "$k" in
"cobbler-server-ip" )
cobbler_server_ip=$v
;;
"cobbler-next-server-ip" )
cobbler_next_server_ip=$v
;;
"net-auto-dev" )
net_auto_dev=$v
;;
esac
fi
shift
done #
# 根据传入的参数,初始化一些必须的参数,比如绑定dhcpd服务的网段地址,cobbler settings配置文件中涉及到的server的ip地址等参数的初始化
function init_param()
{
str=`ip addr show $net_auto_dev | awk -F"[ ]+" 'NR==3{print $3}'`
if [ $? -ne ]
then
echo -e "\033[31m 获取网卡配置信息失败. \033[0m"
return
fi str_ip="${str%/*}"
str_netmask="${str#*/}" #
# 以下的写法只能支持 // 子网
case $str_netmask in
"" )
dhcpd_bind_net_prefix=`egrep -o "([0-9]+.){1}" <<<$str_ip`
dhcpd_bind_net_subnet="${dhcpd_bind_net_prefix}0.0.0"
dhcpd_bind_net_netmask="255.0.0.0"
;;
"" )
dhcpd_bind_net_prefix=`egrep -o "([0-9]+.){2}" <<<$str_ip`
dhcpd_bind_net_subnet="${dhcpd_bind_net_prefix}0.0"
dhcpd_bind_net_netmask="255.255.0.0"
;;
"" )
dhcpd_bind_net_prefix=`egrep -o "([0-9]+.){3}" <<<$str_ip`
dhcpd_bind_net_subnet="${dhcpd_bind_net_prefix}0"
dhcpd_bind_net_netmask="255.255.255.0"
;;
esac if [ "$cobbler_server_ip" == "auto" ]
then
cobbler_server_ip=$str_ip
fi
if [ "$cobbler_next_server_ip" == "auto" ]
then
cobbler_next_server_ip=$str_ip
fi
} #
# YUM of epel
# 自动现在cobbler先决条件项目,比如epel源等、
# 说明:如果已经有了epel源,该函数不执行安装epel源的操作,如果没有epel源,自动安装阿里云的epel源
function install_pre_require()
{
echo -e "\033[36m Installing requires \033[0m"
if [ `yum --disablerepo=\* --enablerepo=epel repolist | grep -c epel` -eq ]
then
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-${os_release_ver}.repo
fi
echo -e "\033[32m requires Completed. \033[0m"
} function install_cobbler_softs()
{
echo -e "\033[36m Installing cobbler-softs \033[0m"
fix_missing_packages_for_centos7_epel
yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd
if [ $? -ne ]
then
echo -e "\033[31m Action failed. \033[0m"
return
fi
echo -e "\033[32m cobbler-softs Completed. \033[0m"
} function fix_missing_packages_for_centos7_epel()
{
if [ $os_release_ver -eq ]
then
# rpm -ql Django14 | wc -l || e
echo -e "\033[33m May be miss Django14-1.4.21-1.el7.noarch. need you fixed. \033[0m"
# yum -y localinstall
fi
} #
# 配置DHCP服务
# 该函数会从远程主机下载,dhcpd.template 文件
# 说明:DHCP IP地址段是 -
function configure_dhcp_template()
{
echo -e "\033[36m Configure dhcp.template \033[0m"
cp /etc/cobbler/dhcp.template{,$(date +%s).ori}
wget -O /etc/cobbler/dhcp.template ${dhcpd_template_geturl}
sed -i "21s#.*#subnet $dhcpd_bind_net_subnet netmask $dhcpd_bind_net_netmask {#" /etc/cobbler/dhcp.template
sed -i "22s#.*# option subnet-mask ${dhcpd_bind_net_netmask};#" /etc/cobbler/dhcp.template
sed -i "23s#.*# range dynamic-bootp ${dhcpd_bind_net_prefix}100 ${dhcpd_bind_net_prefix}254;#" /etc/cobbler/dhcp.template
} function configure_tftpd()
{
echo -e "\033[36m Configure tftpd \033[0m"
sed -i 's#yes#no#' /etc/xinetd.d/tftp
} function configure_httpd()
{
echo -e "\033[36m Configure httpd \033[0m"
} function sync_configure()
{
echo -e "\033[36m Sync cobbler settings \033[0m"
cobbler sync
} function restart_services()
{
echo -e "\033[36m Restart cobbler's services \033[0m"
if [ $os_release_ver -ne ]
then
/etc/init.d/cobblerd restart
/etc/init.d/httpd restart
/etc/init.d/xinetd restart
else
systemctl restart cobblerd.service
systemctl restart httpd.service
systemctl restart cobblerd.service
systemctl restart xinetd.service
fi
} function configure_cobbler_services()
{
configure_dhcp_template
configure_tftpd
configure_httpd cp /etc/cobbler/settings{,$(date +%s).ori} # 备份 # 修改配置文件
sed -i "s/server: .*/server: ${cobbler_server_ip}/" /etc/cobbler/settings
sed -i "s/next_server: .*/next_server: ${cobbler_next_server_ip}/" /etc/cobbler/settings
sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings
sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings # 限制客户端只能安装一次系统
sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'oceanhoasdhakdhakjs' '123456'`\"#" /etc/cobbler/settings
#sed -i 's#yes#no#' /etc/xinetd.d/rsync
sed -i 's#yes#no#' /etc/xinetd.d/tftp
} # 程序入口
function main()
{ # 初始化参数
init_param install_pre_require
install_cobbler_softs
configure_cobbler_services
sync_configure
restart_services
cobbler get-loaders
sync_configure
cobbler check
} # 执行安装程序操作
main
一键安装cobbler脚本的更多相关文章
- linux一键安装vncserver脚本
title: linux一键安装vncserver脚本 date: 2016-04-11 14:32:04 tags: --- linux多数情况下是作为服务器使用的,管理员一般也喜欢使用命令行来管理 ...
- Rehat一键安装mysql脚本和备份数据库脚本
Rehat一键安装mysql脚本 ##说明:适用,Rehat 5 6 7 1.运行状态,运行成功输出mysql临时密码 2.代码如下 #!/bin/bash #获取系统信息 sudo cat /etc ...
- (转)CentOS一键安装Nginx脚本
原文:https://www.xiaoz.me/archives/10301 https://blog.slogra.com/post-676.html-----centos7一键安装nginx脚本
- rsync服务端一键安装rsync脚本(非源码)
export RSYNC_PASSWORD=123 USER=rsync AUTHUSERS=bck MK=backupmk local_dir=/backup yum remove rsync &a ...
- 一键安装lnmp脚本
前段时间一直在找一个快速部署lnmp环境的方法,也没找着,就自己写了一个,结合网上的大神们的.我的方法是脚本结合源码包,很多依赖裤都是yum安装的,这都在脚本里面,需要的源码包我都下载好了,打包成压缩 ...
- 【转载】一键安装maven脚本
#!/bin/bashif [ -z "${MAVEN_HOME}" ]; then #得到时间 TIME_FLAG=`date +%Y%m%d_%H%M%S` #备份配置文件 c ...
- Node_exporter一键安装部署脚本(Shell)
#!/bin/bash # # rhel7. 安装node_exporter 用于监控数据采集 # Usage: # sh addNode.sh #Logs: /var/log/messages #H ...
- centos下的redis一键安装shell脚本
#!/bin/bash yum install cpp binutils glibc-kernheaders glibc-common glibc-devel gcc make wget #安装依赖库 ...
- rsync客户端一键安装rsync脚本(源码)
客户端 read -np "请输入源码rsync的URL 地址 包名(以空格为分隔符,别带/):" URL DZ BM yum remove -y rsync &>& ...
随机推荐
- jQuery .delay()
.delay() Effects > Custom .delay( duration [, queueName ] )Returns: jQuery Description: Set a tim ...
- UNITY相关的一些新功能,新想法
1,lua profiler for unity : https://github.com/ElPsyCongree/LuaProfiler-For-Unity 参考文章:https://blog.c ...
- Uep弹窗showModalDialog的使用
function imageMaintain() { $.showModalDialog($$pageContextPath + "uepI/imageMaintain.do?service ...
- apache禁止php解析--安全
#禁止解析php <Directory "/data/www/data/"> php_admin_flag engine off <filesmatch &quo ...
- Oracle 安装 RAC 11.2.0.4 centos7.4 -udev磁盘绑定/执行root脚本报错
在centos 7.4上安装oracle rac 11.2.0.4 报错及相关解决 $ cat /etc/redhat-release CentOS Linux release 7.4.1708 (C ...
- java里null强转为某个类会报错吗?
1.定义一个User类如下: /** * @author lizhibiao * @date 2018/11/27 17:21 */public class User{ private String ...
- 对于富文本编辑器中使用lazyload图片懒加载
使用lazyload.js图片懒加载的作用是给用户一个好的浏览体验,同时对服务器减轻了压力,当用户浏览到该图片的时候再对图片进行加载,项目中使用lazyload的时候需要将图片加入data-orgin ...
- Python学习之GIL&进程池/线程池
8.6 GIL锁** Global interpreter Lock 全局解释器锁 实际就是一把解释器级的互斥锁 In CPython, the global interpreter lock, or ...
- C++类大小的计算
这里记录一下怎么计算类对象的大小. 大概总结下,类的大小需要考虑以下内容: 非静态成员变量大小 数据对齐到多少位 有无虚函数(即需不需要指向虚函数表的指针,如果考虑继承的情况,则还需要看继承了多少个指 ...
- centos v7.0解决乱码
[root@localhost ~]# ll 鎬荤敤閲4-rw-------. 1 root root 1045 8鏈 24 21:17 anaconda-ks.cfg [root@localhost ...