為什麼我的伺服器只使用3GB內存

為什麼我的伺服器只使用3GB內存

該伺服器有 24 GB 記憶體和 4 個四核心 CPU。它在 apache/MySQL/php 上運行繁忙的網站,有時會給出伺服器負載過高的消息。當我查看日誌時,它從未使用超過 3 GB 的內存,這對我來說也很奇怪。這可能是 MySQL 或 apache 設定。

這裡有一些數據

uname -a
Linux s2274 2.6.32-32-server #62-Ubuntu SMP Wed Apr 20 22:07:43 UTC 2011 x86_64 GNU/Linux


free -m
             total       used       free     shared    buffers     cached
Mem:         24153      20951       3201          0        125      17719
-/+ buffers/cache:       3106      21046
Swap:        11240         14      11226

正如您所看到的,這裡顯示已使用 20 GB。但當我查看 top/htop 時,它的使用量從未超過 3092。處理器實際上並不活躍,平均負載為 0.9。我可以以某種方式增加 apache 和/或 MySQL 使用的記憶體來看看它是否可以使用所有記憶體嗎?


抱歉,我離開了一段時間......這是 mysqld 命令的輸出:

120108  8:48:21 [Note] Plugin 'FEDERATED' is disabled.
  --binlog_cache_size=#
  --bulk_insert_buffer_size=#
  --delayed_queue_size=#
  --join_buffer_size=#
  --key_buffer_size=# The size of the buffer used for index blocks for MyISAM
  --key_cache_block_size=#
  --max_binlog_cache_size=#
  --max_binlog_size=# Binary log will be rotated automatically when the size
                      max_relay_log_size is 0. The minimum value for this
  --max_heap_table_size=#
  --max_join_size=#   Joins that are probably going to read more than
                      max_join_size records return an error.
  --max_relay_log_size=#
                      the size exceeds max_binlog_size. 0 excepted, the minimum
  --myisam_block_size=#
  --myisam_data_pointer_size=#
  --myisam_max_extra_sort_file_size=#
  --myisam_max_sort_file_size=#
  --myisam_sort_buffer_size=#
  --preload_buffer_size=#
  --profiling_history_size=#
  --query_alloc_block_size=#
  --query_cache_size=#
  --query_prealloc_size=#
  --range_alloc_block_size=#
  --read_buffer_size=#
  --read_rnd_buffer_size=#
  --record_buffer=#   Alias for read_buffer_size
  --sort_buffer_size=#
  --thread_cache_size=#
  --tmp_table_size=#  If an internal in-memory temporary table exceeds this
  --transaction_alloc_block_size=#
--transaction_prealloc_size=#
binlog_cache_size                 32768
bulk_insert_buffer_size           8388608
delayed_queue_size                1000
join_buffer_size                  12582912
key_buffer_size                   805306368
key_cache_block_size              1024
max_binlog_cache_size             18446744073709547520
max_binlog_size                   104857600
max_heap_table_size               805306368
max_join_size                     18446744073709551615
max_relay_log_size                0
myisam_block_size                 1024
myisam_data_pointer_size          6
myisam_max_extra_sort_file_size   2147483648
myisam_max_sort_file_size         9223372036853727232
myisam_sort_buffer_size           25165824
preload_buffer_size               32768
profiling_history_size            15
query_alloc_block_size            8192
query_cache_size                  805306368
query_prealloc_size               8192
range_alloc_block_size            4096
read_buffer_size                  25165824
read_rnd_buffer_size              25165824
sort_buffer_size                  25165824
thread_cache_size                 256
tmp_table_size                    805306368
transaction_alloc_block_size      8192
transaction_prealloc_size         4096

php記憶體限制是128M

我在多種情況下看到 3 GB 的限制。 Fi Htop、top 以及當我在伺服器狀態下登入 Webmin 時。

我會嘗試在這裡添加屏幕截圖...

答案1

您正在使用 24153 中的 20951 個。當您的應用程式需要更多記憶體時,核心將減少快取以適應新的應用程式需求。

調整 MySQL 和 Apache 配置以獲得最佳效能取決於應用程式。在某些情況下,例如靜態網站,大型檔案系統快取非常有用。然而,具有大量資料庫互動的動態網站將受益於對預設 MySQL 配置的一些變更。

Percona 有一個很好的工具可以幫助您開始 MySQL 設定。http://tools.percona.com/wizard一旦您了解了基礎知識,您就可以針對應用程式的具體情況進行進一步調整。

Apache 設定取決於流量和請求的大小。在不了解任何情況的情況下,很難推薦超出預設值的內容。

答案2

如果我是正確的,你正在運行 32 位元伺服器

32 位元記憶體限制為 4 GB,除非您使用 pae 映像:

32 位元電腦的字大小為 32 位元,理論上將記憶體限制為 4GB。這一障礙已透過使用「實體位址擴展」(或 PAE)得到了擴展,它將限制增加到 64GB,儘管 4GB 以上的記憶體存取會稍微慢一些。

我找不到核心映像是否包含 pae。

您可以嘗試執行 apt-get install linux-image-generic-pae

如果是這樣,請重新啟動並查看是否使用了更多記憶體。

否則考慮安裝 64 位元伺服器

相關內容