
复制#优化History历史记录 vi /etc/bashrc #设置保存历史命令的手动署实文件大小 export HISTFILESIZE=1000000000 #保存历史命令条数 export HISTSIZE=1000000 #实时记录历史命令,默认只有在用户退出之后才会统一记录,编译很容易造成多个用户间的安装相互覆盖。 export PROMPT_COMMAND="history -a" #记录每条历史命令的及全践附执行时间 export HISTTIMEFORMAT="%Y-%m-%d_%H:%M:%S " #设置时区(可选) rm -rf /etc/localtime ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #禁用NetworkManager(可选) /etc/init.d/NetworkManager stop chkconfig NetworkManager off /etc/init.d/network restart #关闭iptables(可选) /etc/init.d/iptables stop chkconfig iptables off #设置dns(可选) echo "nameserver 114.114.114.114" > /etc/resolv.conf #关闭maildrop #cd /var/spool/postfix/maildrop;ls | xargs rm -rf; sed s/MAILTO=root/MAILTO=""/g /etc/crontab service crond restart #关闭selinux setenforce 0 sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config #文件打开数量, echo ulimit -SHn 65535 >> /etc/profile source /etc/profile #修改最大进程和最大文件打开数限制 vi /etc/security/limits.conf * soft nproc 11000 * hard nproc 11000 * soft nofile 655350 * hard nofile 655350 sed -i -e /# End of file/i\* soft nofile 65535\n* hard nofile 65535 /etc/security/limits.conf #优化TCP vi /etc/sysctl.conf net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 #开启SYN Cookies,自动当出现SYN等待队列溢出时,化部启用cookies来处理 net.ipv4.tcp_syncookies = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 #timewait的详细数量,默认是代码180000 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.tcp_sack = 1 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_rmem = 4096 87380 4194304 net.ipv4.tcp_wmem = 4096 16384 4194304 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 #每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的手动署实数据包的最大数目 net.core.netdev_max_backlog = 262144 #web应用中listen函数的backlog默认会给我们内核参数的net.core.somaxconn限制到128,而nginx定义的编译NGX_LISTEN_BACKLOG默认为511,所以有必要调整这个值 net.core.somaxconn = 262144 #系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上。安装如果超过这个数字,及全践附孤儿连接将即刻被复位并打印出警告信息。自动这个限制仅仅是化部为了防止简单的DoS攻击,不能过分依靠它或者人为地减小这个值,详细更应该增加这个值(如果增加了内存之后) net.ipv4.tcp_max_orphans = 3276800 #记录的那些尚未收到客户端确认信息的连接请求的最大值。对于有128M内存的云服务器提供商系统而言,缺省值是1024,小内存的系统则是128 net.ipv4.tcp_max_syn_backlog = 262144 #时间戳可以避免序列号的卷绕。一个1Gbps的链路肯定会遇到以前用过的序列号。时间戳能够让内核接受这种“异常”的数据包。这里需要将其关掉 net.ipv4.tcp_timestamps = 0 #为了打开对端的连接,内核需要发送一个SYN并附带一个回应前面一个SYN的ACK。也就是所谓三次握手中的第二次握手。这个设置决定了内核放弃连接之前发送SYN+ACK包的数量 net.ipv4.tcp_synack_retries = 1 #在内核放弃建立连接之前发送SYN包的数量 net.ipv4.tcp_syn_retries = 1 #启用timewait快速回收 net.ipv4.tcp_tw_recycle = 1 #开启重用,允许将TIME-WAIT sockets重新用于新的TCP连接 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 #如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间。对端可以出错并永远不关闭连接,甚至意外当机。缺省值是60 秒。2.2 内核的通常值是180秒,企商汇你可以按这个设置,但要记住的是,即使你的机器是一个轻载的WEB服务器,也有因为大量的死套接字而内存溢出的风险,FIN- WAIT-2的危险性比FIN-WAIT-1要小,因为它最多只能吃掉1.5K内存,但是它们的生存期长些。 net.ipv4.tcp_fin_timeout = 1 #当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时。 net.ipv4.tcp_keepalive_time = 30 #允许系统打开的端口范围 net.ipv4.ip_local_port_range = 1024 65000 #表示文件句柄的最大数量 fs.file-max = 102400 #云主机上的优化 # Kernel sysctl configuration file for Red Hat Linux # # Forbinaryvalues, 0 is disabled, 1 is enabled. See sysctl(8) and # sysctl.conf(5) for more details. # Controls IP packet forwarding net.ipv4.ip_forward = 0 # Controls source route verification net.ipv4.conf.default.rp_filter = 1 # Do not accept source routing net.ipv4.conf.default.accept_source_route = 0 # Controls the System Request debugging functionality of the kernel # Controls whether core dumps will append the PID to the core filename. # Useful for debugging multi-threaded applications. kernel.core_uses_pid = 1 # Controls the use of TCP syncookies net.ipv4.tcp_syncookies = 1 # Disable netfilter on bridges. net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0 # Controls the default maxmimum sizeof a mesage queue kernel.msgmnb = 65536 # Controls the maximum sizeof a message, in bytes kernel.msgmax = 65536 # Controls the maximum shared segment size, in bytes kernel.shmmax = 68719476736 # Controls the maximum number of shared memory segments, in pages kernel.shmall = 4294967296 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.all.secure_redirects = 0 net.ipv4.conf.default.secure_redirects = 0 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.all.secure_redirects = 0 net.ipv4.conf.default.secure_redirects = 0 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.netfilter.nf_conntrack_max = 1000000 kernel.unknown_nmi_panic = 0 kernel.sysrq = 0 fs.file-max = 1000000 vm.swappiness = 10 fs.inotify.max_user_watches = 10000000 net.core.wmem_max = 327679 net.core.rmem_max = 327679 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 net.ipv4.conf.all.secure_redirects = 0 net.ipv4.conf.default.secure_redirects = 0 net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 /sbin/sysctl -p #自动选择最快的yum源 yum -y install yum-fastestmirror #移除系统自带的rpm包的http mysql php #yum remove httpd* php* yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd -y #升级基础库 yum install -y wget gcc gcc-c++ openssl* curl curl-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel gd gd2 gd-devel gd2-devel libaio autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel #yum安装基础必备环境包,可以先将yum源更换为阿里云的源 阿里:http://mirrors.aliyun.com/ 搜狐:http://mirrors.sohu.com/ 网易:http://mirrors.163.com/ #备份原先的yum源信息 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup #从阿里云镜像站下载centos6的b2b信息网repo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo #最后yum重新生成缓存 yum makecache #yum安装软件包(可选) yum -y install tar zip unzip openssl* gd gd-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers make libmcrypt libmcrypt-devel fontconfig fontconfig-devel libXpm* libtool* libxml2 libxml2-devel t1lib t1lib-devel #定义目录结构,下载安装包 mkdir -p /app/{local,data} cd /app/local #PCRE - Perl Compatible Regular Expressions wget "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz" #Tengine wget "http://tengine.taobao.org/download/tengine-2.1.0.tar.gz" #MySQL wget "https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz" #PHP wget "http://cn2.php.net/distributions/php-5.6.11.tar.gz" #Mhash wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz" #libmcrypt wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz" #Mcrypt wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz" 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.109.110.111.112.113.114.115.116.117.118.119.120.121.122.123.124.125.126.127.128.129.130.131.132.133.134.135.136.137.138.139.140.141.142.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.158.159.160.161.162.163.164.165.166.167.168.169.170.171.172.173.174.175.176.177.178.179.180.181.182.183.184.185.186.187.188.189.190.191.192.193.194.195.196.197.198.199.200.201.202.203.204.205.206.207.208.209.210.211.212.213.214.215.216.217.218.219.220.