Centos 7.6 源码编译安装 MariaDB 10.5.9

本文主要记录如何在 CentOS 7.6 中编译安装 MariaDB 官方最新的 10.5.9 版本。由于像 NginxMysqlPHP的的源码都是用 C/C++ 写的,所以自己的 CentOS 7.6 服务器上必须要安装 gccg++ 软件。

搭建 LNMP 环境一般是先安装 Mysql/MariaDB ,再安装 Nginx ,其次是安装 PHP

准备工作

创建用户和组

先创建一个名为 mysql 且没有登录权限的系统用户和一个名为 mysql 的系统用户组,然后安装 MariaDB 所需的依赖库和依赖包,最后通过 cmake 进行安装的详细配置。

  • 创建 mysql 系统用户和系统用户组
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

删除数据库相关文件

  • 删除 CentOS 默认数据库配置文件
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/
  • 卸载系统自带 mariadb-libs
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 安装 GCCGCC-C++C/C++ 语言编译环境
yum -y install gcc gcc-c++ make autoconf automake libtool
  • Yum 安装 MariaDB 必须的依赖库
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

安装编译包

  • CMake :编译工具

(备用: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	# 或者 make && make 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

# 使用 mysql 用户执行脚本, 安装数据库到数据库存放目录
/usr/local/mariadb/scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
  • 复制 MariaDB 配置文件到 /etc 目录
# 拷贝 maria 安装目录下 support-files 目录下的文件 wsrep.cnf 到 /etc 目录并重命名为 my.cnf
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
  • 启动 mysqld 服务
/etc/rc.d/init.d/mysqld start
  • 配置环境变量
# 写入环境变量到 mysql.sh
echo -e "export PATH=\$PATH:/usr/local/mariadb/bin/" > /etc/profile.d/mysql.sh

# 为脚本赋于可执行权限
chmod 0777 /etc/profile.d/mysql.sh

# 读取并执行 mysql.sh 脚本, 并执行脚本, 以立即生效环境变量
source /etc/profile.d/mysql.sh
  • 初始化 MariaDB
# 运行 MariaDB 初始化脚本
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!
  • 设置 MariaDB 为自启动并启动服务
systemctl enable mysqld.service && systemctl start mysqld.service
  • 查询 MariaDB 状态
systemctl status mysqld.service

# 或者
ps -ef | grep mysqld
netstat -anp | grep mysqld

作者:白小七羽
原文链接:https://geek.xiaoqy.com/215.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
A:要在CentOS 7.6编译安装FFmpeg,可以按照以下步骤进行操作: 1. 安装基本工具 首先,需要安装一些基本的工具和库。使用以下命令在CentOS 7.6安装这些软件包: ``` yum install -y autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make mercurial pkgconfig zlib-devel ``` 2. 下载最新的FFmpeg源码 从官方网站 https://ffmpeg.org/download.html 下载最新版本的FFmpeg源码压缩包,并将其解压缩到某个目录中。例如: ``` cd /usr/local/src wget https://ffmpeg.org/releases/ffmpeg-4.3.1.tar.bz2 tar -xjvf ffmpeg-4.3.1.tar.bz2 cd ffmpeg-4.3.1 ``` 3. 配置和编译FFmpeg 使用以下命令在CentOS 7.6上配置和编译FFmpeg: ``` ./configure --enable-shared --disable-static make make install ``` 这将启用共享库,并禁用静态库。如果需要使用其他选项,可以在“configure”命令中添加相应的参数。 4. 配置库路径 最后,在使用FFmpeg时需要将库路径配置到环境变量中。使用以下命令将其添加到“/etc/ld.so.conf.d”目录下的新文件中: ``` echo "/usr/local/lib/" >> /etc/ld.so.conf.d/ffmpeg.conf ldconfig -v ``` 这将添加“/usr/local/lib/”到ld.so.conf文件中,并重新加载库缓存。现在应该可以成功使用FFmpeg了。 以上是在CentOS 7.6编译安装FFmpeg的步骤。需要注意的是,具体的操作可能会因为系统环境和其他因素而有所不同。在操作时请认真阅读相关文档,并保证操作安全。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白小七羽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值