#!/bin/bash
yum groupinstall -y
"development tools"
[ ! -d
/server/tools
] &&
mkdir
-p
/server/tools
[ ! -d
/application
] &&
mkdir
-p
/application
[ ! -d
/data
] &&
mkdir
-p
/data
[ ! -d
/app/logs
] &&
mkdir
-p
/app/logs
[ ! -d
/server/backup
] &&
mkdir
-p
/server/backup
[ ! -d
/delete
] &&
mkdir
-p
/delete
echo
"############### auto update time ###############"
>>
/var/spool/cron/root
echo
"00 01 * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1"
>>
/var/spool/cron/root
[ `
grep
ntpdate
/var/spool/cron/root
|
wc
-l` -
ne
0 ] && action
"uptime set"
/bin/true
|| action
"uptime set"
/bin/false
wget -P
/etc/yum
.repos.d/ http:
//mirrors
.163.com/.help
/CentOS6-Base-163
.repo
/bin/mv
/etc/yum
.repos.d
/CentOS-Base
.repo
/etc/yum
.repos.d
/CentOS-Base
.repo.bak
/bin/cp
/etc/yum
.repos.d
/CentOS6-Base-163
.repo
/etc/yum
.repos.d
/CentOS-Base
.repo
[ `
grep
163.com
/etc/yum
.repos.d
/CentOS-Base
.repo |
wc
-l` -
ne
0 ] && action
"yum set"
/bin/true
|| action
"yum set"
/bin/false
/bin/cp
/etc/selinux/config
/etc/selinux/config
.bak
sed
-i
's/SELINUX=enforcing/SELINUX=disabled/'
/etc/selinux/config
2>&1
/etc/init
.d
/iptables
stop >
/dev/null
chkconfig iptables off >
/dev/null
[ `chkconfig --list |
grep
iptables|
grep
3:on|
wc
-l` -
eq
0 -a `
grep
"SELINUX=enforcing"
/etc/selinux/config
|
wc
-l` -
eq
0 ] && action
"iptables and selinux close"
/bin/true
|| action
"iptables and selinux close"
/bin/false
/bin/cp
/etc/security/limits
.conf
/etc/security/limits
.conf.bak
echo
'* - nofile 65535'
>>
/etc/security/limits
.conf
[ `
tail
-1
/etc/security/limits
.conf|
grep
65535|
wc
-l` -
eq
1 ] && action
"limit set"
/bin/true
|| action
"limit set"
/bin/false
/bin/cp
/etc/sysconfig/i18n
/etc/sysconfig/i18n
.bak
echo
'LANG="en_US.UTF-8"'
>
/etc/sysconfig/i18n
[ ! -d
/server/scripts
] &&
mkdir
-p
/server/scripts
if
[ `rpm -qa sendmail |
wc
-l` -
ne
0 ];
then
echo
>
/server/scripts/del
.sh<<EOF
#!/bin/bash
find
/var/spool/clientmqueue/
-
type
f|
xargs
rm
-f >
/dev/null
2>&1
EOF
echo
'################ clean /var/spool/clientmqueue/ ################'
>>
/var/spool/cron/root
echo
'00 00 * * 1 /bin/sh /server/scripts/del.sh >/dev/null 2>&1'
>>
/var/spool/cron/root
[
"$?"
-
eq
0 ] && action
"clean /var/spool/clientmqueue/ set"
/bin/true
|| action
"clean /var/spool/clientmqueue/ set"
/bin/false
else
action
"service sendmail is not installed,do not need set"
/bin/false
fi
for
cgt
in
`chkconfig --list |
grep
3:on |
awk
'{print $1}'
`;
do
chkconfig --level 3 $cgt off;
done
for
cgt
in
{crond,sshd,network,rsyslog};
do
chkconfig --level 3 $cgt on;
done
flag=0
[ `chkconfig --list|
grep
3:on|
wc
-l` -
eq
4 ] && action
"auto_start services set"
/bin/true
|| action
"auto_start services set"
/bin/false
[ -f
/etc/sysctl
.conf.bak ] &&
/bin/cp
/etc/sysctl
.conf.bak
/etc/sysctl
.conf.bak.$(
date
+%F-%H%M%S) ||
/bin/cp
/etc/sysctl
.conf
/etc/sysctl
.conf.bak
cat
>>
/etc/sysctl
.conf <<EOF
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
EOF
sysctl -p >
/dev/null
2>&1
[ `
grep
"net.ipv4.tcp_max_orphans = 16384"
/etc/sysctl
.conf|
wc
-l` -
ne
0 ] && action
"kernel set"
/bin/true
|| action
"kernel set"
/bin/false
/bin/cp
/etc/ssh/sshd_config
/etc/ssh/sshd_config
.bak
sed
-i
's/\#PermitRootLogin yes/PermitRootLogin no/'
/etc/ssh/sshd_config
sed
-i
's/\#PermitEmptyPasswords no/PermitEmptyPasswords no/'
/etc/ssh/sshd_config
sed
-i
's/\#UseDNS yes/UseDNS no/'
/etc/ssh/sshd_config
[ `
grep
"PermitRootLogin no"
/etc/ssh/sshd_config
|
wc
-l` -
ne
0 -a `
grep
"PermitEmptyPasswords no"
/etc/ssh/sshd_config
|
wc
-l` -
ne
0 -a `
grep
"UseDNS no"
/etc/ssh/sshd_config
|
wc
-l` -
ne
0 ] &&action
"ssh set"
/bin/true
|| action
"ssh set"
/bin/false
chattr +ai
/etc/passwd
chattr +ai
/etc/shadow
chattr +ai
/etc/group
chattr +ai
/etc/gshadow
chattr +ai
/etc/inittab
/bin/cp
/etc/issue
/etc/issue
.bak
>
/etc/issue
[ `
cat
/etc/issue
|
wc
-l` -
eq
0 ] && action
"/etc/issue set"
/bin/true
|| action
"/etc/issue set"
/bin/false