UNIX伺服器搭建手冊標準版之伺服器優化手冊

UNIX伺服器搭建手冊標準版之伺服器優化手冊

 

提綱

  • UNIX內核優化…………………………………………………………………………………

 

  • UNIX系統優化………………………………………………………………………………..

 

  • APACHE優化…………………………………………………………………………………..

 

  • PHP優化………………………………………………………………………………………..

 

  • MYSQL優化……………………………………………………………………………………

 

  • FTP伺服器優化……………………………………………………………………………….

 

  • MAIL伺服器優化………………………………………………………………………………

 

  • DNS伺服器優化……………………………………………………………………………….

 

  • LOG日誌伺服器優化………………………………………………………………………….

 

  • SQUID緩存伺服器優化……………………………………………………………………….

 

  • CVS伺服器優化………………………………………………………………………….

  • UNIX內核優化

重新編譯內核

優化編譯環境
更新/etc/make.conf文件,做適當的編譯優化, 如果CPU是Intel的:

CPUTYPE=i686
CFLAGS= -O3 -pipe
COPTFLAGS= -O3 -pipe

 

編譯內核,加入以下參數

#disable ctrl+alt+delete
options SC_DISABLE_REBOOT

#quota limit
options QUOTA

優化內核參數

修改系統內核參數,實現微調:vi /etc/sysctl.conf

kern.ipc.somaxconn=8192
kern.ipc.maxsockbuf=2097152
kern.maxfilesperproc=32768
kern.maxfiles=65536
kern.securelevel=-1
net.inet.tcp.sendspace=65536
net.inet.tcp.recvspace=32768
net.inet.udp.maxdgram=57344
net.inet.icmp.drop_redirect=1
net.inet.icmp.log_redirect=0
net.inet.ip.redirect=0
net.inet6.ip6.redirect=0
net.inet.icmp.icmplim=100
net.inet.tcp.always_keepalive=0
net.inet.tcp.delayed_ack=0
net.inet.tcp.log_in_vain=0
net.inet.udp.log_in_vain=0
net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1
net.local.stream.sendspace=65535
net.local.stream.recvspace=32768
net.inet.ip.fastforwarding=1
vfs.vmiodirenable=1

 

  • UNIX系統優化

升級源碼樹

安裝cvsup
進入:/usr/ports/net/cvsup

make clean
make deinstall
make install
make clean

即可

升級系統源碼樹及ports

更新/usr/share/examples/cvsup目錄下stand-cvsup和ports-cvsup文件,並執行cvsup –g –L2 standard-supfile和cvsup –g –L2 ports-cvsup兩個文件,升級ports樹﹔

重新編譯內核

優化編譯環境
更新/etc/make.conf文件,做適當的編譯優化,如果CPU是Intel的:

CPUTYPE=i686
CFLAGS= -O3 -pipe
COPTFLAGS= -O3 -pipe

升級操作系統

進入/usr/src
執行make world
整個過程很久,需要2小時左右.

升級配置文件

執行mergemaster升級配置文件,在此過程中,需要按i以便系統執行升級﹔

 

  • APACHE優化.
    • conf優化

在httpd.conf 加入以下內容:

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 10

 

<IfModule prefork.c>

ServerLimit 2000

Startservers 10

MinSpareServers 10

MaxSpareServers 15

MaxClients 1000

MaxRequestsPerChild 1000

</IfModule>

B、啟用了單獨一個IP的並發鏈接數設置。

使用MOD_LIMITIP限制IP連接數
# wget http://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz
# tar –zxvf mod_limitipconn-0.22.tar.gz
# cd mod_limitipconn-0.22
# vi Makefile
修改相關路徑適應你的系統
# make install
# vi /usr/local/etc/apache2/httpd.conf
=========+===========+===========+============
<IfModule mod_limitipconn.c>
<Location / >                 //設置要控制的目錄
MaxConnPerIP 10              //限制單IP最大進程數
NoIPLimit image/*             //非限制的文件類型
</Location>
<Location /mp3>
MaxConnPerIP 1
OnlyIPLimit audio/mpeg video       //可選限制的文件類型
</Location>
</IfModule>

 

  • mysql優化
    • cnf優化

#cp /usr/local/share/mysql/my-huge.cnf /etc/my.cnf

#cd /etc

# vi  my.cnf 修改並增加如下內容:

[mysqld]

skip-locking
connect_timeout=15
interactive_timeout=100
join_buffer_size=1M
key_buffer=128M
max_allowed_packet=16M
max_connections=500
max_connect_errors=10
myisam_sort_buffer_size=64M
read_buffer_size=1M
read_rnd_buffer_size=768K
sort_buffer_size=1M
table_cache=1024
thread_cache_size=100
thread_concurrency=4
wait_timeout=300
query_cache_size=32M
query_cache_limit=1M
query_cache_type=1

long_query_time = 5

bind-address = 127.0.0.1

local-infile= 0

tmp_table_size = 100M
skip-innodb

 

 

log-slow-queries= /var/log/slow.log

 

  • php優化

php.ini的優化

確認你的 register_globals 配置為disabled

禁用 magic_quotes_* 選項

關閉 expose_php

關閉 register_argc_argv

除非絕對需要不要啟用 always_populate_raw_post_data

  • FTP伺服器優化.

修改pure-ftpd.conf

a、限定最大的客戶端訪問數。

MaxClientsNumber            50

b、每個ip最多鏈接數,最好設小點。

MaxClientsPerIP              5

C、不反向解釋客戶端的ip

DontResolve   yes

D、最大閑置時間

MaxIdleTime  5

e、ls最多列出3000個文件.最深8層

LimitRecursion       2000 8

f、支不支持FXP

AllowUserFXP        yes

g、當硬碟使用率到多少時將停止上傳.

 

MaxDiskUsage         99

  • MAIL伺服器優化。

在main.cf 設置如下參數:

qmgr_message_active_limit = 7000
local_destination_concurrency_limit = 600
default_destination_concurrency_limit = 600
default_process_limit=600
process_limit=600

 

  • DNS伺服器優化

以下優化是針對bind源代碼安裝的方式。

  • 變編譯選項;BIND默認的編譯選項中有個選項為「—O2」,該為「—O3」後
  • 使用ICC編譯器,對於應用軟體的編譯,使用intel 公司ICC編譯器相對於GCC編譯器有程度不等的提升。最樂觀的情況下會有20%以上的性能提升.

C、調整DNS服務線程數;目前使用的BIND版本基本上都支持多線程(啟動named後,用命令ps –eLF | grep named查看),但是默認的線程數並不一定是最好的。因此調整服務的線程個數來使當前硬體達到最大性能是很有必要的。修改方法在 dns 服務啟動文件中前面加入OPTIONS=「-n NUM」一行,NUM為指定進程數。然後啟動服務用上述命令查看是否是設定的線程數,然後通過BIND自帶的測試工具queryperf(在BIND源碼包的bind-VERSION/contrib/queryperf/目錄下)來測試自己DNS伺服器的最大QPS。不同的硬體的測試結果也不一樣。一般提高的幅度還都比較大。

  • 日誌伺服器優化

針對awstats日誌分析。

1、安裝GeoIP

2、安裝p5-GeoIPfree

3、安裝p5-Geo-IP

 

4、編輯:awstats.ding9.conf  加入以下內容:

LoadPlugin=”decodeutfkeys”

LoadPlugin=”tooltips”

  • SQUID 緩存伺服器優化

針對squid.conf的優化

#取消對代理陣列的支持
icp_port 0

訪問控制設置
acl mynet src 192.168.1.0/255.255.255.0
acl all src 0.0.0.0/0.0.0.0
http_access allow mynet
http_access deny all

swap 性能微調
half_closed_clients off
cache_swap_high 100%
cache_swap_low 80%
maximum_object_size 1024 KB

#這幾句其實是強行控制對象的超時時間,這違反了http協議的精神,但是在帶寬較窄的場合,可以提高明顯系統相應時間。

refresh_pattern -i .html 1440 90% 129600 reload-into-ims
refresh_pattern -i .shtml 1440 90% 129600 reload-into-ims
refresh_pattern -i .hml 1440 90% 129600 reload-into-ims
refresh_pattern -i .gif 1440 90% 129600 reload-into-ims
refresh_pattern -i .swf 1440 90% 129600 reload-into-ims
refresh_pattern -i .jpg 1440 90% 129600 reload-into-ims
refresh_pattern -i .png 1440 90% 129600 reload-into-ims
refresh_pattern -i .bmp 1440 90% 129600 reload-into-ims
refresh_pattern -i .js 1440 90% 129600 reload-into-ims

  • CVS伺服器優化
    • 首先正確創建用於CVS的組和用戶:
    • 修改配置文件:
      #cat/etc/services|grep cvspserver
      看看是否有:
      cvspserver    2401/tcp #CVS client/server operations
      cvspserver    2401/udp #CVS client/server operations
    • 初始化CVS
      切換到cvsroot用戶,然後進行初始化:
      cvs -d /home/cvsroot init
    • /sbin/service xinetd restart
      當然,重新啟動計算機也可以。確認是否啟動:
      netstat -anp|grep 2401
      如果能看到:
      tcp 0 0 0.0.0:2401
      說明已經正常啟動,

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營