MariaDB--编译、RPM、二进制安装

MariaDB之编译、RPM、通用二进制安装

]# mount /dev/sr0 /cdrom/
mount: /dev/sr0 is write-protected, mounting read-only

安装开发包组

]# yum groupinstall "Development Tools" -y

安装mariadb所需的组件和cmake

]# yum install ncurses-devel openssl-devel libevent-devel jemalloc-devel cmake

配置数据库LVM分区

]# mkdir /mydata
]# fdisk /dev/sda
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (29378560-41943039, default 29378560): 
Using default value 29378560
Last sector, +sectors or +size{K,M,G} (29378560-41943039, default 41943039):      
Using default value 41943039
Partition 3 of type Linux and of size 6 GiB is set

Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

更新磁盘分区表

]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-3

创建物理卷

]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

配置PE大小为512KB

]# vgcreate testvg -s 512k /dev/sda3
  Volume group "testvg" successfully created

查看PE大小

]# vgdisplay testvg| grep "PE Size"
  PE Size               512.00 KiB

配置逻辑卷大小为5G

]# lvcreate -L 5G -n testlv testvg
  Logical volume "testlv" created

查看逻辑卷信息

]# lvdisplay | grep -A 15 testlv
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                7SBI68-adPq-gdM1-NL0A-x9RS-HDat-eBSH1A
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-05-10 15:08:53 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             10240
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3

格式化逻辑卷文件类型为ext4

]# mke2fs -t ext4 /dev/testvg/testlv

配置为开机自动挂载

]# vim /etc/fstab
/dev/testvg/testlv      /mydata                 ext4    defaults        0 0

mount命令自动挂载并查看是否挂载

]# mount -a
]# mount |grep testlv
/dev/mapper/testvg-testlv on /mydata type ext4 (rw,relatime,seclabel,data=ordered)

新建管理组与管理用户

]# groupadd -r mysql
]# useradd -r -g mysql -s /sbin/nologin mysql
]# grep mysql /etc/passwd
mysql:x:992:990::/home/mysql:/sbin/nologin

编译安装

下载软件包

]# wget http://mirrors.neusoft.edu.cn/mariadb//mariadb-5.5.56/source/mariadb-5.5.56.tar.gz

解压软件包进入目录

]# tar xf mariadb-5.5.56.tar.gz
]# cd mariadb-5.5.56/

查看软件包目录结构

]# ls
BUILD           config.h.cmake   EXCEPTIONS-CLIENT   libmysql     packaging  sql            tests
BUILD-CMAKE     configure.cmake  extra               libmysqld    plugin     sql-bench      unittest
client          COPYING          include             libservices  randgen    sql-common     VERSION
cmake           dbug             INSTALL-SOURCE      man          README     storage        vio
CMakeLists.txt  debian           INSTALL-WIN-SOURCE  mysql-test   regex      strings        win
cmd-line-utils  Docs             KNOWN_BUGS.txt      mysys        scripts    support-files  zlib

执行cmake编译

]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb-5.5.56 -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

编译并安装

]# make &&make install
make命令可使用-j选项,选择使用的核心数,以加快编译速度

cmake详解

cmake指定编译选项的方式不同于make,其实现方式对比如下:
./configure cmake .
./configure --help cmake . -LH or ccmake .

cmake编译选项

指定安装文件的安装路径时常用的选项:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql #指定安装包路径
-DMYSQL_DATADIR=/mydata/data #指定数据存储库路径
-DSYSCONFDIR=/etc #指定配置文件路径
默认编译的存储引擎包括:csv、myisam、myisammrg和heap。若要安装其它存储引擎,可以使用类似如下编译选项:
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
若要明确指定不编译某存储引擎,可以使用类似如下的选项:
-DWITHOUT__STORAGE_ENGINE=1
例如:
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
如若要编译进其它功能,如SSL等,则可使用类似如下选项来实现编译时使用某库或不使用某库:
-DWITH_READLINE=1
-DWITH_SSL=system
-DWITH_ZLIB=system
-DWITH_LIBWRAP=0

其它常用的选项:
-DMYSQL_TCP_PORT=3306 #指定服务端口
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock #指定服务套接字路径
-DENABLED_LOCAL_INFILE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8 #指定字符编码
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0 #指定排错级别
-DENABLE_PROFILING=1

如果想清理此前的编译所生成的文件,则需要使用如下命令:
make clean
rm CMakeCache.txt

链接目录至mysql便于查看管理

]# cd /usr/local/
]# ln -sv mariadb-5.5.56/ mysql
‘mysql’ -> ‘mariadb-5.5.56/’

配置程序包属主属组

]# chown -R root.mysql /usr/local/mysql/

新建数据库目录并配置属主属组

# mkdir -pv /mydata/data
mkdir: created directory ‘/mydata/data’
]# chown -R mysql.mysql /mydata/data

拷贝示例配置文件

]# cp support-files/my-large.cnf /etc/my.cnf

编辑my.cnf配置文件42行

]# vim /etc/my.cnf
[mysqld]
42 datadir=/mydata/data

配置系统环境变量路径

]# vi /etc/profile.d/mysql.sh  
   export PATH=/usr/local/mysql/bin:$PATH  
   # 备注:加入到系统环境变量中   

重新载入配置文件

]# .  /etc/profile.d/mysql.sh
或者source重新载入
]# source /etc/profile.d/mysql.sh

安装数据库并查看生成的目录文件

]# mysql_install_db --user=mysql --datadir=/mydata/data --defaults-file=/etc/my.cnf
]# ls /mydata/data/
aria_log.00000001  aria_log_control  mysql  mysql-bin.000001  mysql-bin.000002  mysql-bin.index  performance_schema  test

编辑启动脚本

]# vim /etc/systemd/system/mariadb.service
[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld_safe  --basedir=/usr/local/mysql
TimeoutSec=300
PrivateTmp=false
[Install]
WantedBy=multi-user.target

重新装载所有守护进程的unit文件,然后重新生成依赖关系树:

]# systemctl daemon-reload 

启动服务并查看状态

]# systemctl start mariadb.service
]# systemctl status mariadb.service
mariadb.service - MariaDB database server
   Loaded: loaded (/etc/systemd/system/mariadb.service; disabled)
   Active: active (running) since Wed 2017-05-10 18:34:20 CST; 13s ago
 Main PID: 35617 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─35617 /bin/sh /usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mysql
           └─35908 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mydata/data --plugin-dir=/usr/local/mysq...

]# ss -tnl |grep 3306
LISTEN     0      50                        *:3306                     *:*     

安全初始化

]# mysql_secure_installation 
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

eload privilege tables now? [Y/n] y
 ... Success!

测试登陆

]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.56-MariaDB Source distribution

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 

RPM安装

挂载镜像,并配置YUM源

]# mount /dev/sr0 /cdr	om
]# vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///cdrom
enabled=1
gpgcheck=0

安装mariadb服务

]# yum install mariadb mariadb-server mariadb-devel -y

启动服务
]# systemctl start mariadb.service

安全初始化

]# mysql_secure_installation 
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

eload privilege tables now? [Y/n] y
 ... Success!

二进制安装

通用二进制安装与编译安装相同,只是少了编译阶段

]# wget http://mirrors.neusoft.edu.cn/mariadb//mariadb-5.5.56/bintar-linux-x86_64/mariadb-5.5.56-linux-x86_64.tar.gz

新建mysql系统用户

]# useradd -r -s /sbin/nologin mysql
]# id mysql
uid=992(mysql) gid=990(mysql) groups=990(mysql)

解压软件包至/usr/local/目录

]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz  -C /usr/local
]# cd /usr/local

链接目录便于查看

]# ln -sv mariadb-5.5.46-linux-x86_64/ mysql
‘mysql’ -> ‘mariadb-5.5.46-linux-x86_64/’

设置目录属主属组

]# chown -R root.mysql /usr/local/mysql/

拷贝示例配置文件

]# cp support-files/my-large.cnf /etc/my.cnf

编辑my.cnf配置文件

]# vi /etc/mysql/my.cnf  
            [mysqld]  
            # [mysqld] 配置里添加这些内容  
            datadir = /mysqldata  
            skip_name_resolve = ON  
            innodb_file_per_table = ON 

配置系统环境变量路径

]# vi /etc/profile.d/mysql.sh  
   export PATH=/usr/local/mysql/bin:$PATH  
   # 备注:加入到系统环境变量中  
]# source /etc/profile.d/mysql.sh  

安装数据库文件

]# mysql_install_db  --user=mysql  --datadir=/mydata/data  --defaults-file=/etc/my.cnf

查看生成的目录文件

]# ls /mydata/data
aria_log.00000001  ib_logfile0                localhost.localdomain.pid  mysql-bin.000002  performance_schema
aria_log_control   ib_logfile1                mysql                      mysql-bin.000003  test
ibdata1            localhost.localdomain.err  mysql-bin.000001           mysql-bin.index

编辑mysql库文件路径

]# vim /etc/ld.so.conf.d/mysql.conf  
            /usr/local/mysql/lib

重新载入库文件

]# ldconfig  

查看载入的mysql库文件

]# ldconfig -p | grep mysql
libmysqld.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqld.so.18
	libmysqld.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqld.so
	libmysqlclient.so.18 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.18
	libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18
	libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so

编辑启动脚本

]# vim /etc/systemd/system/mariadb.service
[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld_safe  --basedir=/usr/local/mysql
TimeoutSec=300
PrivateTmp=false
[Install]
WantedBy=multi-user.target

重新装载所有守护进程的unit文件,然后重新生成依赖关系树:

]# systemctl daemon-reload 重新读取

启动mariadb

]# systemctl start mariadb.service

]# ss -tnl | grep -e "mysql" -e "3306"
LISTEN     0      50                        *:3306                     *:*   

查看服务状态

]# systemctl status mariadb.service
mariadb.service - MariaDB database server
   Loaded: loaded (/etc/systemd/system/mariadb.service; disabled)
   Active: active (running) since Wed 2017-05-10 20:55:06 CST; 2min 12s ago
 Main PID: 4456 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─4456 /bin/sh /usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mysql
           └─4766 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mydata/data --plugin-dir=/usr/local/mysql...

安全初始化

]# mysql_secure_installation 
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

eload privilege tables now? [Y/n] y
 ... Success!

测试登陆

]# 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.46-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> 

posted on 2017-05-10 21:20  architect&*  阅读(309)  评论(0)    收藏  举报

导航