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

Linux 系统初始化脚本

2011-12-09 16:03 393 查看
Linux 系统初始化脚本

适用于批量部署linux 操作系统!

#update 20130305

cat sys-init.sh

#!/bin/bash
#linux system initialization
#update 20130305 by dongnan
#
#关闭不需要的服务
chkconfig atd off
chkconfig cups off
chkconfig bluetooth off
chkconfig hidd off
chkconfig ip6tables off
chkconfig auditd off
chkconfig autofs off
chkconfig avahi-daemon off
chkconfig avahi-dnsconfd off
chkconfig cpuspeed off
chkconfig isdn off
chkconfig nscd off
chkconfig pcscd off
chkconfig yum-updatesd off
chkconfig acpid off
chkconfig autofs off
chkconfig firstboot off
chkconfig mcstrans off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig setroubleshoot off
chkconfig xfs off
chkconfig xinetd off
chkconfig messagebus off
chkconfig gpm off
chkconfig restorecond off
chkconfig haldaemon off
chkconfig sysstat off
chkconfig readahead_early off
chkconfig anacron off
chkconfig iscsid off
chkconfig iscsi off
chkconfig lm_sensors  off
chkconfig mdmonitor  off
chkconfig ntpd off
chkconfig smb off
chkconfig rawdevices off
chkconfig iptables off
chkconfig netfs off
chkconfig nfs off
chkconfig nfslock off
chkconfig portmap off
chkconfig hplip off
chkconfig nfs off
chkconfig nfslock off
chkconfig portmap off

#打开需要的服务
chkconfig crond on
chkconfig irqbalance on
chkconfig kudzu on
chkconfig microcode_ctl on
chkconfig messagebus on
chkconfig network on
chkconfig sshd on
chkconfig syslog on
chkconfig --list | grep '3:on'

#关闭selinux
sed -ir 's/SELINUX=.*/SELINUX=disabled/g'  /etc/selinux/config

#设定最大文件句柄数量
echo -e '* soft nofile 65536
* hard nofile 65536'  >> /etc/security/limits.conf

#同步时间
echo -e "#ntpdate \n/usr/sbin/ntpdate time-nw.nist.gov" >> /etc/rc.local

#tcp/ip 优化
echo -en '#begin
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.ip_local_port_range = 10240 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_synack_retries = 3
net.ipv4.tcp_syncookies = 1\n' >> /etc/sysctl.conf
sysctl -p

#.vimrc 文件
cat >  ~/.vimrc << EOF
set nobackup
set number
set cindent
set autoindent
set shiftwidth=2
set tabstop=2
set softtabstop=2
set expandtab
set ruler
syntax on
EOF

#.bash_profile
echo -en '# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
HISTTIMEFORMAT="$(whoami) [%Y-%m-%d %H:%M:%S] " && export HISTTIMEFORMAT

#after add
ip=`/sbin/ifconfig eth0 | grep Bcast | sed -e "s/^.* addr:\\(.*\\) Bcast.*$/\1/"` || ip=`/sbin/ifconfig eth1 | grep Bcast | sed -e "s/^.* addr:\\(.*\\) Bcast.*$/\1/"`
PS1="\[\e[32;1m\]$ip\[\e[0m\][\W]\$ " && export PS1

#export HISTIGNORE="&:history:ls:ls *:ps:ps -A:df:df *:du:du *:[bf]g:exit"
#unset USERNAME
echo "[LOAD]";cat /proc/loadavg;echo "[DISK]";df -Th

locale | sed -r 's/zh_CN/en_US/g' > .lang
source ~/.lang \n' > ~/.bash_profile


结束

更多请:

linux 系统运维 37275208

vmware 虚拟化 166682360
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 初始化 脚本 shell