Openfire伺服器MySQL最佳化

來源:互聯網
上載者:User

標籤:

Openfire伺服器MySQL最佳化:

[[email protected] ~]# mysql -u root -p XXXXX

mysql> show processlist;

+----------+-----------------+---------------------+-------+---------+-------+-----------------------------+------------------+

| Id       | User            | Host                | db    | Command | Time  | State                       | Info             |

+----------+-----------------+---------------------+-------+---------+-------+-----------------------------+------------------+

|        1 | event_scheduler | localhost           | NULL  | Daemon  | 51497 | Waiting for next activation | NULL             |

| 16069885 | xx_xxx_user     | 10.164.13.209:48184 | XXXXX | Sleep   |     0 |                             | NULL             |

| 16069886 | xx_xxx_user     | 10.164.13.209:48185 | XXXXX | Sleep   |     0 |                             | NULL             |

| 16069887 | xx_xxx_user     | 10.164.13.209:48186 | XXXXX | Sleep   |     0 |                             | NULL             |

| 16069888 | xx_xxx_user     | 10.164.13.209:48187 | XXXXX | Sleep   |     0 |                             | NULL             |

| 16069889 | xx_xxx_user     | 10.164.13.209:48188 | XXXXX | Sleep   |     0 |                             | NULL             |

......

| 16071110 | xx_xxx_user     | 10.164.13.209:48520 | XXXXX | Sleep   |     3 |                             | NULL             |

| 16358232 | root            | localhost           | XXXXX | Query   |     0 | NULL                        | show processlist |

+----------+-----------------+---------------------+-------+---------+-------+-----------------------------+------------------+

118 rows in set (0.00 sec)

mysql> show variables like ‘%timeout‘;

+----------------------------+----------+

| Variable_name              | Value    |

+----------------------------+----------+

| connect_timeout            | 10       |

| delayed_insert_timeout     | 300      |

| innodb_lock_wait_timeout   | 50       |

| innodb_rollback_on_timeout | OFF      |

| interactive_timeout        | 100      |

| lock_wait_timeout          | 31536000 |

| net_read_timeout           | 30       |

| net_write_timeout          | 60       |

| slave_net_timeout          | 3600     |

| wait_timeout               | 100      |

+----------------------------+----------+

10 rows in set (0.00 sec)

mysql> show global variables like ‘%timeout‘;

+----------------------------+----------+

| Variable_name              | Value    |

+----------------------------+----------+

| connect_timeout            | 10       |

| delayed_insert_timeout     | 300      |

| innodb_lock_wait_timeout   | 50       |

| innodb_rollback_on_timeout | OFF      |

| interactive_timeout        | 100      |

| lock_wait_timeout          | 31536000 |

| net_read_timeout           | 30       |

| net_write_timeout          | 60       |

| slave_net_timeout          | 3600     |

| wait_timeout               | 100      |

+----------------------------+----------+

10 rows in set (0.00 sec)

mysql> set global interactive_timeout=100;

mysql> set global wait_timeout=100;

如果修改interactive_timeout的話wait_timeout也會跟著變,而只修改wait_timeout是不生效的。

 

[[email protected] ~]# vim /etc/my.cnf

[client]

port            = 3306

socket          = /data/mysql/mysql.sock

[mysqld_safe]

socket          = /data/mysql/mysql.sock

nice            = 0

[mysqld]

#datadir=/data/mysql/data/mysql

socket=/data/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0

# 預設連接埠

port            = 3306

datadir         = /data/mysql/data/mysql

tmpdir          = /tmp

lc-messages-dir = /usr/share/mysql

# 避免MySQL的外部鎖定,減少出錯幾率增強穩定性

skip-external-locking

# 設定mysql伺服器的字元集

character-set-server = utf8

# 預設儲存引擎

default-storage-engine = INNODB

# Instead of skip-networking the default is now to listen only on

# localhost which is more compatible and is not less secure.

# bind-address            = 0.0.0.0

skip-name-resolve

# UDF自訂函數若有用到需要開啟。後續memcached會用到UDF

log_bin_trust_function_creators = 1

# 用到了事件,應該開啟

event_scheduler = 1

# Error log - should be very few entries.

# log_error = /data/mysql/log/error.log

key_buffer              = 16M

# MYISAM儲存引擎的索引緩衝的大小

key_buffer_size = 16M

# 聯集查詢操作所能使用的緩衝區大小

join_buffer_size = 4M

# 用來控制其通訊緩衝區的最大長度

max_allowed_packet      = 16M

# 指定MySQL允許的最大串連進程數。如果經常出現Too Many Connections的錯誤提 示,則需要增大該參數值。預設值是151,這裡設為500。根據實際情況再行調整

max_connections = 500

# 最大串連錯誤數

max_connect_errors = 10000

# 緩衝可重用的線程數

table_open_cache = 4096

# 查詢排序時所能使用的緩衝區大小

sort_buffer_size = 4M

# 每個進行一個順序掃描的線程為其掃描的每張表分配這個大小的一個緩衝區,若做很多順序掃描,增加該值。

read_buffer_size = 4M

# 隨機讀緩衝區,mysql排序查詢時,先掃描該緩衝避免磁碟搜尋

read_rnd_buffer_size = 8M

# 開啟查詢快取

query_cache_type = 1

# 指定MySQL查詢緩衝區的大小

query_cache_size = 256M

# 單個查詢能用緩衝區大小

query_cache_limit = 2M 

# 指定分配緩衝區空間的最小單位,預設為4K

query_cache_min_res_unit = 4K

# 記憶體表大小,該值用來計算記憶體表的最大行數

max_heap_table_size = 32M

# 指定mysql緩衝的記憶體大小,預設16M

tmp_table_size = 32M

# 臨時停止回應新請求前在短時間內可以堆起多少請求,也就是說,如果MySql的串連資料達到max_connections時,新來的請求將會被存在堆棧中,以等待某一串連釋放資源,

# 該堆棧的數量即back_log,如果等待串連的數量超過back_log,將不被授予串連資源。back_log值不能超過TCP/IP串連的偵聽隊列的大小。若超過則無效,

# 查看當前系統的TCP/IP串連的偵聽隊列的大小命令:cat /proc/sys/net/ipv4/tcp_max_syn_backlog目前系統為1024。對於Linux系統推薦設定為小於512的整數。

# 每個串連256kb,佔用:125M

back_log = 500

# 指定一個請求的最大連線時間,逾時時間,可以避免攻擊。對於4GB左右記憶體的伺服器可以設定為5-10

wait_timeout = 604800

# 伺服器在關閉它前在一個互動串連上等待行動的秒數

interactive_timeout = 604800  

# 該參數取值為伺服器邏輯CPU數量×2,預設8

# 該參數在5.6.1版本後被放棄了

thread_concurrency = 16

thread_stack            = 512K

thread_cache_size       = 64

myisam-recover         = BACKUP

# 記錄慢查詢語句,路徑根據實際

log_slow_queries        = /data/mysql/log/mysql-slow.log

# 設定慢查詢的時間

long_query_time = 2

# 記錄未用索引的慢查詢

log-queries-not-using-indexes

# 開啟二進位日誌earcs-bin為記錄檔首碼 basename

log_bin                 = /data/mysql/log/earcs-bin.log

# 設定日誌的有效期間為10天.

expire_logs_days        = 2

max_binlog_size         = 100M

# 開啟檔案數

open_files_limit = 10240

# 控制日誌重新整理到硬碟的時機

innodb_flush_log_at_trx_commit = 0

# on表示啟用單資料表空間,減少共用資料表空間維護成本,減少空閑磁碟空間釋放的壓力

innodb_file_per_table = 1

# 設定交易隔離等級

transaction-isolation = READ-COMMITTED

# 二進位日誌格式

binlog-format = MIXED

# 官方建議在一個32位的系統中,要設定小於2G。

innodb_buffer_pool_size = 10G

# 控制日誌重新整理到硬碟的時機

innodb_flush_log_at_trx_commit = 0

# 需要根據寫負載的頻度以及大事務的多少,動態調整。

innodb_log_buffer_size = 8M

# 在日誌組中每個記錄檔的大小

innodb_log_file_size = 512M

# 這個參數在5.6.3版本以後會被棄用。

innodb_additional_mem_pool_size = 100M

# 提高mysql速度的,禁止DNS緩衝

skip-host-cache

[mysqld_safe]

log-error=/data/mysql/log/mysqld.log

pid-file=/data/mysqld/mysqld.pid

 

Openfire伺服器MySQL最佳化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.