next up previous contents
Next: Message queue Up: 環境準備 Previous: OpenStack 套件   Contents

SQL 資料庫

  1. 安裝 mariadb 資料庫相關套件。
    [root@ip112 ~]# yum install mariadb mariadb-server python2-PyMySQL
  2. 新增並編輯 /etc/my.cnf.d/openstack.cnf,章節 mysqld 中加入以下設定,其中 bind-address 為 contorl node 的 IP。
    [root@ip112 ~]# vim /etc/my.cnf.d/openstack.cnf
    [root@ip112 ~]# cat /etc/my.cnf.d/openstack.cnf
    bind-address =
    default-storage-engine = innodb
    innodb_file_per_table = on
    max_connections = 4096
    collation-server = utf8_general_ci
    character-set-server = utf8
  3. 啟動 mariadb 服務,並設定開機啟動。
    [root@ip112 ~]# systemctl enable mariadb.service 
    Created symlink from /etc/systemd/system/ 
    to /usr/lib/systemd/system/mariadb.service.
    [root@ip112 ~]# systemctl start mariadb.service 
    [root@ip112 ~]# systemctl status mariadb.service 
    ● mariadb.service - MariaDB 10.1 database server
       Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
       Active: active (running) since Wed 2018-05-23 16:35:37 CST; 10s ago
      Process: 11833 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
      Process: 11647 ExecStartPre=/usr/libexec/mysql-prepare-db-dir %n (code=exited, status=0/SUCCESS)
      Process: 11623 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
     Main PID: 11806 (mysqld)
       Status: "Taking your SQL requests now..."
       CGroup: /system.slice/mariadb.service
               └─11806 /usr/libexec/mysqld --basedir=/usr
    May 23 16:35:37 systemd[1]: Started MariaDB 10.1 data...
    Hint: Some lines were ellipsized, use -l to show in full.
  4. mysql 安全設定,主要是設定 mysql 管理帳號 root 登入的密碼,其餘都按 Enter 使用預設值。
    [root@ip112 ~]# mysql_secure_installation 
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.
    Enter current password for root (enter for none): 
    OK, successfully used password, moving on...
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorisation.
    Set root password? [Y/n] Y
    New password: 
    Re-enter new password: 
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    Remove anonymous users? [Y/n] 
     ... Success!
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    Disallow root login remotely? [Y/n] 
     ... Success!
    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    Remove test database and access to it? [Y/n] 
     - Dropping test database...
     ... Success!
     - Removing privileges on test database...
     ... Success!
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    Reload privilege tables now? [Y/n] 
     ... Success!
    Cleaning up...
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    Thanks for using MariaDB!
  5. 使用設定的密碼,確認可以登入 mysql。
    [root@ip112 ~]# mysql -uroot -p
    Enter password: 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 10
    Server version: 10.1.20-MariaDB MariaDB Server
    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    MariaDB [(none)]> exit

De-Yu Wang 2018-12-12