Linux UDEV和為MySQL InnoDB共享表空間配置裸設備 ⑴ UDEV 基礎 udev 可管理保存在/dev 目錄下的文件、文件只有在接入相應設備後才會生成、設備被拔出後自動刪除 它還允許用戶添加規則、以便修改/dev中默認的名稱和權限、規則保存在/etc/udev/rules.d/目錄下 ⑵ MySQL 綁定裸設備 只有InnoDB可以用裸設備 優點:繞過了文件系統,讀寫速度會有提高,並且數據會比較安全、同時降低文件系統負擔、也改善系統性能 缺點:太安全了,好多備份工具可能沒法用、dd可以考慮 下面介紹如何為mysql共享表空間綁定裸設備 ㈠ 制作裸設備
# fdisk /dev/sda ==> /dev/sda5 # partprobe # fdisk -l # pvcreate /dev/sda5 # vgcreate -s 16M mysqlvg /dev/sda5 # lvcreate -L 90M -n sharespace mysqlvg # vim /etc/sysconfig/rawdevices ==> /dev/raw/raw1 /dev/mysqlvg/sharespace # service rawdevices start # chkconfig rawdevices on # chown -R mysql:dba /dev/mapper/mysqlvg-sharespace
㈡ 配置MySQL ① 指定newraw屬性
innodb_data_home_dir = innodb_data_file_path = /dev/mapper/mysqlvg-sharespace:60Mnewraw
② 重啟mysql服務,待其完成分區初始化工作後,再關閉mysql服務 ③ 修改raw屬性
innodb_data_home_dir = innodb_data_file_path = /dev/mapper/mysqlvg-sharespace:60Mraw
④ 重啟mysql服務 如果整個系統重啟、裸設備的權限會被回收、導致mysql無法開啟 官網描述如下:
[plain] will fail after the next reboot, if the /dev-tree is dynamically created by, e.g. udev, a MAKEDEV-script or similar. After reboot, the device will regain its former permission, typically excluding access by mysql.
alert 報警如下:
[plain] 130719 20:42:43 InnoDB: Operating system error number 13 in a file operation. InnoDB: The error means mysqld does not have the access rights to InnoDB: the directory. InnoDB: File name /dev/mapper/mysqlvg-sharespace InnoDB: File operation call: 'open'. InnoDB: Cannot continue operation.
此時可選方案: 1)寫個簡單的初始化腳本、當重啟的時候自動授權 2)配置 udev條目、
[plain] [root@odd rules.d]# pwd /etc/udev/rules.d [root@odd rules.d]# cat 60-raw.rules ACTION=="add", KERNEL=="sda5", GROUP=="dba", MODE=="0660", RUN+="/bin/raw /dev/raw/raw1 %N" [root@odd rules.d]# cat 65-raw-permissions.rules KERNEL=="sda5", GROUP="dba", MODE="0660"