您的位置:首页 > 运维架构 > Linux

刚学习时自己写的一个linux系统初始化脚本

2016-01-14 12:12 627 查看
#!/bin/bash
##########--- updata yum ku ----######cd /etc/yum.repos.d//usr/bin/wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo/bin/mv CentOS-Base.repo CentOS-Base-Old.repo/bin/mv CentOS-Base-sohu.repo CentOS-Base.repocd /tmp
##########--- remove excess service --######for server in `chkconfig --list |grep 3:on|awk '{ print $1}'` do chkconfig --level 3 $server off donefor server in crond network syslog sshd do chkconfig --level 3 $server ondone
#########--- update the system time -----#######/usr/sbin/ntpdate time.windows.com/bin/echo "*/5 * * * * /usr/sbin/ntpdate time.windows.com 1> /dev/null 2>&1" >> /var/spool/cron/root
>/etc/sysconfig/clockcat >>/etc/sysconfig/clock <<EOFZONE="Asia/Hong_Kong"UTC=falseARC=falseEOF
##########--- Add uer and Diretory ---##########user=`grep wentong /etc/shadow|wc -l`[ $user -eq 0 ] && \{useradd wentongecho "chaoren" | passwd --stdin wentong}[ ! -d /root/tools ] && /bin/mkdir -p /root/tools/[ ! -d /root/history ] && /bin/mkdir -p /root/history[ ! -d /backup ] && /bin/mkdir -p /backup[ ! -d /root/shell ] && /bin/mkdir -p /root/shell#自己的目录结构规范:工具放于/root/tools 脚本放于/root/shell下 备份数据放于/backup#一些历史数据放于/root/history下
#########---close the firewall and SELinux---#####/etc/init.d/iptables stopchkconfig iptables offsetenforce 0/bin/echo "setenforce 0" >>/etc/rc.local/bin/sed -i 's#SELINUX=enforce#SELINUX=disable#g' /etc/selinux/config
##########---- permit root ssh login--- ########### /bin/cat >> /etc/ssh/sshd_conf << EOF
###----ATong-deny root ssh login --####Port 52022#PermitRootLogin no#PermitEmptyPasswords no#UseDNS no#EOF
#/bin/cat >> /etc/sudoers << EOF#wentong ALL=(ALL) ALL#EOF
##########---- Update system lange ---####/bin/echo "* - nofile 65535">>/etc/security/limits.conf/bin/echo " LANG=zh_CN.GB18030" >/etc/i18n

######---- Opimizing the kernel ----######应该要再添加进入一些系统内核优化的命令,[待更新...]
######----- yum install some tolls --- ###/usr/bin/yum -y install lrzsz vsftpd libtool-ltdl libtool-ltdl-devel sysstat >/dev/null 2>&1
#PS:目前脚本太过长了,由于刚学习能力有限,可能做了一些无用功,有些地方还需要加些判断。#比如判断cron中是否已经有向网络时间服务器去同步时间点命令了。#此脚本中有创建用户密码的命令,需要设置权限为rwx------#大家如果觉得有什么不正确或者你有更好的,希望能够让我学习学习。

本文出自 “从头开始” 博客,请务必保留此出处http://atong.blog.51cto.com/2393905/1342152
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息