linux系统初始化脚本
#!/bin/bash
#make by Jeck
. /etc/init.d/functions
export LANG="en_US.UTF-8"
#生成local.repo文件
function local.repo() {
cat > /tmp/local.repo <<EOF
[sever]
name=yum
baseurl=file:///media
enabled=1
gpgcheck=0
EOF
}
#生成localnet.repo文件
function localnet.repo() {
source=`sed s/[[:space:]]//g /etc/issue | head -1 |cut -b 1-6 | tr '[:upper:]' '[:lower:]'`
cat > /tmp/$source.repo <<EOF
[sever]
name=localnet
baseurl=http://192.168.254.1/$source
gpgchek=1
enabled=1
gpgkey=http://192.168.254.1/$source/RPM-GPG-KEY-redhat-release
EOF
}
#生成CentOS6-Base-163.repo文件
function 163.repo() {
cat > /tmp/CentOS6-Base-163.repo <<EOF
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-\$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/os/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-\$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/updates/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-\$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/extras/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/centosplus/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-\$releasever - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/\$releasever/contrib/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
EOF
}
#yum源配置
function yum-source() {
rm -f /etc/yum.repos.d/*
read -t 5 -p "do you want to build local.repo : _(y/n)" m
case $m in
y)
local.repo
cp -f /tmp/local.repo /etc/yum.repos.d/ && action "local.repo build " /bin/true
;;
n)
echo "the local.repo is in /tmp ,you can copy by hand"
;;
*)
echo "you input error,please input y/n"
;;
esac
read -p "do you want to build l63.repo or localnet.repo : _(localnet/163)" n
case $n in
163)
wget -P /tmp http://mirrors.163.com/.help/CentOS6-Base-163.repo &>/dev/null
if [ $? -eq 0 ];then
action "download CentOS6-Base-163.repo" /bin/true
cp -f /tmp/CentOS6-Base-163.repo /etc/yum.repos.d/
[ $? -eq 0 ] && action "CentOS6-Base-163.repo build " /bin/true || action "CentOS6-Base-163.repo build " /bin/false
else
163.repo
cp -f /tmp/CentOS6-Base-163.repo /etc/yum.repos.d
[ $? -eq 0 ] && action "CentOS6-Base-163.repo build " /bin/true || action "CentOS6-Base-163.repo build " /bin/false
fi
;;
localnet)
localnet_name=`sed s/[[:space:]]//g /etc/issue | head -1 |cut -b 1-6 | tr '[:upper:]' '[:lower:]'`
wget -P /tmp http://192.168.254.1/${localnet_name}.repo &>/dev/null
if [ $? -eq 0 ];then
cp -f /tmp/${localnet_name}.repo /etc/yum.repos.d/
[ $? -eq 0 ] && action " create localnet.repo" /bin/true || action "create localnet.repo " /bin/false
else
localnet.repo
cp -f /tmp/${localnet_name}.repo /etc/yum.repos.d
[ $? -eq 0 ] && action " create localnet.repo" /bin/true || action "create localnet.repo " /bin/false
fi
;;
*)
echo "you input error,please input localnet/163"
;;
esac
yum clean all &>/dev/null
yum makecache &>/dev/null
sleep 1
}
function hostname() {
read -t 5 -p "do you want to set hostname:_(y/n)" rs
case $rs in
y)
read -p "please input your hostname:__" HOSTNAME_NEW
HOSTNAME_OLD=`tail -1 /etc/sysconfig/network | awk -F"=" '{print $2}'`
sed -i "s/HOSTNAME=${HOSTNAME_OLD}/HOSTNAME=${HOSTNAME_NEW}/g" /etc/sysconfig/network
HOSTNAME=`tail -1 /etc/sysconfig/network | awk -F"=" '{print $2}'`
action "your hostname is ${HOSTNAME}" /bin/true
;;
*)
sleep 1
esac
}
#selinux 配置
function selinux() {
selinux_status=` cat /etc/sysconfig/selinux | grep -v ^# | grep -v ta | awk -F "=" '{print $2}'| grep -v ^$`
if [ ${selinux_status} == "enforcing" ];then
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
sleep 1
setenforce 0
action "selinux is `cat /etc/sysconfig/selinux | grep -v ^# | grep -v ta | awk -F "=" '{print $2}'| grep -v ^$` " /bin/true
fi
}
#防火墙iptables配置
function iptables() {
service iptables restart &>/dev/null
/sbin/iptables -F
service iptables save &>/dev/null
service iptables stop &>/dev/null
chkconfig iptables off &>/dev/null
action "iptables is stop" /bin/true
}
#服务启动配置
function service() {
for service in `chkconfig --list | grep 3:on | awk '{print $1}'`; do chkconfig $service off ; done
for service in network rsyslog crond sshd;do chkconfig $service on;done
[ $? -eq 0 ] && action "the service is OK" /bin/true
echo "the `chkconfig --list | grep 3:on | awk '{print $1}' | tr '\n' ','` is on now "
}
#系统语言环境配置
function language() {
language_old=`cat /etc/sysconfig/i18n | awk -F"=" '{print $2}' | head -1 `
language_new="en_US.UTF-8"
sed -i "s/LANG=${language_old}/LANG=${language_new}/g" /etc/sysconfig/i18n
language=`cat /etc/sysconfig/i18n | awk -F"=" '{print $2}' | head -1`
[ $? -eq 0 ] && action "system language is ${language} " /bin/true || action "system language is ${language_new} " /bin/false
. /etc/sysconfig/i18n
export LANG=zh_CN
}
#ntp时间同步配置
function ntp() {
zone_old=`cat /etc/sysconfig/clock | awk -F"=" '{print $2}'`
zone_new='Asia/Shanghai'
sed -i "s#ZONE=${zone_old}#ZONE=${zone_new}#g" /etc/sysconfig/clock
rm -fr /etc/localtime
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
/usr/sbin/ntpdate pool.ntp.org &>/dev/null
[ $? -eq 0 ] && action "the time update now `date +%F-%H:%M:%S` " /bin/true || action "the time update now `date +%F-%H:%M:%S`" /bin/false
echo '#time sync by fuzj at 2014-10-1'>>/var/spool/cron/root
echo '*/10 * * * * 192.168.254.199 pool.ntp.org >/dev/null 2>&1'>>/var/spool/cron/root
}
#内核参数配置
function kernal() {
cat >> /etc/sysctl.conf <<EOF
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
net.netfilter.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
EOF
[ $? -eq 0 ] && action "the kernal is OK " /bin/true
}
function ssh ()
{
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
useradd fuzj
echo "fuzj123" | passwd --stdin fuzj &> /dev/null
/etc/init.d/sshd restart &> /dev/null && action "ssh is config ok ,please used fuzj login "
}
#下载必备常用软件
function software() {
yum install lrzsz wget elinks -y &>/dev/null
[ $? -eq 0 ] && action "lrzsz wget elinks install" /bin/true || action "lrzsz wget elinks install" /bin/false
}
#下面开始执行综上的函数
echo "============================ hostname config =========================="
hostname
sleep 1
echo "============================ yum config ==============================="
yum-source
sleep 2
echo "=========================== selinux config ============================"
selinux
sleep 2
echo "========================== iptables config ============================="
iptables
sleep 2
echo "========================== service config =============================="
service
sleep 2
echo "========================== language config ============================="
language
sleep 2
echo "========================== kernal config ==============================="
kernal
sleep 2
echo "========================== date update config =========================="
ntp
sleep 2
echo "========================== ssh config =========================="
ssh
sleep 2
echo "========================== software config ============================="
software
sleep 2
jishi(){
tput sc
count=11
while true;
do
if [ $count -gt 0 ];then
let count--;
sleep 1;
tput rc
tput ed
echo -n -e "\033[;36m ....$count \033[0m"
else
reboot;
fi
done
}
echo -e "\033[;31m system config is ok, it need to reboot \033[0m"
echo -e "\033[;34m Press enter to continue reboot!\033[0m"
read -t 5 -p "" a
jishi
转载于:https://blog.51cto.com/studys/1598651
linux系统初始化脚本相关推荐
- s5.CentOS、Ubuntu、Rocky Linux系统初始化脚本
CentOS.Ubuntu.Rocky Linux系统初始化脚本 Shell脚本源码地址 Gitee:https://gitee.com/raymond9/shell Github:https://g ...
- linux 账户初始化脚本,linux 系统初始化脚本
服务器初始化脚本,可以参考一下. #!/bin/env bash exportPATH=$PATH:/bin:/sbin:/usr/sbin # Require root to run thisscr ...
- linux系统日常脚本sh
一.系统初始化脚本(init.sh) #!/bin/bash#操作系统安装 #执行方法: ./init.sh 主机名os_hostname=$1 if [ ! -d /alidata ] then m ...
- Linux系统shell脚本之打印系统的IP信息
Linux系统shell脚本基础之打印系统的IP信息 一.脚本要求 二.脚本内容 三.执行脚本 一.脚本要求 1.显示服务器的运行状态,并输出提示 2.输出电脑的IP地址等信息 3.将执行输出的信息记 ...
- Linux系统shell脚本之批量修改服务器密码
Linux系统shell脚本之批量修改服务器密码 一.脚本要求 二.脚本内容 三.编辑原始旧密码 四.执行脚本 五.验证密码更改 1.查看更改后的密码文件 2.在远端服务器验证密码 一.脚本要求 可以 ...
- Linux系统shell脚本之函数的使用
Linux系统shell脚本之函数的使用 一.函数解释 二.函数参数 1.参数注意事项 2.特殊参数说明 三.函数实例1 四.函数实例2 一.函数解释 1.函数(function)作用:函数可以在sh ...
- Linux系统Shell脚本中的echo命令
Linux系统Shell脚本中的echo命令 echo的作用 输出字符串 格式 echo "字符串内容" 一,显示转义字符 转义字符 ...
- Linux系统shell脚本实战之解决生产ddos攻击
Linux系统shell脚本实战之解决生产ddos攻击 一.脚本于鏊求 二.脚本内容 三.执行脚本 一.脚本于鏊求 要求屏蔽掉ddos攻击的IP 二.脚本内容 [root@192 scripts]# ...
- LINUX系统初始化
说明BIOS是位于位于主板flash rom(掉电不丢失0)中的程序,操作系统Boot Loader位于硬盘MBR中.BIOS在完成 硬件检测和资源分配后.将硬盘MBR中的Boot Loader读到 ...
最新文章
- 深度学习 | 反卷积/转置卷积 的理解 transposed conv/deconv
- 线性一致性与全序广播------《Designing Data-Intensive Applications》读书笔记12
- docker for windows could not read CA certificate【转】
- Linux C: 定时器及时钟服务
- discuz!5.5.0安装方法及常见问题解决
- (STL,vector)木块问题
- java使用poi实现大数据量导出为EXCEL
- LDA的Gibbs抽样详细推理与理解
- 第二章:React 面向组件编程
- java求正整数和_求连续正整数的和-Java
- Java Web应用程序开发-深入体验Java Web开发内幕之初步
- 安全架构--14--企业安全管理体系建设总结
- css苹果手机字号变大,css – 智能手机字体大小不一致
- Web 服务器性能与站点访问性能的优化思路
- revit二次开发之程序调试
- 机器学习数据集(持续更新)
- html页面实现打印预览功能,js实现打印、页面设置、打印预览功能
- git for windows下载
- margin带一个、二个、三个、四个参数不同的含义。
- Revit二次开发,新手接入IExternalCommand、IExternalApplication,如何使用它们!
热门文章
- python锁机制_Python并发编程之谈谈线程中的“锁机制”(三)
- php urledcode_php慎用urldecode函数
- winform界面嵌入dwg图纸_完美解决窗体中预览DWG图形(C#版)
- android sharedpreference 清空,Android 从SharedPreferences中存储,检索,删除和清除数据...
- 怎么提前体验鸿蒙,鸿蒙OS手机版明天发布,开发者提前体验,上手操作毫无难度...
- oracle 多表查询_【Oracle】多表查询
- matlab 指定路径保存图片_关于matlab图片保存方式
- miniconda安装BWA 以及miniconda的环境配置
- 实现挖掘大数据价值的三大因素
- python selenium自动化框架_一文讲透!实现一个Python+Selenium的自动化测试框架如此简单!...