web优化

 

先对脚本的内容做一下说明:
1.     对系统进行判断,如果是 Cent OS 64位,继续运行。
2.     设置为每天凌晨四点进行时间同步(跟国家授时中心的服务器进行时间同步)注释:已调 .
3.     禁用 atime 日志记录特性。
4.     将系统同时打开的文件个数增大
5.     ctrl ALT delete键进行屏蔽,防止误操作的时候服务器重启
6.     关闭 SELinux
7.     禁用 GSSAPI来认证,也禁用DNS反向解析,加快SSH登陆速度
8.    优化一些内核参数
9.    调整删除字符的按键为 backspace(某些系统默认是delete)
10.    打开 vim的语法高亮
11.    取消生成 whatis数据库和locate数据库
12.    关闭没用的服务
13.    关闭 IPv6
 
 
下面是 sh脚本文件详细内容.
 
 
 
#!/bin/bash
#check the OS
platform=`uname -i`
if [ $platform != "x86_64" ];then
echo "this script is only for 64bit Operating System !"
exit 1
fi
echo "the platform is ok"
version=`lsb_release -r |awk '{print substr($2,1,1)}'`
if [ $version != 6 ];then
echo "this script is only for CentOS 6 !"
exit 1
fi
cat << EOF
+---------------------------------------------+
|    Winenice system is CentOS 6 x86_64 |
|       start optimizing........               |
+---------------------------------------------+
EOF
 
yum -y install ntp
echo "* 4 * * * /usr/sbin/ntpdate 203.117.180.36 > /dev/null 2>&1" >> /var/spool/cron/root                                     
service crond restart                                       设置为每天凌晨四点进行时间同步(跟国家授时中心的服务器进行时间同步 .)
 
#set the file limit
echo "ulimit -SHn 102400" >> /etc/rc.local                                                                                                               指定最大打开文件数 .
cat >> /etc/security/limits.conf << EOF                                              
*            soft   nofile       65536
*            hard   nofile       65536
EOF
 
 
#set the control-alt-delete to guard against the misuse
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf                    禁用 control-alt-delete,防止误操作.
 
#disable selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config                                                                        禁用 SELINUX
 
#set ssh
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config                      禁用 GSSAPI来认证,也禁用DNS反向解析,加快SSH登陆速度.
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
service sshd restart
 
 磁盘在我们 LEMP平台架构中扮演着重要的角色。静态文件、模板和代码都来自磁盘,因为磁盘访问的延迟相当高。因此,花一些时间对磁盘硬件进行优化是有意义的。禁用 atime 日志记录特性。atime 是最近访问文件的时间,每当访问文件时,底层文件系统必须记录这个时间戳。现在我们很少使用 atime,禁用它可以减少磁盘访问时间。
 
 
 
#tune kernel parametres                                                                  优化内核,需重启!
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200                                                                                                    ----------------长连接会话保持,与 DBA沟通.
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
EOF
/sbin/sysctl -p                                                                                                                                                       IP碎片去除,从指定的文件加载系统参数 .
 
#define the backspace button can erase the last character typed
echo 'stty erase ^H' >> /etc/profile                                                                                                                      退格键设定为 backspace
 
echo "syntax on" >> /root/.vimrc                                                                                                                          开启 vim色彩.
 
#stop some crontab      whatismlocate都是查询whatis数据库的工具,对于WEB服务器作用不大.
mkdir /etc/cron.daily.bak
mv /etc/cron.daily/makewhatis.cron /etc/cron.daily.bak
mv /etc/cron.daily/mlocate.cron /etc/cron.daily.bak
 
chkconfig bluetooth off                                                                                                                                        蓝牙功能,无用,可关闭 .
chkconfig cups off                                                                                                                                                打印功能,无用,可关闭 .
chkconfig ip6tables off                                                                                                                                          IPV6 可关闭 .                                  
 
 
#disable the ipv6
cat > /etc/modprobe.d/ipv6.conf << EOFI
alias net-pf-10 off
options ipv6 disable=1
EOFI
 
echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
cat << EOF
+-------------------------------------------------+
|    Winenice Web Server Optimization end!      |
|                    Please restart!                             |
+-------------------------------------------------+
EOF

你可能感兴趣的:(服务器,中心,日志记录,国家,的)