码迷,mamicode.com
首页 > 数据库 > 详细

2.MariaDB和Apache安装

时间:2018-03-02 10:56:13      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:MariaDB   Apache   

[toc]

MariaDB安装

11.6 MariaDB安装

1.下载安装包到统一目录/usr/local/src/

[root@xavi ~]# cd /usr/local/src/
[root@xavi src]#wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz

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

[root@xavi src]# yum install -y lrzsz 
[root@xavi src]# rz

2.解压二进制安装包并移动至/usr/local下

[root@xavi src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
[root@xavi src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb

3.初始化,指定basedir和datadir

3.1 这里说下进入/usr/local/mariadb/的三种方法

①.cd /usr/local/mariadb/

②.cd $! //上一条指令移动到的位置就是该路径,所有可实现

③.cd ../mariab //当前src的路径和mariab相同所以能实现

[root@xavi src]# cd /usr/local/mariadb/ 
[root@xavi mariadb]# ./scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mariadb --datadir=/data/mariadb

3.2 初始化之后查看是否成功,只出现1个OK,再用echo $?确认是否错误

技术分享图片

[root@xavi mariadb]# echo $?
0

3.3 对比mariadb和mysql的数据存储目录

[root@xavi mariadb]# ls /data/mariadb/
aria_log.00000001  ibdata1      mysql
aria_log_control   ib_logfile0  performance_schema
ib_buffer_pool     ib_logfile1  test

[root@xavi mariadb]# ls /data/mysql/
auto.cnf     localhost.localdomain.err  xavi.err
ibdata1      mysql                      xavi.pid
ib_logfile0  performance_schema
ib_logfile1  test

4.拷贝配置文件并编辑(my-small.cnf)

4.1 查看下该路径下有哪些文件/support-files/找到my-small.cnf

[root@xavi mariadb]# ls
bin                 data               include         mysql-test    share
COPYING             DESTINATION        INSTALL-BINARY  README.md     sql-bench
COPYING.thirdparty  docs               lib             README-wsrep  support-files
CREDITS             EXCEPTIONS-CLIENT  man             scripts

进入support-files目录,发现其和mysql下的support-files是有区别的

[root@xavi mariadb]# ls support-files/
binary-configure  my-innodb-heavy-4G.cnf  my-small.cnf         mysql.server  wsrep_notify
magic             my-large.cnf            mysqld_multi.server  policy
my-huge.cnf       my-medium.cnf           mysql-log-rotate     wsrep.cnf

技术分享图片

4.2 my-small.cnf的作用根据你的内存大小,合理分配,根据系统运行情况

[root@xavi mariadb]# vim support-files/my-small.cnf

打开后有很多参数
技术分享图片

[root@xavi mariadb]# free
              total        used        free      shared  buff/cache   available
Mem:        1867292      625788      973228        9120      268276     1045700
Swap:       3905532           0     3905532

4.3把my-small.cnf拷贝到/usr/local/mariadb/my.cnf,编辑指定basedir和datadir

[root@xavi mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf

技术分享图片

技术分享图片

basedir=/usr/local/mariadb
datadir=/data/mariadb

技术分享图片

5.拷贝启动脚本至/etc/init.d/目录下,并修改内容

[root@xavi mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
[root@xavi mariadb]# vim /etc/init.d/mariadb

技术分享图片

技术分享图片

技术分享图片

[root@xavi mariadb]# ps aux |grep mysql
root       1073  0.0  0.0 115392  1668 ?        S    20:39   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/xavi.pid
mysql      1354  0.2 24.5 1368672 458540 ?      Sl   20:39   0:11 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/xavi.err --pid-file=/data/mysql/xavi.pid
root       3762  0.0  0.0 112676   976 pts/0    S+   21:55   0:00 grep --color=auto mysql
[root@xavi mariadb]# ps aux |grep mariadb
root       3764  0.0  0.0 112676   972 pts/0    S+   21:55   0:00 grep --color=auto mariadb

6.启动mariadb:/etc/init.d/mariadb start或者service mariadb start

[root@xavi mariadb]# /etc/init.d/mariadb start
Reloading systemd:                                         [  确定  ]
Starting mariadb (via systemctl):                          [  确定  ]
[root@xavi mariadb]# ps aux |grep mariadb
root       3693  0.0  0.0 112676   972 pts/0    S+   21:50   0:00 grep --color=auto mariadb

6.1 这里出现了错误,有可能是mysql服务没有关,查看一下:ps aux |grep mysql

[root@xavi mariadb]# ps aux |grep mysql
root       1073  0.0  0.0 115392  1668 ?        S    20:39   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/xavi.pid
mysql      1354  0.2 24.5 1302876 458540 ?      Sl   20:39   0:10 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/xavi.err --pid-file=/data/mysql/xavi.pid
root       3478  0.0  0.0 112676   976 pts/0    S+   21:48   0:00 grep --color=auto mysql

6.2 先把mysql服务关闭,然后打开mariadb

[root@xavi mariadb]# service mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@xavi mariadb]# service mariadb start
Starting mariadb (via systemctl):                          [  确定  ]

6.3 再次查看ps aux |grep mariadb

[root@xavi mariadb]# ps aux |grep mariadb
root       3990  0.1  0.0 115392  1720 ?        S    22:06   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/xavi.pid
mysql      4112  1.4  3.1 1585872 58176 ?       Sl   22:06   0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/xavi.err --pid-file=/data/mariadb/xavi.pid --socket=/tmp/mysql.sock --port=3306

6.4 netstat -lntp查看3306端口

[root@xavi mariadb]# 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:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2183/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1045/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1044/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1597/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      4112/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::22                   :::*                    LISTEN      1045/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1044/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1597/master  

有疑问的是?

技术分享图片
这个无法解释,单从3306端口来看mariadb应该是启动了

killall mysqld先杀死全部mysqld进程,mysql和mariadb用的都是一个端口且mysqld进程program.

[root@xavi mariadb]# killall mysqld
[root@xavi mariadb]# ps aux |grep mysql
root       4566  0.0  0.0 112676   976 pts/0    R+   22:39   0:00 grep --color=auto mysql
[root@xavi mariadb]# service mariadb start
Starting mariadb (via systemctl):                          [  确定  ]

修改主机名字

[root@localhost ~]# hostnamectl set-hostname xavi
[root@localhost ~]# 
[root@localhost ~]# init 6

重启后,即[root@xavi ~]#

11.7~11.9 Apache安装

1. 下载所需源码包到指定目录/usr/local/src

[root@xavi mariadb]# cd /usr/local/src
[root@xavi src]#  wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz   //2.4源码包
[root@xavi  src]#  wget  http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz       //apr-1.6.3r包
[root@xavi src]#  wget  http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz  //apr-util-1.6.1包

1.1 查看是否都已下载完全:ls

[root@xavi src]# ls
apr-1.6.3              httpd-2.4.29.tar.gz
apr-1.6.3.tar.gz       mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-util-1.6.1         mysql-5.5.55
apr-util-1.6.1.tar.gz  mysql-5.5.55.tar.gz
httpd-2.4.29           mysql-5.6.36-linux-glibc2.5-x86_64.tar.g

2.解压源码包

[root@xavi src]# tar zxvf httpd-2.4.29.tar.gz 
[root@xavi src]# tar zxvf apr-1.6.3.tar.gz 
[root@xavi src]# tar zxvf apr-util-1.6.1.tar.gz

3.安装源码包

3.1 安装apr包:#./configure --prefix=/usr/local/apr

[root@xavi apr-1.6.3]# ./configure --prefix=/usr/local/apr    //执行配置命令
[root@xavi apr-1.6.3]# echo $?
0 //确认有无错误
进行编译安装:make && make install
[root@xavi apr-1.6.3]# make && make install

3.3 安装apr-unit包

查看apr下有4个目录

[root@xavi apr-1.6.3]# ls /usr/local/apr
bin  build-1  include  lib

打开一个apr目录:为什么是1.6.1??

[root@xavi apr-1.6.3]# cd ../apr-util-1.6.5/
-bash: cd: ../apr-util-1.6.5/: //没有那个文件或目录
[root@xavi apr-1.6.3]# cd ../apr-util-1.6.1/

[root@xavi apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@xavi apr-util-1.6.1]# make && make install
出现了错误:expat.h:没有那个文件或目录
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.1”
make: *** [all-recursive] 错误 1
从描述确实文件,重新安装下和expat*相关的软件包
[root@xavi apr-util-1.6.1]# yum install -y expat*

技术分享图片

再次安装make && make install,在apr-util/下生产了3个子目录

技术分享图片

[root@xavi apr-util-1.6.1]# echo $?
0
[root@xavi apr-util-1.6.1]# ls /usr/local/apr-util/  
bin  include  lib

3.7 安装httpd包,回到src目录下

[root@xavi apr-util-1.6.1]# cd ..
[root@xavi src]# cd httpd-2.4.29 

配置apache2.4: ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/loccal/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most

[root@xavi httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/loccal/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/
解决报错:yum list |grep pcre
[root@xavi httpd-2.4.29]# yum list |grep pcre
安装:yum install -y pcre--devel
[root@xavi httpd-2.4.29]# yum install -y pcre--devel

安装成功

技术分享图片

[root@xavi local]# cd /usr/local/src
[root@xavi src]# ls
apr-1.6.3              httpd-2.4.29.tar.gz
apr-1.6.3.tar.gz       mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-util-1.6.1         mysql-5.5.55
apr-util-1.6.1.tar.gz  mysql-5.5.55.tar.gz
httpd-2.4.29           mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@xavi src]# cd /usr/local/src/apr-util-1.6.1
[root@xavi apr-util-1.6.1]# make clean

技术分享图片

报错:
技术分享图片

在configure后加上 “--with-included-apr”。再重新编译, make, make install. 即可。

问题又来了,加上--with-included-apr之后,编译,报错如下:

configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

错误为:apr,apr-util缺失,需要下载并解压到./srclib/目录下

解决办法:
#cd /usr/local/src/# cp -r apr-1.5.2 /usr/local/src/httpd-2.4.7/srclib/apr

#cp -r apr-util-1.5.4 /usr/local/src/httpd-2.4.7/srclib/apr-util

2.MariaDB和Apache安装

标签:MariaDB   Apache   

原文地址:http://blog.51cto.com/12995218/2074501

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!