LAMP架构mariadb/apache的安装及基本使用

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 05:44:22
 
11月12日任务
11.6 MariaDB安装
11.7/11.8/11.9 Apache安装
 

MariaDB安装(类似于mysql安装)

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

  1. 解压二进制已编译包
[root@localhost src]# tar zxf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz 
  1. 移动至/usr/local/下
[root@localhost src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
[root@localhost local]# cd mariadb/
  1. 初始化脚本,指定basedir和datadir
# 这里跟mysql安装不同的地方是需要额外指定basedir

[root@localhost mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in '/data/mariadb' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/local/mariadb//bin/mysqladmin' -u root password 'new-password'
'/usr/local/mariadb//bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'/usr/local/mariadb//bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr/local/mariadb/' ; /usr/local/mariadb//bin/mysqld_safe --datadir='/data/mariadb'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mariadb//mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
  1. 拷贝配置文件(按服务器内存选择,这里测试选择my-small.cnf
# 这里是实现mysql和mariadb同存于一个机器中的做法
# 如果你的主机内只有mariadb,那么直接复制到/etc命令下,命名为my.cnf也行;对于的basedir也同样修改即可
[root@localhost mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
[root@localhost mariadb]# vi /usr/local/mariadb/my.cnf 
在[mysqld]下插入下面的内容
basedir=/usr/local/mariadb
datadir=/data/mariadb
  1. 拷贝启动脚本至/etc/init.d/目录下,并修改内容
[root@localhost mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
[root@localhost mariadb]# vi /etc/init.d/mariadb 
修改内容
basedir=/usr/local/mariadb
datadir=/data/mariadb
confdir=$basedir/my.cnf    #新增

并在下面启动项内添加--defaults-file选项加载指定的配置文件
$bindir/mysqld_safe --defaults-file="$confdir" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
  1. 启动脚本并验证是否成功
[root@localhost mariadb]# /etc/init.d/mariadb start
Reloading systemd:                                         [  确定  ]
Starting mariadb (via systemctl):                          [  确定  ]

[root@localhost mariadb]# ps aux | grep mysql
root       3466  0.5  0.1 115392  1736 ?        S    13:04   0:00 /bin/sh /usr/local/mariadb//bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/localhost.localdomain.pid
mysql      3588 12.7  5.7 1125028 57864 ?       Sl   13:04   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/localhost.localdomain.err --pid-file=/data/mariadb//localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root       3624  0.0  0.0 112676   972 pts/0    S+   13:04   0:00 grep --color=auto mysql

注意第4步中拷贝、重命名配置文件的过程你可以任意存储,只要在启动脚本内指定好配置文件的路径,就可以安装启动成功。

安装apache

apache是一个基金会的名字,httpd才是要安装的软件包,其早期名字为apache。

Apache官网 www.apache.org

软件包下载地址

由于软件更新,下面的地址链接截止为...
到http://mirrors.cnnic.cn/apache/查看当前版本号

httpd:      http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.28.tar.gz 
apr:       http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
apr-util:   http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz 

软件安装

apr和apr-util

  1. 先安装apr
[root@localhost src]# tar -zxvf apr-1.6.3.tar.gz
[root@localhost src]# cd apr-1.6.3/
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr

# 判断是否编译成功
[root@localhost src]# echo $?
0
[root@localhost src]# make && make install
  1. 安装apr-util
[root@localhost src]# tar -zxvf apr-util-1.6.1.tar.gz 
[root@localhost src]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/loca/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# echo $?
0
[root@localhost src]# make && make install
  1. 安装apache2.4
[root@localhost src]# tar -zxvf httpd-2.4.28.tar.gz
[root@localhost src]# cd httpd-2.4.28
[root@localhost httpd-2.4.28]# ./configure --prefix=/usr/local/apache2.4  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@localhost httpd-2.4.28]# echo $?
0
[root@localhost httpd-2.4.28]# make && make install

编译参数说明:

--enable-so 支持动态扩展模块
如php模块,其实质为一个.so文件,通过apache的配置文件制定php模块位置,来加载php,在apache需要php解析时才调用。
--enable-mods-shared=most 允许大多数的模块扩展到apache主进程

查看编译时的参数

[root@localhost ~]# cat /usr/local/apache/build/config.nice 
#! /bin/sh
#
# Created by configure

"./configure" \
"--prefix=/usr/local/apache" \
"--with-apr=/usr/local/apr" \
"--with-apr-util=/usr/local/apr-util/" \
"--enable-so" \
"--enable-mods-shared=most" \
"$@"

apache文件目录说明

  1. bin目录
# apache二进制文件存放目录
[root@localhost apache2.4]# ls bin/
ab         checkgid   envvars-std   htdbm     httpd       rotatelogs
apachectl  dbmmanage  fcgistarter   htdigest  httxt2dbm
apxs       envvars    htcacheclean  htpasswd  logresolve

  1. conf目录
# apache配置文件存放目录
[root@localhost apache2.4]# ls conf/
extra  httpd.conf  magic  mime.types  original

  1. htdocs目录
# 访问apache网络服务时的默认网页存放目录
[root@localhost apache2.4]# ls htdocs/
index.html

  1. modules目录
# apache可加载模块文件存放目录
[root@localhost apache2.4]# ls modules/
httpd.exp                   mod_lbmethod_heartbeat.so
mod_access_compat.so        mod_log_config.so
mod_actions.so              mod_log_debug.so
mod_alias.so                mod_logio.so
mod_allowmethods.so         mod_macro.so
mod_auth_basic.so           mod_mime.so
mod_auth_digest.so          mod_negotiation.so
mod_auth_form.so            mod_proxy_ajp.so
mod_authn_anon.so           mod_proxy_balancer.so
mod_authn_core.so           mod_proxy_connect.so
...

查看当前已加载模块

# 其中static为已经编译进二进制文件bin/httpd内的模块;
# shared为动态加载模块,需要在编译时添加参数--enable-so
[root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl -M
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)

启动/关闭apache

# 启动
[root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl start

[root@localhost apache2.4]# ps aux | grep httpd
root      40316  0.1  0.2  70908  2204 ?        Ss   19:44   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    40317  0.0  0.4 359872  4256 ?        Sl   19:44   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    40318  0.0  0.4 359872  4256 ?        Sl   19:44   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    40319  0.0  0.4 359872  4256 ?        Sl   19:44   0:00 /usr/local/apache2.4/bin/httpd -k start
root      40402  0.0  0.0 112680   972 pts/0    R+   19:44   0:00 grep --color=auto httpd

[root@localhost 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      1598/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2415/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      1968/mysqld         
tcp6       0      0 :::80                   :::*                    LISTEN      40316/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      1598/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2415/master         

# 关闭
[root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl stop

软件安装时可能会遇到的问题

  1. ./configure编译apr时提示(不是错误):
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands

[root@localhost apr-1.6.3]# echo $?
0
  1. make安装apr-util时报错:
xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录
 #include <expat.h>
                   ^
编译中断。

解决:缺少expat-devel包

yum install -y expat-devel
  1. ./configure httpd时报错:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

解决:缺少prce库(正则相关的库)

yum install -y pcre-devel
  1. make http时报错:
...
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.28/support”
make[1]: *** [all-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.28/support”
make: *** [all-recursive] 错误 1

解决:安装libxml2-devel包

详细步骤参见:https://my.oschina.net/LuCastiel/blog/1590706

可能缺少的软件包

编译安装前提

yum install -y gcc gcc-c++

安装apr/apr-util/httpd

yum install -y expat-devel pcre-devel
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!