2019年5月29日 星期三

Zabbix



安裝流程

1 安裝server
2 安裝 mysql
3 建立 db
4 改設定

參考官方安裝文件
https://www.zabbix.com/download?zabbix=4.0&os_distribution=centos&os_version=7&db=mysql

https://www.zabbix.com/documentation/4.0/manual/installation/install_from_packages/rhel_centos

設定 zabbix mysql password

grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
flush privileges;

設定 php time zone

vi /etc/httpd/conf.d/zabbix.conf,
php_value date.timezone Asia/Shanghai

2019年5月16日 星期四

MySQL InnoDB Lock

詳細說明
詳細說明

InnoDB在transaction中,會視語法不同,自動加鎖。
Transaction中的鎖,都是以Row為標的。

非transaction中,因為會自動COMMIT,所以使用加鎖的語法也沒用。

InnoDB三種加鎖類型

  • Record lock: This is a lock on an index record.
  • Gap lock: This is a lock on a gap between index records, or a lock on the gap before the first or after the last index record.
  • Next-key lock: This is a combination of a record lock on the index record and a gap lock on the gap before the index record.
  • 官網說明:http://dev.mysql.com/doc/refman/5.7/en/innodb-record-level-locks.html
  • 重點1:Next-key locking combines index-row locking with gap locking.
  • InnoDB performs row-level locking in such a way that when it searches or scans a table index, it sets shared or exclusive locks on the index records it encounters (select 過程搜尋遇到的資料列都會被加鎖)

InnoDB鎖定模式

  • 共享鎖定 (shared lock) (S lock):permits the transaction that holds the lock to read a row.
  • 排他鎖定 (exclusive lock) (X lock):permits the transaction that holds the lock to update or delete a row.

不同語句的加鎖效果

  • SELECT ... FROM 基本不加鎖
    但在 SERIALIZABLE 隔離層級時,會自動在遇到的資料加鎖
  • SELECT ... FROM ... LOCK IN SHARE MODE (加共享鎖)
  • SELECT ... FROM ... FOR UPDATE (加排它鎖)
  • UPDATE ... WHERE ... (加排它鎖)
  • DELETE FROM ... WHERE ... (加排它鎖)
  • INSERT (加排它鎖)

MySQL AUTOCOMMIT命令

Autocommit 是設定MySQL是否自動提交變更

AUTOCOMMIT 的設定值,預設一般都是 1

查詢目前 AUTOCOMMIT 的設定值:SELECT @@AUTOCOMMIT

將 AUTOCOMMIT 改為 0 時 ( SET AUTOCOMMIT=0 ),就算沒使用transaction( START TRANSACTION 或 BEGIN ),整個連線執行的 SQL 指令,都會等到下達 COMMIT 提交後,才會真正儲存變更。

也就是當 AUTOCOMMIT=0 時,跟在交易模式下相同。

更改COMMIT狀態指令:
SET AUTOCOMMIT=0; // AUTOCOMMIT=1;

提交指令:
COMMIT;