刚学习时自己写的一个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
##########--- 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
相关文章推荐
- 手动安装Intel network I217-LM网卡的Linux驱动
- 解析linux系统根目录结构
- Linux中使用ln命令在文件之间建立连接的用法讲解
- linux文件系统简介(转载)
- Linux系统中quota磁盘命令的相关使用解析
- CentOS SSH连接慢的解决办法
- Linux系统中开起和关闭用户的磁盘空间限制的命令
- 详解Linux系统中at与atq命令的用法
- linux命令crontab
- Kali Linux中前十名的Wifi攻击工具
- Centos6笔记 -- 数据流重导向(Redirection)
- linux进程管理
- centos 开放端口
- linux (redhat) 通过系统镜像安装桌面及开发库
- Linux中的EAGAIN含义
- 【转】Centos 建立一个新用户 详细讲解
- CentOS6.5下搭建NFS文件服务器
- 记录一些linux命令
- 类成员函数作为pthread_create函数参数
- linux同时创建多进程的方法