MariaDB和 Apache安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MariaDB和 Apache安装相关的知识,希望对你有一定的参考价值。

11.6 MariaDB安装

准备工作

因为MariaDB的二进制包镜像源在国外地址,所以预先下载了该包到本地物理机,使用lrzsz工具将该包上传至虚拟机/usr/local/src目录进行安装。

先安装lrzsz工具:
[[email protected] src]# yum install -y lrzsz

上传本地包到虚拟终端:
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# ls
mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[[email protected] src]# rz

[[email protected] src]# ls
mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
安装MariaDB

初始化

解压包:
[[email protected] mariadb]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz

[[email protected] src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
[[email protected] src]# cd /usr/local/mariadb

初始化:
[[email protected] mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
配置MariaDB

[[email protected] mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf

[[email protected] mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
配置启动脚本:

[[email protected] mariadb]# vim /etc/init.d/mariadb
basedir=/usr/local/mariadb
datadir=/data/mariadb
conf=$basedir/my.cnf
mark

启动mariadb服务

检测mysql服务是否在运行:
[[email protected] mariadb]# ps aux |grep mysql
root 1326 0.0 0.0 115376 612 ? S 16:42 0:00 /bin/sh /usr/local/mysql/b
mysql 1848 0.1 44.9 981244 453044 ? Sl 16:42 0:19 /usr/local/mysql/bin/mysqlysql --log-error=/data/mysql/centos-01.err --pid-file=/data/mysql/centos-01.pid --socket=/t
root 2780 0.0 0.0 112664 972 pts/1 R+ 21:48 0:00 grep --color=auto mysql

因mysql和Mariadb监听同一端口,为避免冲突,所以需要先关不mysql服务:
[[email protected] mariadb]# systemctl stop mysql

启动mariadb服务:
[[email protected] mariadb]# /etc/init.d/mariadb start
Reloading systemd: [ 确定 ]
Starting mariadb (via systemctl): [ 确定 ]
注: 如果系统中只安装mysql和mariadb其中一种服务,可以直接把启动脚本放在/etc/文件中设置开机启动。

11.7-11.9 Apache安装

Apache是一个基金会的名字,httpd才是我们要安装的软件包,早期它的名字就叫apache。httpd使用一个通用函数库Apr和apr-util,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)。
Apache官网 www.apache.org 。

httpd2.2和httpd2.4所所使用的Apr库不同,而且centos7系统自带的Apr与之不匹配,所以需要使用yum安装Apr库文件。

准备工作

下载所需要的包

Apache包:
[[email protected] src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz

Apr包:
[[email protected] src]# wget http://mirrors.hust.edu.cn/apache/apr/apr-1.5.2.tar.gz

Apr-util包:
[[email protected] src]# wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
解压包

[[email protected] src]# tar zxvf httpd-2.4.27.tar.gz

[[email protected] src]# tar zxvf apr-1.5.2.tar.gz

[[email protected] src]# tar zxvf apr-util-1.5.4.tar.gz
安装Apr包

[[email protected] src]# cd apr-1.5.2
配置:
[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr

报错:
configure: error: in /usr/local/src/apr-1.5.2‘:<br/>configure: error: no acceptable C compiler found in $PATH<br/>Seeconfig.log‘ for more details
说明:缺少C语言相关的编译器。

解决办法:
[[email protected] apr-1.5.2]# yum install -y gcc*
安装gcc编译器。

[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr

配置成功!

编译和安装:
[[email protected] apr-1.5.2]# make

报错:
xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
#include <expat.h>
^
编译中断。
make[1]: [xml/apr_xml.lo] 错误 1
make[1]: 离开目录“/usr/local/src/apr-util-1.6.0”
make:
[all-recursive] 错误 1

解决办法:
[[email protected] apr-util-1.6.0]# yum -y install expat-devel

[[email protected] apr-1.5.2]# make && make install
[[email protected] apr-1.5.2]# echo $?
0
完成!
注意: APR 1.6.2版本有变更,进行了加密设置,进行编译时需要使用如下命令(否则在安装Apache是无法调用该库文件):

[[email protected] httpd-2.4.27]# CC="gcc -m64" ./configure --prefix=/usr/local/apr
安装Apr-util包

[[email protected] src]# cd apr-util-1.5.4
配置:
[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[[email protected] apr-util-1.5.4]# echo $?
0

编译和安装:
[[email protected] apr-util-1.5.4]# make && make install
完成!
安装httpd

[[email protected] src]# cd httpd-2.4.27
配置:

[[email protected] httpd-2.4.27]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most

报错:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
说明:需要安装库文件pcre

解决办法:
##查看相关的包
[[email protected] httpd-2.4.27]# yum list |grep pcre
(结果不展示)

根据搜索的结果安装下面的包:
[[email protected] httpd-2.4.27]# yum install -y pcre-devel

[[email protected] httpd-2.4.27]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[[email protected] httpd-2.4.27]# echo $?
0
配置完成!
编译和安装

[[email protected] httpd-2.4.27]# make
此过程 时间较长!

[[email protected] httpd-2.4.27]# make install
[[email protected] httpd-2.4.27]# echo $?
0
安装完成!
启动服务

切换至Apache2.4目录:

[[email protected] httpd-2.4.27]# cd /usr/local/apache2.4
[[email protected] apache2.4]# ls
bin build cgi-bin conf error htdocs icons include logs man manual modules
注:较常用目录bin(可执行文件存放目录)、conf(配置文件所在目录)、htdocs(存放一个访问页)、logs(日志文件存放目录)、modules(存放扩展模块)。

查看Apache所加载的模块:
[[email protected] apache2.4]# /usr/local/apache2.4/bin/httpd -M
或者
[[email protected] apache2.4]# /usr/local/apache2.4/bin/apachectl -M

启动:

[[email protected] apache2.4]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using fe80::65d2:adc:20d3:8c74. Set the ‘ServerName‘ directive globally to suppress this message
#此处错误提示没影响。

检测状态:
[[email protected] apache2.4]# ps aux |grep httpd
root 51085 0.0 0.2 95476 2532 ? Ss 04:00 0:00 /usr/local/apache2.4/binhttpd -k start
daemon 51086 0.0 0.4 382304 4424 ? Sl 04:00 0:00 /usr/local/apache2.4/binhttpd -k start
daemon 51087 0.0 0.4 382304 4428 ? Sl 04:00 0:00 /usr/local/apache2.4/binhttpd -k start
daemon 51088 0.1 0.4 382304 4432 ? Sl 04:00 0:00 /usr/local/apache2.4/binhttpd -k start
root 51185 0.0 0.0 112668 972 pts/2 S+ 04:02 0:00 grep --color=auto httpd
[[email protected] apache2.4]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0: LISTEN 836/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:
LISTEN 1975/master
tcp6 0 0 :::3306 ::: LISTEN 20596/mysqld
tcp6 0 0 :::80 :::
LISTEN 51085/httpd
tcp6 0 0 :::22 ::: LISTEN 836/sshd
tcp6 0 0 ::1:25 :::
LISTEN 1975/master

以上是关于MariaDB和 Apache安装的主要内容,如果未能解决你的问题,请参考以下文章

安装mariadb和apache服务

安装mariadb和apache

安装MariaDB和Apache

MariaDB安装,Apache安装

安装MariaDB和Apache

MariaDB和 Apache安装