顯示具有 RDS 標籤的文章。 顯示所有文章
顯示具有 RDS 標籤的文章。 顯示所有文章

2015年2月14日 星期六

AWS 筆記 - DB Instance XXXX contains MyISAM tables that have not been migrated to InnoDB. These tables can impact your ability to perform point-in-time restores. Consider converting these tables to InnoDB

先查看有哪些 table:

mysql> SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES;
+----------------------+--------------------+
| TABLE_NAME           | ENGINE             |
+----------------------+--------------------+
...
| pma_bookmark         | MyISAM             |
| pma_column_info      | MyISAM             |
| pma_designer_coords  | MyISAM             |
| pma_history          | MyISAM             |
| pma_pdf_pages        | MyISAM             |
| pma_recent           | MyISAM             |
| pma_relation         | MyISAM             |
| pma_table_coords     | MyISAM             |
| pma_table_info       | MyISAM             |
| pma_table_uiprefs    | MyISAM             |
| pma_tracking         | MyISAM             |
| pma_userconfig       | MyISAM             |
...


結果發現是 PHPMyAdmin 的那些 tables,由於這些影響不大,就操刀吧!以 pma_bookmark 為例

mysql> ALTER TABLE  `phpmyadmin`.`pma_bookmark` ENGINE = INNODB;

收工。

2014年10月30日 星期四

[MySQL] Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

些前在阿里雲、AWS RDS 架設 MySQL Master-Master Replication 出現此問題 Orz 將兩邊設定為各是對方的 Master 如此達到資料跨國同步。然而,卻發現在阿里雲作為 Replication Slave 角色的出現這個問題 Orz 由於在阿里雲的 DB Server 偏向 Cache 角色,確認後資料屬性,決定解決的方案是將阿里雲機器清空再重 AWS RDS 匯入,筆記一下解決步驟:

  1. 兩邊都停下 slave 角色動作
    • ALiYun-DB> STOP SLAVE
    • AWS-RDB> CALL mysql.rds_stop_replication
  2. 從 AWS RDS 匯出資料、並查看 MASTER_LOG_FILE 和 MASTER_LOG_POS 資訊
  3. 匯入阿里雲 DB Server,並設定 Slave 角色資訊,啟動 Slave 工作
    • $ mysql -h AliYunDB < AWSRDBExport.sql
    • ALiYun-DB> CHANGE MASTER TO MASTER_LOG_FILE='aws-rdb-mysql-bin-changelog.#######', MASTER_LOG_POS=#####;
    • ALiYun-DB> START SLAVE
    • ALiYun-DB> SHOW SLAVE STATUS \G
  4. 查看阿里雲 MASTER_LOG_FILE 和 MASTER_LOG_POS,更新 AWS RDS Slave 角色資訊,重新啟動 AWS RDS Slave 工作
    • ALiYun-DB> SHOW MASTER STATUS \G
      • MASTER_LOG_FILE
      • MASTER_LOG_POS
    • AWS-RDB> CALL mysql.rds_reset_external_master;
    • AWS-RDB> CALL mysql.rds_set_external_master (
          'aliyun-db-server-ip',
          3306,
          'repl_account',
          'repl_password',
          'aliyun-db-MASTER_LOG_FILE',
          aliyun-db-MASTER_LOG_POS
      ,   0 )
    • AWS-RDB > CALL mysql.rds_start_replication;
    • AWS-RDS > CALL mysql.rds_set_configuration('binlog retention hours', 24*14);

2014年5月10日 星期六

[Linux] 使用 Nagios 監控 AWS EC2、RDS 服務狀況 @ Ubuntu 12.04

雖然 AWS 已經有不錯的服務監控系統,但原先已經用 Nagios 監控服務,就順手研究一下對於 EC2、RDS 的監控吧。

由於資安角度,預設都不給 PING 的,此外 RDS (此例是 MySQL port 3306) 則只開放特定 TCP Port 而已,對 Nagios 而言,就可以改測試 TCP Port (HTTP,HTTPS,SSH) 等用法,如此一來就可以解決 Host is Down 囉。

define host {
        host_name aws-rdb
        alias aws-rdb-dns
        address aws-rdb-dns
        use rdb-host
        contact_groups db-services
}

define host {
        host_name aws-dev
        alias aws-dev-dns
        address aws-dev-dns
        hostgroups ssh-servers,http-servers
        use ec2-host
        contact_groups pc-services
}

define command {
        command_name check-rds-host-alive
        command_line /usr/lib/nagios/plugins/check_tcp -H $HOSTADDRESS$ -p 3306
}

define command {
        command_name check-ec2-host-alive
        command_line /usr/lib/nagios/plugins/check_tcp -H $HOSTADDRESS$ -p 80
}

define host{
        name                            rdb-host    ; The name of this host template
        notifications_enabled           1       ; Host notifications are enabled
        event_handler_enabled           1       ; Host event handler is enabled
        flap_detection_enabled          1       ; Flap detection is enabled
        failure_prediction_enabled      1       ; Failure prediction is enabled
        process_perf_data               1       ; Process performance data
        retain_status_information       1       ; Retain status information across program restarts
        retain_nonstatus_information    1       ; Retain non-status information across program restarts
                check_command                   check-rds-host-alive
                max_check_attempts              10
                notification_interval           0
                notification_period             24x7
                notification_options            d,u,r
                contact_groups                  admins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

define host{
        name                            ec2-host    ; The name of this host template
        notifications_enabled           1       ; Host notifications are enabled
        event_handler_enabled           1       ; Host event handler is enabled
        flap_detection_enabled          1       ; Flap detection is enabled
        failure_prediction_enabled      1       ; Failure prediction is enabled
        process_perf_data               1       ; Process performance data
        retain_status_information       1       ; Retain status information across program restarts
        retain_nonstatus_information    1       ; Retain non-status information across program restarts
                check_command                   check-ec2-host-alive
                max_check_attempts              10
                notification_interval           0
                notification_period             24x7
                notification_options            d,u,r
                contact_groups                  admins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

[Linux] AWS RDS + PHPMyAdmin + HTTPS + HTTP Basic authentication @ Ubuntu 14.04

為了配合 AWS RDS 而開始用 mysql-server-5.6 ,就試著用 EC2 + Ubuntu 14.04,安裝 PHPMyAdmin 時,採用的 DB 不是在本機的,而是 RDS 上。雖然我也不常用 PHPMyAdmin ,但為了提供其他人使用,所以就來架設一下 XD

$ sudo apt-get install mysql-client-5.6 php5 apache2 apache2-utils git php5-mysql
$ sudo a2ensite default-ssl.conf
$ sudo php5enmod mcrypt
$ sudo service apache2 restart

$ sudo vim /etc/phpmyadmin/config-db.php
// 在底部新增:
$dbuser='rds_account';
$dbpass='rds_password';
$dbserver='rds_location';

$ sudo vim /etc/phpmyadmin/config.inc.php

// 採用 HTTP Basic authentication
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'http';

// ...
// 最底層加上強制 HTTPS
$cfg['ForceSSL'] = true;


如此一來,使用 http://hostname/phpmyadmin 時,就會強制轉成 https://hostname/phpmyadmin,並且會採用 HTTP Basic authentication 機制。

註:不知為何,採用 HTTP Basic authentication 機制時,logout 後再進行 login 時,url後面會帶有 old_usr 資訊時,無法正常登入,所以後來就放棄了 XD

2014年4月29日 星期二

AWS 筆記 - 查詢 Amazon RDS Disk Space 硬碟空間使用情況


AWS Console -> RDS -> Instances -> choose an instance -> Show Monitoring -> Freeable Sapce (MB)

此例是建立 300GB RDS,還剩 284053 MB 可用。還可以查看兩星期內的空間使用變化。

2014年4月23日 星期三

AWS - 使用 Amazon RDS - MySQL Replica 筆記



體驗 Amazon RDS 與 MySQL Replica 運作模式,有幾項心得:
  • Amazon RDS 當 Slave 時,必須改用 Amazon 自定 func 來啟動,如 mysql.rds_set_external_mastermysql.rds_reset_external_mastermysql.rds_start_replication (START SLAVE)、mysql.rds_stop_replication (STOP SLAVE) 和 mysql.rds_skip_repl_error 等
  • Amazon RDS 使用 UTC 時區,依照 MySQL Replication and Time Zones 文件所述,Master 跟 Slave 的時區須一致,因此,也調整 Master 情況,對於 Timestamp 的用法就要避免用 MySQL CURRENT_TIMESTAMP 等,建議避開透過 MySQL 管理時區,直接用程式設定 timestamp 數值。但這樣變動還滿大的。
  • 定期用 mysql> SHOW SLAVE STATUS \G 觀看,儘量不要用 SELECT count(*) FROM table 來觀看,因為會需要關注的情況通常是資料量已經很大了,而 AWS RDS $0.10 per 1 million I/O requests,一直用 count(*) 在資料量大的情況也會很可觀的。Seconds_Behind_Master 數值,可能短期不會降下來,用0.5~1天的時間間隔去觀察是否有下降即可
  • 機器要 reboot 前,記得要先用 mysql.rds_stop_replication (等同 STOP Slave) 指令,若 Seconds_Behind_Master 數值很大,通常要跑很久

    mysql> CALL mysql.rds_stop_replication;                                                                                          
    +---------------------------+
    | Message                   |
    +---------------------------+
    | Slave is down or disabled |
    +---------------------------+
    1 row in set (5 min 28.69 sec)
    
  • 假設 RDS 專門當 MySQL Replica Slave 的話,記得 Master 可以透過 binlog-ignore-db 濾掉 mysql 等 databases,不然當 Master 更動 mysql 時(例如 apt-get upgrade 有 mysql 時也會有機會碰到)也會把這些 log 記錄起來,到時後 RDS 收到就會噴錯誤訊息,而 RDS 的解法就是不斷地用 mysql.rds_skip_repl_error 略過這些更動(可以搭配 SHOW SLAVE STATUS \G 查看 Last_SQL_Error 資訊,例如:

    mysql> SHOW SLAVE STATUS \G
    ...
    Last_SQL_Error: Error 'Access denied for user ''@'' to database 'mysql'' on query. Default database: 'mysql'. Query: 'ALTER TABLE db
       MODIFY Host char(60) NOT NULL default '',
       MODIFY Db char(64) NOT NULL default '',
       MODIFY User char(16) NOT NULL default '',
       ENGINE=MyISAM, CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin'
    
    mysql> CALL mysql.rds_skip_repl_error ;
    +-------------------------------------+
    | Message                             |
    +-------------------------------------+
    | Statement in error has been skipped |
    +-------------------------------------+
    1 row in set (0.05 sec)
    
    +-----------------------------------------------------------------------------------+
    | Message                                                                           |
    +-----------------------------------------------------------------------------------+
    | Slave has encountered a new error. Please use SHOW SLAVE STATUS to see the error. |
    +-----------------------------------------------------------------------------------+
    1 row in set (2.05 sec)
    
    Query OK, 0 rows affected (2.05 sec)
    
    ...
    
    mysql> CALL mysql.rds_skip_repl_error ;
    +---------------------------------------------------------+
    | Message                                                 |
    +---------------------------------------------------------+
    | Slave is running normally.  No errors detected to skip. |
    +---------------------------------------------------------+
    1 row in set (0.03 sec)
    
    
此外,對於 RDS 操作心得:
  • 開一個單位出來至少 15 分鐘起跳,從 create 到 backup 約 15 分鐘,其中 backup 是開台例行流程,以 18GB的 storage size 來說,約 3 分鐘,從 backup 換到 modifying 還要 2分鐘。
  • 從 snapshot restore 亦是如此,過程還必須重 load my.cnf 設定(因為預設不給挑 my.cnf),過程像是要再 reboot 一下,從 applying 到 pending-reboot 約 4 分鐘,當按下手動 reboot 時,兩分鐘內狀態從 pending-reboot 變成 in-sync,但 DB Instance Status 還是在 rebooting,從 rebooting 轉成 available 約 2 分鐘
  • 試過 db.t1.micro 跟 db.m1.small 做 MySQL Replica Slave 的角色,發現 DB server 資料增加量追不上?改用 db.m1.medium 了($0.115 per RDS Medium Instance hour ),穩穩地有看到 Seconds_Behind_Master 下降,但貴的不是開台的價錢,還可能是 I/O Requests 的價碼,資料要一直追,現況 12 小時約 0.5 million I/O requests ($0.10 per 1 million I/O requests)
所以從 snapshot 開一檯機器都可以用耗時約 27 分鐘,比我想像中慢了不少,測試起來真痛苦。

其他心得:
  • 別忘了確認 Master 跟 Slave 的 character,此例我是設定為 utf8,RDS 預設也是 latin1

    mysql> show variables like '%char%';
    +--------------------------+-------------------------------------------+
    | Variable_name            | Value                                     |
    +--------------------------+-------------------------------------------+
    | character_set_client     | utf8                                      |
    | character_set_connection | utf8                                      |
    | character_set_database   | utf8                                      |
    | character_set_filesystem | binary                                    |
    | character_set_results    | utf8                                      |
    | character_set_server     | utf8                                      |
    | character_set_system     | utf8                                      |
    | character_sets_dir       | /rdsdbbin/mysql-5.5.33.R1/share/charsets/ |
    +--------------------------+-------------------------------------------+
    
  • 如果未來打算把 RDS 當 Master 的話,可以留意 auto_increment_increment 跟 auto_increment_offset 的設定,可提供平順的轉換機制(可支援從 Read 變 Write)
    mysql> show variables like 'auto_inc%';
    +--------------------------+-------+
    | Variable_name            | Value |
    +--------------------------+-------+
    | auto_increment_increment | 10    |
    | auto_increment_offset    | 2     |
    +--------------------------+-------+
  • 建一台 RDS 個人常做設定 Parameter Groups:
    max_allowed_packet = 67108864
    sync_binlog = 1
    innodb_flush_log_at_trx_commit = 1
    auto_increment_offset = m
    auto_increment_increment = n
    collation_connection = utf8_unicode_ci
    character_set_results = utf8
    character_set_server = utf8
    character_set_connection = utf8
    character_set_database = utf8
    character_set_client = utf8
    character_set_filesystem = binary
    
  • 一般 MySQL Server Master my.cnf:
    [mysqld]
    # ...
    character-set-server=utf8
    collation-server=utf8_general_ci
    # ...
    default-time-zone       = '+00:00'
    server-id               = x 
    auto-increment-increment = y
    auto-increment-offset   = z 
    log_bin                 = /var/log/mysql/mysql-bin.log
    binlog-ignore-db = mysql
    binlog-ignore-db = performance_schema
    binlog-ignore-db = information_schema
    binlog-ignore-db = test
    innodb_flush_log_at_trx_commit = 1 
    sync_binlog = 1
    
  • 簡易 Slave 設定對應表:
    • 一般 MySQL Slave:
      mysql> CHANGE MASTER TO 
      MASTER_HOST='YourDBServerIP', 
      MASTER_USER='repl_account', 
      MASTER_PASSWORD='repl_password', 
      MASTER_LOG_FILE='mysql-bin.######', 
      MASTER_LOG_POS=#######;
      
      mysql> START SLAVE;
      
      mysql> STOP SLAVE;
      
      mysql> RESET SLAVE;
      
    • RDS Slave:
      mysql> CALL mysql.rds_set_external_master (
      'YourDBServerIP'
      , 3306
      , 'repl_account'
      , 'repl_password'
      , 'mysql-bin.######'
      , #######
      , 0
      );
      
      mysql> CALL mysql.rds_start_replication;
      
      mysql> CALL mysql.rds_stop_replication;
      
      mysql> CALL mysql.rds_reset_external_master;
      
      
  • 如果MySQL Replica Master 是 5.5.x 版,那依照 MySQL 文件在 RDS 開一台 5.6.x 當 MySQL Replica Slave 應該也行,文件出處:MySQL 5.6 Reference Manual :: 16 Replication :: 16.4 Replication Notes and Tips :: 16.4.3 Upgrading a Replication Setup When you upgrade servers that participate in a replication setup, the procedure for upgrading depends on the current server versions and the version to which you are upgrading.

    This section applies to upgrading replication from older versions of MySQL to MySQL 5.6. A 4.0 server should be 4.0.3 or newer.

    When you upgrade a master to 5.6 from an earlier MySQL release series, you should first ensure that all the slaves of this master are using the same 5.6.x release. If this is not the case, you should first upgrade the slaves. To upgrade each slave, shut it down, upgrade it to the appropriate 5.6.x version, restart it, and restart replication. Relay logs created by the slave after the upgrade are in 5.6 format.

    ...

2014年4月16日 星期三

AWS - 初次使用 Amazon Relational Database Service (RDS) 筆記

時間差不多了,該幫公司引入 Amazon RDS 了!首先就是先請老闆拿出信用卡註冊一個帳號,接著邀請指定的管理者進駐使用,再透過 AWS Identity and Access Management (IAM) 給予權限,而這些管理者就不需要註冊 AWS 了,並且有專屬的 login 網址。此例會接觸到 EC2 跟 RDS 這兩塊,其中 EC2 是 Security Group 的部分,因為 Amazon RDS 的登入權限是吃 EC2 裡的 Security Group,例如不限 IP 來源(0.0.0.0/0) 等。

簡單地用圖記錄,此例先用預設值:

Step 1:使用 AWS RDS


Step 2:在此選擇 MySQL


Step 3:在此使用最簡單的方案


Step 4:設定 RDS 的規格,以及 RDS 代號,以及登入的帳密


Step 5:設定 MySQL 的環境,在此先用預設,之後還可以改。並且開一個 Database,此外 Security Group 則是在規範有誰可以連到這台 DB server,這可以晚點再切換到 EC2 去設定


Step 6:使用預設備份等


Step 7:接著就會確認 RDS 規格並進行啟動啦,可以準備回到 Dashboard 觀察目前的資訊


Steo 8:接著就可以查看目前 RDS 初始化的狀態


Step 9:初始化完在 EndPoint就會顯示登入位置:


Step 10:這步不見得需要,這是切換到 EC2 的 Security Group 設定,此例是允許任何位置的 IP 連入


最後,就跟用 command line 連進一台 MySQL DB 沒兩樣囉。