熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> MySQL >> 正文

服務器優化——Sysctl、Apache、MySQL

2013-11-23 21:01:21  來源: 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的安全
  
  以上所做的這些優化在某種程度上會增強服務器的負載性能但請注意最佳的配置是實踐出來的
From:http://tw.wingwit.com/Article/program/MySQL/201311/29461.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.