11.6 MariaDB安装



1.下载mariaDB

[root@linux-5 ~]# cd /usr/local/src/
[root@linux-5 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



2.解压

[root@linux-5 src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz



3.将目录重命名

[root@linux-5 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
[root@linux-5 src]# cd /usr/local/mariadb/
[root@linux-5 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



4.创建mysql用户

[root@linux-5 mysql]# useradd -s /sbin/nologin mysql



5.创建存放数据库的目录

[root@linux-5 mysql]# mkdir /data



6.初始化

[root@linux-5 mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb    
//--user=mysql定义mysql身份运行
//--basedir=/usr/local/mariadb 定义mariadb的安装目录,这里如果不定义mariadb的目录有可能系统会去找之前安装的mysql的目录
//--datadir=/data/mariadb定义存放数据库的目录
[root@linux-5 mariadb]# echo $?  
0



7.配置文件

Mariadb的配置文件也在/user/local/mariadb/support-files/目录下,和mysql有一定区别,这个目录下有好几个配置模板

[root@linux-5 mariadb]# ls /usr/local/mariadb/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

my-huge.cnf;my-large.cnf;my-medium.cnf;my-small.cnf这些配置文件的区别就在于缓存数字的大小不一样,这些值是根据内存的大小指定合适的缓存,这样会让mysql达到一个更高效的性能。我们做实验内存是1G 拷贝my-small.cnf就可以,如果你的内存有几十G,可以拷贝my-huge.cnf,再根据实际情况适当调整这些参数。



(1)拷贝配置文件
[root@linux-5 mariadb]# cp support-files/my-small.cnf  /usr/local/mariadb/my.cnf  
//为了和之前mysql的配置文件区别,将配置文件路径修改下。



(2)修改配置文件
[root@linux-5 ~]# vim /usr/local/mariadb/my.cnf
添加basedir和datadir
[mysqld]
basedir = /usr/local/mariadb    //mariadb安装目录
datadir = /data/mariadb		   //存放数据库目录
port            = 3306      
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K

注:如果不添加数据库的存储目录,仅仅在在系统中存在其他数据库时(如MySQL),则mariadb数据库会使用之前数据库中的配置文件里面的数据库的存储目录



8.拷贝启动脚本

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



(1)修改启动脚本
[root@linux-5 ~]# vim /etc/init.d/mariadb
需要修改2个地方
basedir=/usr/local/mariadb     //存放mariadb的目录
datadir=/data/mariadb			//存放数据库的目录
conf=$basedir/my.cnf			//指定配置文件的路径

并且在开始启动脚本中添加上面修改的配置文件路径

mariadb10离线安装 mariadb10.6_开发工具



(2)启动脚本
[root@linux-5 ~]# /etc/init.d/mariadb start
Starting mariadb (via systemctl):                          [  确定  ]

这里要注意:之前安装过mysql,所以在安装mariadb的时候,要先关闭mysqld服务,在启动脚本中指定了配置文件路径conf,并将添加到启动脚本中,如果之前没有装过mysql,可以直接将配置文件拷贝到/etc/my.cnf,启动脚本中也不用指定配置文件路径。



11.7/11.8/11.9 Apache安装



1.下载apache和apr、apr-util

[root@linux-5 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
[root@linux-5 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
[root@linux-5 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2



2.解压

[root@linux-5 src]# tar zxvf apr-1.6.3.tar.gz
[root@linux-5 src]# tar jxvf apr-util-1.6.1.tar.bz2
[root@linux-5 src]# tar zxvf httpd-2.4.29.tar.gz



3.安装apr

[root@linux-5 src]# cd apr-1.6.3
[root@linux-5 apr-1.6.3]# ./configure --prefix=/usr/local/apr    //初始化
…
[root@linux-5 apr-1.6.3]# echo $?    //检查初始化是否正确
0

编译make
[root@linux-5 apr-1.6.3]# make
[root@linux-5 apr-1.6.3]# echo $?    //检查编译是否正确
0

编译安装 make install
[root@linux-5 apr-1.6.3]# make install
…
[root@linux-5 apr-1.6.3]# echo $?    //检查编译安装是否正确
0
[root@linux-5 apr-1.6.3]# ls /usr/local/apr
bin  build-1  include  lib



4.安装apr-util

[root@linux-5 apr-1.6.3]# cd /usr/local/src/apr-util-1.6.1/
初始化
[root@linux-5 apr-util-1.6.1]#  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@linux-5 apr-util-1.6.1]# echo $?
0
编译make
[root@linux-5 apr-util-1.6.1]# 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.1”
make: *** [all-recursive] 错误 1
编译报错,需要安装expat-devel包
[root@linux-5 apr-util-1.6.1]# yum install -y expat-devel

然后重新编译 make
…
[root@linux-5 apr-util-1.6.1]# echo $?
0

编译安装 make install
[root@linux-5 apr-util-1.6.1]# make install
[root@linux-5 apr-util-1.6.1]# echo $?
0
apr/      bin/      games/    lib/      libexec/  mysql/    share/
[root@linux-5 apr-util-1.6.1]# ls /usr/local/apr-util/
bin  include  lib



5.安装apache



(1)初始化
[root@linux-5 apr-util-1.6.1]# cd /usr/local/src/httpd-2.4.33/
[root@linux-5 httpd-2.4.33]# ./configure \   //这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
--prefix=/usr/local/apache2.4 \     //指定安装路径
--with-apr=/usr/local/apr \			//指定apr
--with-apr-util=/usr/local/apr-util \	//指定apr-util
--enable-so \		
//支持动态模块 ;表示启用DSO,意思是把某些功能以模块的形式展现出来,一个功能模块就是一个.so文件,编译完会看到这些文件。
--enable-mods-shared=most   //指定模块most;most绝大多数功能模块

这里出现一个错误:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/ 可以用yum list来查找缺少那个包

[root@linux-5 httpd-2.4.33]# yum list |grep pcre
pcre.x86_64                               8.32-15.el7_2.1              @anaconda
ghc-pcre-light.x86_64                     0.4-13.el7                   epel
ghc-pcre-light-devel.x86_64               0.4-13.el7                   epel
mingw32-pcre.noarch                       8.38-1.el7                   epel
mingw32-pcre-static.noarch                8.38-1.el7                   epel
mingw64-pcre.noarch                       8.38-1.el7                   epel
mingw64-pcre-static.noarch                8.38-1.el7                   epel
pcre.i686                                 8.32-17.el7                  base
pcre.x86_64                               8.32-17.el7                  base
pcre-devel.i686                           8.32-17.el7                  base
pcre-devel.x86_64                         8.32-17.el7                  base
pcre-static.i686                          8.32-17.el7                  base
pcre-static.x86_64                        8.32-17.el7                  base
pcre-tools.x86_64                         8.32-17.el7                  base
pcre2.i686                                10.23-2.el7                  base
pcre2.x86_64                              10.23-2.el7                  base
pcre2-devel.i686                          10.23-2.el7                  base
pcre2-devel.x86_64                        10.23-2.el7                  base
pcre2-static.i686                         10.23-2.el7                  base
pcre2-static.x86_64                       10.23-2.el7                  base
pcre2-tools.x86_64                        10.23-2.el7                  base
pcre2-utf16.i686                          10.23-2.el7                  base
pcre2-utf16.x86_64                        10.23-2.el7                  base
pcre2-utf32.i686                          10.23-2.el7                  base
pcre2-utf32.x86_64                        10.23-2.el7                  base

[root@linux-5 httpd-2.4.33]# yum install -y pcre-devel



(2)然后重新编译参数
[root@linux-5 httpd-2.4.33]# ./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@linux-5 httpd-2.4.33]# echo $?
0



(3)编译make&&安装make install
[root@linux-5 httpd-2.4.33]# make

此时编译出现一个错误

mariadb10离线安装 mariadb10.6_linux_02

经查询相关资料后,将apr-util重新初始化并编译一次即可解决。

再次重新编译并安装apache

[root@linux-5 httpd-2.4.33]# make
[root@linux-5 httpd-2.4.33]# make install
[root@linux-5 apr-util-1.5.2]# cd /usr/local/apache2.4/
[root@linux-5 apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

这里介绍一个进程用到的目录
bin :可执行文件的目录
conf:配置文件的目录
htdocs:默认访问网站的目录
logs:日志文件的目录
modules:存放动态模块的目录;也就是.so文件,每一个模块就代表这一个功能

启动/停止apache

[root@linux-5 apache2.4]# /usr/local/apache2.4/bin/apachectl start
[root@linux-5 apache2.4]# /usr/local/apache2.4/bin/apachectl stop

查看apache都加载了那些模块

[root@linux-5 apache2.4]# /usr/local/apache2.4/bin/apachectl -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::fdb8:14ca:d41b:3dc8. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:   	//这里不用管它
 core_module (static)   //static 表示静态模块
 so_module (static)     
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)    //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)

动态和静态模块的区别:静态模块(static)直接和主程序(/usr/local/apache2.4/bin/httpd)绑定在一起,动态模块(shared)都是一个个独立存在的文件(moudles目录下面的.so文件)这些动态模块不会全部加载,如果想用哪个动态模块,直接在配置文件里面配置即可。