1. 程式人生 > >yum安裝Mariadb,二進制安裝Mariadb

yum安裝Mariadb,二進制安裝Mariadb

tun date don file 創建文件 pri rom support 權限

yum安裝Mariadb

設置Mariadb的yum源

vim /etc/yum.repos.d/mariadb.repo  
[mariadb]
name=mariadb
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64/
gpgcheck=0

使用清華yum源安裝Mariadb,可以選擇不同的版本,此處安裝10.2.23
yum install mariadb-server

二進制安裝Mariadb

1 準備mysql用戶和組

groupadd -r -g 336 mysql      #創建mysql組
useradd -r -g mysql -u 336 -s /sbin/nologin -d /data/mysql mysql  #創建mysql用戶,並加入mysql用戶組,設置UID為336,設置默認shell為nologoin,家目錄為/data/mysql 但不自動創建

2 準備二進制程序文件和相關文件屬性

tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local   #只能放在此目錄中
cd /usr/local/
ln -s mariadb-10.2.23-linux-x86_64/ mysql                   #建立軟件鏈接,方便使用
chown -R root.root /usr/local/mysql/                        #設置屬主和屬組為root用戶和root組

3 PATH變量

vim /etc/profile.d/mysql.sh
PATH=/usr/local/mysql/bin:$PATH
. /etc/profile.d/mysql.sh

4 準備數據庫數據目錄和數據(使用邏輯卷)

創建邏輯卷
pvcreate /dev/sda6
創建卷組
vgcreate vg0 /dev/sda6
創建邏輯卷
lvcreate -n mysql -L 20G /dev/vg0
創建文件系統並掛載到/data/mysql
mkfs.xfs /dev/vg0/mysql
mkdir /data/mysql
mount /dev/vg0/mysql /data/mysql
chown mysql.mysql /data/mysql/
cd /usr/local/mysql
./scripts/mysql_install_db --datadir=/data/mysql --user=mysql #安裝mysql到/data/mysql目錄下,用戶為mysql

5 準備Mysql的服務器端配置文件

mkdir /etc/mysql  
cp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf  
vim /etc/mysql/my.cnf  
[mysqld]
datadir=/data/mysql   #設置目錄為/data/mysql

6 準備服務啟動腳本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
systemctl start mysqld

7 安全加固

[[email protected] ~]#/usr/bin/mysql_secure_installation

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     #設置root用戶密碼
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] 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  #禁止root遠程登錄
 ... 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] y    #刪除測試數據庫test
 - 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] 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!

8 測試連接
mysql -uroot -pPASSWORD

yum安裝Mariadb,二進制安裝Mariadb