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

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值