服务器

位置:IT落伍者 >> 服务器 >> 浏览文章

服务器优化——Sysctl、Apache、MySQL


发布日期:2021年02月21日
 
服务器优化——Sysctl、Apache、MySQL

服务器的负载能力很大程度上取决于系统管理员的配置和优化能力相同的硬件不同的软件配置会造成截然不同的效果下面我将给大家介绍一下如何优化 sysctrl Apache 以及 MySQL 请注意所有配置均为取决于个人请根据自己的实际情况做调整

配置Sysctl

编辑此文件

nano w /etc/nf

如果该文件为空则输入以下内容否则请根据情况自己做调整

# Controls source route verification

# Default should work for all interfaces

nfdefaultrp_filter =

# nfallrp_filter =

# nflorp_filter =

# nfethrp_filter =

# Disables IP source routing

# Default should work for all interfaces

nfdefaultaccept_source_route =

# nfallaccept_source_route =

# nfloaccept_source_route =

# nfethaccept_source_route =

# Controls the System Request debugging functionality of the kernel

kernelsysrq =

# Controls whether core dumps will append the PID to the core filename

# Useful for debugging multithreaded applications

re_uses_pid =

# Increase maximum amount of memory allocated to shm

# Only uncomment if needed!

# kernelshmmax =

# Disable ICMP Redirect Acceptance

# Default should work for all interfaces

nfdefaultaccept_redirects =

# nfallaccept_redirects =

# nfloaccept_redirects =

# nfethaccept_redirects =

# Enable Log Spoofed Packets Source Routed Packets Redirect Packets

# Default should work for all interfaces

nfdefaultlog_martians =

# nfalllog_martians =

# nflolog_martians =

# nfethlog_martians =

# Decrease the time default value for tcp_fin_timeout connection

netipvtcp_fin_timeout =

# Decrease the time default value for tcp_keepalive_time connection

netipvtcp_keepalive_time =

# Turn on the tcp_window_scaling

netipvtcp_window_scaling =

# Turn on the tcp_sack

netipvtcp_sack =

# tcp_fack should be on because of sack

netipvtcp_fack =

# Turn on the tcp_timestamps

netipvtcp_timestamps =

# Enable TCP SYN Cookie Protection

netipvtcp_syncookies =

# Enable ignoring broadcasts request

netipvicmp_echo_ignore_broadcasts =

# Enable bad error message Protection

netipvicmp_ignore_bogus_error_responses =

# Make more local ports available

# netipvip_local_port_range =

# Set TCP ReOrdering value in kernel to

netipvtcp_reordering =

# Lower syn retry rates

netipvtcp_synack_retries =

netipvtcp_syn_retries =

# Set Max SYN Backlog to

netipvtcp_max_syn_backlog =

# Various Settings

dev_max_backlog =

# Increase the maximum number of skbheads to be cached

rehot_list_length =

# Increase the tcptimewait buckets pool size

netipvtcp_max_tw_buckets =

# This will increase the amount of memory available for socket input/output queues

rermem_default =

rermem_max =

netipvtcp_rmem =

rewmem_default =

rewmem_max =

netipvtcp_wmem =

netipvtcp_mem =

reoptmem_max =

如果希望屏蔽别人 ping 你的主机则加入以下代码

# Disable ping requests

netipvicmp_echo_ignore_all =

编辑完成后请执行以下命令使变动立即生效

/sbin/sysctl p

/sbin/sysctl w netipvrouteflush=

MySQL优化

编辑MySQL的配置文件

nano /etc/f

输入以下内容

[mysqld]

connect_timeout=

interactive_timeout=

join_buffer_size=M

key_buffer=M

max_allowed_packet=M

max_connections=

max_connect_errors=

myisam_sort_buffer_size=M

read_buffer_size=M

read_rnd_buffer_size=K

sort_buffer_size=M

table_cache=

thread_cache_size=

thread_concurrency=

wait_timeout=

query_cache_size=M

query_cache_limit=M

query_cache_type=

skipinnodb

请注意以上配置适用于M~M内存如内存更大的话请自行做调整给项目增加内存会加快速度但是使用过多的内存而导致启用swap的话会极大的导致系统效率下降其中 thread_concurrency 这项配置单CPU的话请设置为双CPU的话请设置为

Apache优化

以下优化适用于 Apache 系列如果你用的是 系列的话请自行做调整和判断

确认 Apache 的配置文件位置并开始编辑

locate  

nano w /path/to/

的文件有许多内容笔者就拿出需要做优化的

KeepAlive On

MaxKeepAliveRequests

KeepAliveTimeout

MinSpareServers

MaxSpareServers

MaxRequestsPerChild

将 KeepAliveTimeout 设定到较小的数字将有助于减少服务器上的无用等待链接一定程度上能增加服务器负载

另外下面这条不算优化但是是Apache安全相关

ServerSignature Off

ServerTokens ProductOnly

将 ServerSignature 关闭并增加 ServerTokens ProductOnly 可以使常人无法检测到Apache的实际版本号有助于Apache的安全

以上所做的这些优化在某种程度上会增强服务器的负载性能但请注意最佳的配置是实践出来的               

上一篇:RedHat6.2服务器配置方案大全(十二):MySQL

下一篇:MSSQL数据库占用内存过大造成服务器死机问题的解决方法