#!/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.repo

cd /tmp


##########--- remove excess service  --######

for server in `chkconfig --list |grep 3:on|awk '{ print $1}'`

 do

     chkconfig --level 3 $server off

 done

for server in crond network syslog sshd

 do

    chkconfig --level 3 $server on

done


#########---  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/clock

cat >>/etc/sysconfig/clock <<EOF

ZONE="Asia/Hong_Kong"

UTC=false

ARC=false

EOF


##########---  Add uer and Diretory ---##########

user=`grep wentong /etc/shadow|wc -l`

[ $user -eq 0  ] && \

{

useradd wentong

echo "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 stop

chkconfig iptables off

setenforce 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------

#大家如果觉得有什么不正确或者你有更好的,希望能够让我学习学习。