MariaDB-Galera10源碼安裝

MariaDB-Galera10源碼安裝

官方網站MariaDB <wbr><wbr><wbr>yum安裝

https://mariadb.com/node

http://galeracluster.com/mysql

http://mirrors.neusoft.edu.cn/mariadb/mariadb-galera-10.0.14/sourcelinux

http://mirrors.neusoft.edu.cn/mariadb/mariadb-galera-10.0.14/galera-25.3.5/c++

環境:CentOS6.5 x64

一.準備編譯環境
1.卸載linux預裝的mysql-libs
rpm -e --nodeps mysql-libs

2.安裝編譯必備工具及庫
sql

yum -y install gcc gcc-c++  cmake ncurses-devel bison libxml2-devel openssl-devel libevent-devel #必選
數據庫

libaio-devel pam-devel  boost-devel valgrind-devel   #可選
安全

libnl-devel popt-devel popt-static   #其它
app

#libevent-devel提供"event.h"


2、安裝MariaDB-Galerasocket

1.下載相關軟件源碼包tcp

wget --no-check-certificate http://mirrors.neusoft.edu.cn/mariadb/mariadb-galera-10.0.14/source/mariadb-galera-10.0.14.tar.gz
wget --no-check-certificate  http://mirrors.neusoft.edu.cn/mariadb/mariadb-galera-10.0.14/galera-25.3.5/galera-25.3.5-1.rhel6.x86_64.rpm

2.建mysql服務的用戶和用戶組

[root@node2 rhel6]# groupadd mysql
[root@node2 rhel6]# useradd -s /sbin/nologin -g mysql -M mysql
[root@node2 rhel6]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)

3.解壓mariadb-galera到臨時安裝目錄,一般放在/usr/local/src目錄下

[root@node2 ~]# ls
mariadb-galera-10.0.14.tar.gz
[root@node2 ~]# tar -xvf mariadb-galera-10.0.14.tar.gz -C /usr/local/src/


4.經過cmake編譯安裝

[root@node2 ~]# cd /usr/local/src/mariadb-10.0.14/
[root@node2 mariadb-10.0.14]# mkdir rhel6
[root@node2 mariadb-10.0.14]# cd rhel6/
[root@node2 rhel6]# cmake

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_DATADIR=/var/lib/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=1 \
-DWITH_BIG_TABLES=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_SSL=system  ..


[root@node2 rhel6]# make && make install

5.安裝galera

[root@node2 ~]# rpm -ivh galera-25.3.5-1.rhel6.x86_64.rpm
Preparing...                ######################################## [100%]
   1:galera                 ######################################### [100%]
[root@node2 ~]# rpm -ql galera
/etc/init.d/garb
/etc/sysconfig/garb
/usr/bin/garbd
/usr/lib64/galera/libgalera_smm.so
/usr/share/doc/galera/COPYING
/usr/share/doc/galera/LICENSE.asio
/usr/share/doc/galera/LICENSE.chromium
/usr/share/doc/galera/LICENSE.crc32c
/usr/share/doc/galera/README
/usr/share/doc/galera/README-MySQL

三.配置MariaDB

1.將mysql管理調式工具添加到PATH路徑

[root@node2 ~]# echo 'PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile

[root@node2 ~]# source /etc/profile

順道也加一個man記錄
[root@node2 ~]# ls /usr/local/mysql/man/
man1  man8
[root@node2 ~]# echo MANPATH /usr/local/mysql/man >>/etc/man.config

2.初始化mariadb
[root@node2 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql
WARNING: The host 'node1' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
141125 11:39:24 [Note] WSREP: Read nil XID from storage engines, skipping position init
141125 11:39:24 [Note] WSREP: wsrep_load(): loading provider library 'none'
141125 11:39:24 [Note] InnoDB: Using mutexes to ref count buffer pool pages
... ...
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at sales@skysql.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

3.配置/etc/my.cnf和/etc/init.d/mysql

[root@node2 ~]# cp /usr/local/src/mariadb-10.0.14/rhel6/support-files/my-huge.cnf /etc/my.cnf

[root@node2 ~]# cp /usr/local/src/mariadb-10.0.14/rhel6/support-files/mysql.server /etc/init.d/mysql
[root@node2 ~]# chmod +x /etc/init.d/mysql
[root@node2 ~]# ll /etc/init.d/mysql
-rwxr-xr-x. 1 root root 12055 Nov 24 14:25 /etc/init.d/mysql


4.啓服務

[root@node2 ~]# /etc/init.d/mysql start
Starting MySQL. SUCCESS!
[root@node2 ~]# /etc/init.d/mysql status
 
SUCCESS! MySQL running (13372)
[root@node2 ~]# netstat -tunlp|grep mysqld
tcp                      0 0.0.0.0: 3306                              0.0.0.0:*                                    LISTEN          13372/mysqld             
[root@node2 ~]# chkconfig mysql on
[root@node2 ~]# chkconfig --list mysql
mysql                        0:off      1:off      2:on      3:on      4:on      5:on      6:off


5.安全設置

[root@rhel7-test1 ~]# mysql_secure_installation
/usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
 

        SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

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!
這裏設置mariadb的root密碼

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] y
  ... 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] y
  ... Success!
不容許mariadb root用戶遠程登陸
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] y
  - Dropping test database...
  ... Success!
  - Removing privileges on test database...
  ... Success!
刪除test數據庫
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
  ... 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!

也能夠手動完成,
mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by "dbrootpwd" with grant option;" 
mysql -e "grant all privileges on *.* to root@'localhost' identified by "dbrootpwd" with grant option;"
mysql -uroot -pdbrootpwd -e "delete from mysql.user where Password='';"
mysql -uroot -pdbrootpwd -e "delete from mysql.db where User='';"
mysql -uroot -pdbrootpwd -e "drop database test;"


四.測試
[root@node2 ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.0.14-MariaDB-wsrep-log Source distribution, wsrep_25.10.r4144

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+


MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> show engines\G;
*************************** 1. row ***************************
          Engine: CSV
        Support: YES
        Comment: CSV storage engine
Transactions: NO
                  XA: NO
  Savepoints: NO
*************************** 2. row ***************************
          Engine: MRG_MyISAM
        Support: YES
        Comment: Collection of identical MyISAM tables
Transactions: NO
                  XA: NO
  Savepoints: NO
*************************** 3. row ***************************
          Engine: BLACKHOLE
        Support: YES
        Comment: /dev/null storage engine (anything you write to it disappears)
Transactions: NO
                  XA: NO
  Savepoints: NO
*************************** 4. row ***************************
          Engine: Aria
        Support: YES
        Comment: Crash-safe tables with MyISAM heritage
Transactions: NO
                  XA: NO
  Savepoints: NO
*************************** 5. row ***************************
          Engine: MyISAM
        Support: YES
        Comment: MyISAM storage engine
Transactions: NO
                  XA: NO
  Savepoints: NO
*************************** 6. row ***************************
          Engine: MEMORY
        Support: YES
        Comment: Hash based, stored in memory, useful for temporary tables
Transactions: NO
                  XA: NO
  Savepoints: NO
*************************** 7. row ***************************
          Engine: InnoDB
        Support: DEFAULT
        Comment: Percona-XtraDB, Supports transactions, row-level locking, and foreign keys
Transactions: YES
                  XA: YES
  Savepoints: YES
*************************** 8. row ***************************
          Engine: PERFORMANCE_SCHEMA
        Support: YES
        Comment: Performance Schema
Transactions: NO
                  XA: NO
  Savepoints: NO
8 rows in set (0.00 sec)

ERROR: No query specified
MariaDB [(none)]> status;
--------------
mysql  Ver 15.1 Distrib 10.0.14-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:            6
Current database:     
Current user:            root@localhost
SSL:                  Not in use
Current pager:            stdout
Using outfile:            ''
Using delimiter:      ;
Server:                  MariaDB
Server version:            10.0.14-MariaDB-wsrep-log Source distribution, wsrep_25.10.r4144
Protocol version:      10
Connection:            Localhost via UNIX socket
Server characterset:      utf8
Db        characterset:      utf8
Client characterset:      utf8
Conn.  characterset:      utf8
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                  29 min 21 sec

Threads: 3  Questions: 4  Slow queries: 0  Opens: 0  Flush tables: 1  Open tables: 63  Queries per second avg: 0.002
MariaDB [mysql]> quit Bye
相關文章
相關標籤/搜索