文章目录
- 准备工作
-
- 安装相关包
-
- 编译安装 `MariaDB`
- 配置 `MariaDB`
本文主要记录如何在 CentOS 7.6
中编译安装 MariaDB
官方最新的 10.5.9
版本。由于像 Nginx
、 Mysql
和 PHP
的的源码都是用 C/C++
写的,所以自己的 CentOS 7.6
服务器上必须要安装 gcc
和 g++
软件。
搭建 LNMP
环境一般是先安装 Mysql
/MariaDB
,再安装 Nginx
,其次是安装 PHP
准备工作
创建用户和组
先创建一个名为 mysql
且没有登录权限的系统用户和一个名为 mysql
的系统用户组,然后安装 MariaDB
所需的依赖库和依赖包,最后通过 cmake
进行安装的详细配置。
groupadd -r mysql && useradd -c "MariaDB Server" -r -g mysql -s /sbin/nologin -d /usr/local/mariadb mysql -M
创建数据库相关目录
提前预定 MariaDB
的安装目录为 /usr/local/mariadb
并且数据目录为 /data/mariadb
,赋予 mysql
用户权限。
mkdir -pv /data/mariadb && chown -R mysql:mysql /data/mariadb
删除数据库相关文件
find -H /etc/ | grep my.c
> /etc/my.cnf.d
> /etc/my.cnf.d/mysql-clients.cnf
> /etc/pki/tls/certs/make-dummy-cert
> /etc/pki/tls/certs/renew-dummy-cert
> /etc/my.cnf
rm -rf /etc/my.cnf /etc/my.cnf.d/
rpm -qa|grep mariadb*
> mariadb-libs-5.5.60-1.el7_5.x86_64
rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps
安装相关包
安装依赖库
Yum
安装 GCC
、 GCC-C++
的 C/C++
语言编译环境
yum -y install gcc gcc-c++ make autoconf automake libtool
yum -y install openssl openssl-devel ncurses ncurses-devel bison bison-devel boost boost-devel jemalloc jemalloc-devel bzip2 bzip2-devel libxml2 libxml2-devel perl perl-devel lsof libaio-devel libcurl-devel libarchive-devel libevent-devel pcre-devel pcre2-devel zlib-devel kernel-headers kernel-devel zip tar m4 git gnutls-devel
安装编译包
(备用:https://blog.xiaoqy.com/pub/packages/cmake/cmake-3.19.5.tar.gz
)
wget -P '/usr/local/src' https://cmake.org/files/v3.19/cmake-3.19.5.tar.gz \
&& cd /usr/local/src \
&& tar -zxvf cmake-3.19.5.tar.gz -C '/usr/local/src' \
&& cd cmake-3.19.5
./bootstrap
gmake && gmake install
cmake --version
编译安装 MariaDB
(备用:https://blog.xiaoqy.com/pub/packages/mariadb/mariadb-10.5.9.tar.gz
)
wget -P '/usr/local/src' https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.5.9/source/mariadb-10.5.9.tar.gz \
&& cd /usr/local/src \
&& tar -zxvf mariadb-10.5.9.tar.gz -C '/usr/local/src' \
&& cd mariadb-10.5.9
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_UNIX_ADDR=/data/mariadb/mysql.sock \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/data/mariadb \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITHOUT_TOKUDB=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_BOOST=system \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=1
make && make install && cd
配置 MariaDB
/usr/local/mariadb/scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
cp /usr/local/mariadb/support-files/wsrep.cnf /etc/my.cnf
cp /usr/local/mariadb/support-files/mysql.server /etc/rc.d/init.d/mysqld
/etc/rc.d/init.d/mysqld start
echo -e "export PATH=\$PATH:/usr/local/mariadb/bin/" > /etc/profile.d/mysql.sh
chmod 0777 /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
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
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none): # 直接Enter,预设MariaDB没有密码
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y # y,切换到unix_socket身份验证
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y # 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 # 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 # y,移除远端登入权限
... 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 # y,移除测试资料库和账号
- 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 # 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!
systemctl enable mysqld.service && systemctl start mysqld.service
systemctl status mysqld.service
ps -ef | grep mysqld
netstat -anp | grep mysqld
作者:白小七羽
原文链接:https://geek.xiaoqy.com/215.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)