1.Tomcat配置优化
a)catalina.sh
在/home/tomcat/bin/catalina.sh中加入
JAVA_OPTS="-server -Xms4096m -Xmx8192m -XX:MaxNewSize=1024m -XX:MaxPermSize=4096m -XX:PermSize=2048M -XX:+HeapDumpOnOutOfMemoryError -XX:-UseGCOverheadLimit -XX:HeapDumpPath=~"
b)server.xml
在/home/tomcat/conf/server.xml中加入红色字体的两个参数
<Connector port="8050" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxThreads="2000"
acceptCount="1500"
URIEncoding="UTF-8" useBodyEncodingForURI="true" />
2.Mysql配置优化:
c)先使用客户端备份所有数据,包括Portal、BO;
d)先优化备机,测试完成后再优化主机;
e)关闭相关应用;
f)先停止MySql服务;
g)备份/etc目录下my.cnf;
h)在/etc目录下修改my.cnf文件;
i)配置信息修改为;
innodb_buffer_pool_size = 1G //操作系统内存的70%-80%最佳
innodb_log_file_size=256M
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size = 2M
innodb_additional_mem_pool_size = 16M
max_connections = 1000
max_allowed_packet = 20M
j)打开/var/lib/mysql
删除ib_logfile0, ib_logfile1 ... ... ib_logfile(n) 等文件
k)重新启动MySql服务,完成优化。再次提醒记得备份。。
3.服务器配置参数优化:
l)检查当前连接数:
[root@localhost ~]# ulimit -n
1024
m)设置连接数(根据项目实际修改连接数个数):
[root@localhost ~]# vi /etc/security/limits.conf
配置文件中加入以下:
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
[root@localhost ~]# vi /etc/pam.d/login
配置文件中加入以下:
session required pam_limits.so
n)保存以上配置文件,不需要重启服务器,断开、重新链接ssh,再ulimit -n查询
[root@localhost ~]# ulimit -n
65535
o)优化服务器链接配置(不需要重启)
Nginx提供高并发的代理服务时,一般都需要进行系统内核网络参数优化,将/etc/sysctl.conf文件清空(注:可以把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
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
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
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.ip_conntrack_max = 6553500
然后执行systcl –p刷新设置。
注意一个问题
这个优化以后,可能会报错



解决办法:
前两个暂时注掉吧,使用下面命令优化一下:
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle;
echo 0 > /proc/sys/net/ipv4/tcp_timestamps;
第三个可以把配置文件改名,如下图

网友评论