10.CentOS 7環境インストールMariaDB(MySQLオープンソース版)

7999 ワード

CentOS 7環境インストールMariaDB(MySQLオープンソース版)
一、MariaDBの概要
1). 説明
MariaDBデータベース管理システムはMySQLのブランチであり、主にオープンソースコミュニティによって維持され、GPLライセンスを採用している.
2). 事前準備
  • にあるcentos 7はMariadbがデフォルトでインストールされており、自分のインストールがあるかどうかを確認することができ、インストールされていないものはインストールを行うことができ、インストールしなくても再インストールをアンインストールすることができます.
  • [root@hadoop000 ~]# yum remove mariadb-server
    [root@hadoop000 ~]# cat /etc/redhat-release
    
    CentOS Linux release 7.4.1708 (Core)
    

    二、設置配置Mariadb
    1).MariaDBのインストール
    yumでインストールすればいいです.簡単で迅速で、mariadb-serverをインストールします.デフォルトはmariadbのインストールに依存します.1つはサービス側で、1つはクライアントです.
    [root@hadoop000 ~]# yum install mariadb-server
    

    2).システムサービスの作成
  • のインストールが完了したら、まずMariaDBサービスをオンにし、起動
  • に設定します.
    [root@hadoop000 ~]# systemctl start mariadb  #     
    [root@hadoop000 ~]# systemctl enable mariadb  #           
    

    3).MariaDB初期化構成
  • 最初のインストールでは、データベースの構成が必要です.コマンドはmysqlと同じ
  • です.
    [root@hadoop000 ~]# mysql_secure_installation
    
  • の構成時に現れる各オプションおよび推奨アクション
  • Enter current password for root (enter for none):  #           root   (      root   ),                 
    
    Set root password? [Y/n]  #     ,y
    
    New password:  #    
    Re-enter new password:  #       
    
    Remove anonymous users? [Y/n]  #       , y
    
    Disallow root login remotely? [Y/n]  #   root    ,n,  y/n,    root    
    
    Remove test database and access to it? [Y/n]  #   test   ,y:  。n:   ,        test   ,     
    
    Reload privilege tables now? [Y/n]  #        ,y。        
    
  • は、
  • にログインできるかどうかをテストします.MariaDB [(none)]>が表示されると、MariaDBデータベースが正常に登録されていることを示します.
    [root@hadoop000 ~]# mysql -u root -p
    Enter password:
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 8
    Server version: 5.5.60-MariaDB MariaDB Server
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MariaDB [(none)]>
    

    4).MariaDB文字セットをutf-8に設定
    vimツールでの構成を推奨
  • は、/etc/my.cnfのファイルを構成する、[mysqld]のラベルの下に、以下の内容
  • を追加する.
    init_connect='SET collation_connection = utf8_unicode_ci'
    init_connect='SET NAMES utf8'
    character-set-server=utf8
    collation-server=utf8_unicode_ci
    skip-character-set-client-handshake
    
  • 構成/etc/my.cnf.d/client.cnfファイルは、[client]ラベルの下に
  • を追加する.
    default-character-set=utf8
    
  • 構成/etc/my.cnf.d/mysql-clients.cnfファイルは、[mysql]ラベルの下に
  • を追加する.
    default-character-set=utf8
    
  • サービス再開
  • [root@hadoop000 ~]# systemctl restart mariadb
    
  • mariadbビュー文字セット
  • にアクセス
    文字セットの設定後の内容
    MariaDB [(none)]> show variables like "%character%";show variables like "%collation%";
    +--------------------------+----------------------------+
    | 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       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)
    
    +----------------------+-----------------+
    | Variable_name        | Value           |
    +----------------------+-----------------+
    | collation_connection | utf8_unicode_ci |
    | collation_database   | utf8_unicode_ci |
    | collation_server     | utf8_unicode_ci |
    +----------------------+-----------------+
    3 rows in set (0.00 sec)
    
    MariaDB [(none)]>
    

    5).ファイアウォール構成の無効化(開発フェーズの推奨)
  • ファイアウォールのステータスを表示する
  • enabledは有効にできることを示します.runningは有効になっていることを示します
    [hadoop@hadoop000 ~]$ systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
       Active: active (running) since Thu 2019-11-28 19:13:33 CST; 1min 41s ago
         Docs: man:firewalld(1)
     Main PID: 18478 (firewalld)
       CGroup: /system.slice/firewalld.service
               └─18478 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
    [hadoop@hadoop000 ~]$    
    
  • ファイアウォール
  • を閉じる
    [hadoop@hadoop000 ~]$ systemctl stop firewalld
    ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
    Authentication is required to manage system services or units.
    Authenticating as: root
    Password:
    ==== AUTHENTICATION COMPLETE ===
    [hadoop@hadoop000 ~]$
    
  • ファイアウォールを無効にし、起動しても自動的に起動しない
  • [hadoop@hadoop000 ~]$ systemctl disable firewalld
    ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ===
    Authentication is required to manage system service or unit files.
    Authenticating as: root
    Password:
    ==== AUTHENTICATION COMPLETE ===
    Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
    Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    ==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ===
    Authentication is required to reload the systemd state.
    Authenticating as: root
    Password:
    ==== AUTHENTICATION COMPLETE ===
    [hadoop@hadoop000 ~]$
    
  • 再検査状態
  • [hadoop@hadoop000 ~]$ systemctl status firewalld
    ● firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
       Active: inactive (dead)
         Docs: man:firewalld(1)
    [hadoop@hadoop000 ~]$
    

    6).ファイアウォール構成オープンポート(本番環境)
    ファイアウォールを閉じないで、ポートの外部リンクを許可します.ステップ3306ポートをオンにし、ファイアウォールを再起動します.
    [root@hadoop000 ~]# systemctl stop firewalld
    
    
    [root@hadoop000 ~]# firewall-cmd --query-port=3306/tcp  #   3306      
    
    [root@hadoop000 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent  #   3306  
    
    [root@hadoop000 ~]# firewall-cmd --reload  #      
    success
    [root@hadoop000 ~]# firewall-cmd --query-port=3306/tcp  #   3306      
    yes
    

    7). リモート・ログインの設定
    MariaDBのデフォルトはrootリモートログインを拒否します.
  • mysqlデータベースのuserテーブル
  • を表示
    [root@hadoop000 ~]# mysql -u root -p  #             
    
    MariaDB [(none)]> use mysql;
    
    MariaDB [mysql]> select host, user from user;
    +-----------+------+
    | host      | user |
    +-----------+------+
    | 127.0.0.1 | root |
    | ::1       | root |
    | hadoop000      | root |
    +-----------+------+
    3 rows in set (0.00 sec)
    
  • ホスト名と等しいフィールドを%に変更し、私のホスト名はhadoop 000です.
  • MariaDB [mysql]> update user set host='%' where host='hadoop000';
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    MariaDB [mysql]> select host, user from user;
    +-----------+------+
    | host      | user |
    +-----------+------+
    | %         | root |
    | 127.0.0.1 | root |
    | localhost | root |
    +-----------+------+
    3 rows in set (0.00 sec)
    
  • 権限テーブルをリフレッシュするか、MariaDBサービス
  • を再起動します.
    MariaDB [mysql]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    [root@hadoop000 ~]# systemctl restart mariadb
    

    注:権限テーブルのリフレッシュはデータベースで、サービスの再起動は外部コマンドラインです.
    三、ユーザーの追加と授権
    rootユーザーは危険すぎるので、アプリアプリは他の一般ユーザーを使って、権限を設定することをお勧めします.
    1). 新規ユーザーの追加と承認
    [hadoop@hadoop000 ~]$ mysql -u root -p
    Enter password:
    ... 
    
    MariaDB [(none)]> create user 'hadoop'@'%' identified by '^_^_^_^';
    MariaDB [(none)]> grant ALL HADOOP_HIVE.* to 'hadoop'@'%';
    

    2). リモートログインテスト