时间:2016-02-26 17:41 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的电脑教程是服务器系列之:【Linux知识点小结】,下面是详细的分享!
Linux知识点小结
#!/bin/bash
flagFile="/root/centos6-init.executed"
precheck(){
if [[ "$(whoami)" !="root" ]]; then
echo "please run this script as root ." >&2
exit 1
fi
if [ -f "$flagFile" ]; then
echo "this script had been executed, please do not execute again!!" >&2
exit 1
fi
echo -e "\033[31m WARNING! THIS SCRIPT WILL \033[0m\n"
echo -e "\033[31m *1 update the system; \033[0m\n"
echo -e "\033[31m *2 setup security permissions; \033[0m\n"
echo -e "\033[31m *3 stop irrelevant services; \033[0m\n"
echo -e "\033[31m *4 reconfig kernel parameters; \033[0m\n"
echo -e "\033[31m *5 setup timezone and sync time periodically; \033[0m\n"
echo -e "\033[31m *6 setup tcp_wrapper and netfilter firewall; \033[0m\n"
echo -e "\033[31m *7 setup vsftpd; \033[0m\n"
sleep 5
}
yum_update(){
yum -y update
#update system at 5:40pm daily
echo "40 3 * * * root yum -y update && yum clean packages" >> /etc/crontab
}
permission_config(){
#chattr +i /etc/shadow
#chattr +i /etc/passwd
}
selinux(){
sed -i 's/SELINUX=disabled/SELINUX=enforcing/g' /etc/sysconfig/selinux
setenforce 1
}
stop_services(){
for server in `chkconfig --list |grep 3:on|awk '{print $1}'`
do
chkconfig --level 3 $server off
done
for server in crond network rsyslog sshd iptables
do
chkconfig --level 3 $server on
done
}
limits_config(){
cat >> /etc/security/limits.conf <> /etc/rc.local
}
sysctl_config(){
sed -i 's/net.ipv4.tcp_syncookies.*$/net.ipv4.tcp_syncookies=1/g' /etc/sysctl.conf
sed -i 's/net.ipv4.ip_forward.*$/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
cat >> /etc/sysctl.conf <> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
fi
#sed -i '/^#Port/s/#Port 22/Port 65535/g' /etc/ssh/sshd_config
sed -i '/^#UseDNS/s/#UseDNS no/UseDNS yes/g' /etc/ssh/sshd_config
#sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
sed -i 's/#PermitEmptyPasswords yes/PermitEmptyPasswords no/g' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
/etc/init.d/sshd restart
}
time_config(){
#timezone
echo "TZ='Asia/Shanghai'; export TZ" >> /etc/profile
# Update time
if [! -f "/usr/sbin/ntpdate"]; then
yum -y install ntpdate
fi
/usr/sbin/ntpdate pool.ntp.org
echo "30 3 * * * root (/usr/sbin/ntpdate pool.ntp.org && /sbin/hwclock -w) &> /dev/null" >> /etc/crontab
/sbin/service crond restart
}
iptables(){
cat > /etc/sysconfig/iptables << EOF
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:syn-flood - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT
-A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn-flood
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN
-A syn-flood -j REJECT --reject-with icmp-port-unreachable
COMMIT
EOF
/sbin/service iptables restart
source /etc/profile
}
other(){
# initdefault
sed -i 's/^id:.*$/id:3:initdefault:/' /etc/inittab
/sbin/init q
# PS1
#echo 'PS1="\[\e[32m\][\[\e[35m\]\u\[\e[m\]@\[\e[36m\]\h \[\e[31m\]\w\[\e[32m\]]\[\e[36m\]$\[\e[m\]"' >> /etc/profile
# Wrong password five times locked 180s
sed -i '4a auth required pam_tally2.so deny=5 unlock_time=180' /etc/pam.d/system-auth
}
vsftpd_setup(){
yum -y install vsftpd
mv /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
touch /etc/vsftpd/chroot_list
setsebool -P ftp_home_dir=1
cat >> /etc/vsftpd/vsftpd.conf <
以上就是关于Linux知识点小结的服务器维护教程分享,更多电脑教程请移步到>>电脑教程频道。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
