11.6 MariaDB 安装
mariadb 是 mysql 的一个分支
. 下载 MariaDB 二进制安装包:
- [root@localhost local]# cd src/
- [root@localhost 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
(下载过程略)
[root@localhost src]# ll
总用量 859696
-rw-r--r--. 1 root root 0 1 月 6 22:20 ]
drwxr-xr-x. 12 1001 1001 4096 1 月 6 22:39 httpd-2.2.34
-rw-r--r--. 1 root root 7684419 7 月 10 2017 httpd-2.2.34.tar.gz
-rw-r--r--. 1 root root 541295045 5 月 16 2017 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
-rw-r--r--. 1 root root 316320366 3 月 18 2017 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 17 mysql mysql 4096 1 月 6 23:10 php-5.6.30
-rw-r--r--. 1 root root 15011816 1 月 19 2017 php-5.6.30.tar.bz2
. 解压安装包:
[root@localhost src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
(过程省略)
[root@localhost src]# ll
总用量 859700
-rw-r--r--. 1 root root 0 1 月 6 22:20 ]
drwxr-xr-x. 12 1001 1001 4096 1 月 6 22:39 httpd-2.2.34
-rw-r--r--. 1 root root 7684419 7 月 10 2017 httpd-2.2.34.tar.gz
drwxrwxr-x. 14 1021 1004 4096 5 月 16 2017 mariadb-10.2.6-linux-glibc_214-x86_64
-rw-r--r--. 1 root root 541295045 5 月 16 2017 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
-rw-r--r--. 1 root root 316320366 3 月 18 2017 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 17 mysql mysql 4096 1 月 6 23:10 php-5.6.30
-rw-r--r--. 1 root root 15011816 1 月 19 2017 php-5.6.30.tar.bz2
. 将解压出的目录移动到 /usr/local/ 下并改名为 mariadb
- [root@localhost src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
- [root@localhost src]# cd ..
- [root@localhost local]# cd mariadb/
- [root@localhost mariadb]# ll
总用量 176
drwxr-xr-x. 2 1021 1004 4096 4 月 27 2017 bin
-rw-r--r--. 1 1021 1004 17987 5 月 15 2017 COPYING
-rw-r--r--. 1 1021 1004 86263 5 月 15 2017 COPYING.thirdparty
-rw-r--r--. 1 1021 1004 2271 5 月 15 2017 CREDITS
drwxrwxr-x. 3 1021 1004 18 5 月 16 2017 data
drwxrwxr-x. 2 1021 1004 31 5 月 16 2017 DESTINATION
drwxrwxr-x. 2 1021 1004 81 5 月 16 2017 docs
-rw-r--r--. 1 1021 1004 8245 5 月 15 2017 EXCEPTIONS-CLIENT
drwxrwxr-x. 3 1021 1004 19 5 月 16 2017 include
-rw-r--r--. 1 1021 1004 8694 5 月 15 2017 INSTALL-BINARY
drwxr-xr-x. 4 1021 1004 216 5 月 3 2017 lib
drwxrwxr-x. 4 1021 1004 30 5 月 16 2017 man
drwxrwxr-x. 11 1021 1004 4096 5 月 16 2017 mysql-test
-rw-r--r--. 1 1021 1004 2371 5 月 15 2017 README.md
-rw-r--r--. 1 1021 1004 19510 5 月 15 2017 README-wsrep
drwxrwxr-x. 2 1021 1004 30 5 月 16 2017 scripts
drwxrwxr-x. 29 1021 1004 4096 5 月 16 2017 share
drwxrwxr-x. 4 1021 1004 4096 5 月 16 2017 sql-bench
drwxrwxr-x. 3 1021 1004 275 5 月 16 2017 support-files
. 初始化:
[root@localhost mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
(过程略)
- [root@localhost mariadb]# echo $?
- 0
(如果不定义 basedir 可能去找 mysql, 那么命令为 / scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb)
.support-files 中 my-small.cnfmy-large.cnfmy-medium.cnfmy-huge.cnf 区别在于参数大小不同, 根据内存大小不同, 指定合适的缓存, 让 mysql 达到更高效的性能, 做实验的虚拟机内存不大, 因此使用 small 即可
拷贝模板(为了和 mysql 区分, 拷贝到其他目录):
- [root@localhost mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
- [root@localhost mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
my.cnf 基本不用更改, 直接可用
修改启动配置 / etc/init.d/mariadb
(因为 maria 的 my.cnf 要和 mysql 的 my.cnf 区分开, 因此单独定义一个 conf, 如果机器没有安装 mysql, 那么可以不用定义, 并且可以将 my.cnf 放在 /etc/ 下)
找到 start 启动参数, 增加 conf
. 打开服务前, 确认关闭 mysqld 服务:
- [root@localhost mariadb]# ps aux | grep mysqld
- root 2120 0.0 0.0 112676 980 pts/0 R+ 16:45 0:00 grep --color=auto mysqld
. 启动 mariadb:
[root@localhost mariadb]# /etc/init.d/mariadb start
Reloading systemd: [ 确定 ]
Starting mariadb (via systemctl): [ 确定 ]
- [root@localhost mariadb]# ps aux |grep mariadb##grep mysqld 也可以
- root 2162 0.0 0.1 115388 1732 ? S 16:47 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
- mysql 2278 8.0 4.9 1125124 49780 ? Sl 16:47 0:01 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariad --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
- root 2321 0.0 0.0 112676 984 pts/0 R+ 16:47 0:00 grep --color=auto mariadb
- [root@localhost 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:22 0.0.0.0:* LISTEN 822/sshd
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 934/master
- tcp6 0 0 :::22 :::* LISTEN 822/sshd
- tcp6 0 0 ::1:25 :::* LISTEN 934/master
- tcp6 0 0 :::3306 :::* LISTEN 2278/mysqld
maridb 是 mysql 的分支, 因此 mariadb 和安装 mysql 一样, 单独定义配置文件所在路径, 为的是和 mysql 区分开
虽然我们制定了配置文件为 --defaults-file=/usr/local/mariadb/my.cnf, 但是依然加载了 --datadir=/data/mysql, 而不是 / data/mariadb 这是因为在 my.cnf 中并没有定义 datadir 这个参数, 他就去找 / etc/my.cnf 配置文件
可以在 / usr/loal/mariadb/my.cnf 中, 在 [mysqld] 下增加 datadir = /data/mariadb
- [root@localhost ~]# killall mysqld
- [root@localhost ~]# ps aux | grep mysqld
- root 1130 0.0 0.0 112676 984 pts/0 S+ 17:16 0:00 grep --color=auto mysqld
- [root@localhost ~]# /etc/init.d/mariadb start
Starting mariadb (via systemctl): [ 确定 ]
- [root@localhost ~]# ps aux | grep mysqld
- root 1156 0.4 0.1 115388 1728 ? S 17:16 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 1275 4.6 5.8 1125024 58584 ? Sl 17:16 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 1311 0.0 0.0 112676 984 pts/0 R+ 17:16 0:00 grep --color=auto mysqld
(datadir 变为 / data/mariadb)
在启动脚本中定义 datadir 不行, 必须要在 my.cnf 中定义
11.7/11.8/11.9 Apache 安装
.Apache 是一个基金会的名字, httpd 才是我们要安装的软件包, 早期它的名字就叫 apache
.Apache 官网 www.apache.org
.apr 和 apr-util 是一个通用的函数库, 它让 httpd 可以不关心底层的操作系统平台, 可以很方便地移植(从 linux 移植到 windows)
下载安装包:
- wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz
- wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
- wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
. 解压下载的安装包:
- tar zxvf apr-1.6.3.tar.gz
- tar jxvf apr-util-1.6.1.tar.bz2
- tar zxvf httpd-2.4.29.tar.gz
. 安装 apr:
- [root@localhost src]# cd apr-1.6.3/
- [root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr/
(过程省略)
- [root@localhost apr-1.6.3]# echo $?
- 0
- [root@localhost apr-1.6.3]# make && make install
(过程省略)
. 安装 apr-util:
- root@localhost src]# cd ../apr-util-1.6.1/
- [root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
(--with-apr = 用来定义依赖的 apr 位置)
(过程省略)
[root@localhost apr-util-1.6.1]# make && make install
. 安装 httpd:
- [root@localhost apr-util-1.6.1]# cd ..
- [root@localhost src]# cd httpd-2.4.29/
- [root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4.29 --with-apr=/usr/local/apr --with-apr-util=/usr/local/util --enable-so --enable-mods-most
(过程省略)
- [root@localhost httpd-2.4.29]# make && make install
- [root@localhost apache2.4]# ls
- bin build cgi-bin conf error htdocs icons include logs man manual modules
(安装过程中的问题见问题汇总)
. 安装完成后, 进入 apache 目录:
- [root@localhost local]# cd apache2.4/
- [root@localhost apache2.4]# ls
- bin build cgi-bin conf error htdocs icons include logs man manual modules
常用目录:
bin 可执行文件 bin 中的 httpd
conf 配置文件所在目录
htdocs 存放访问页
logs 存放错误日志访问日志等
man 帮助文档
modules 模块
. 查看 apache 加载了哪些模块:/usr/local/apache2.4/bin/httpd -M
(或者 / usr/local/apache2.4/bin/apachectl -M)
- [root@localhost apache2.4]# /usr/local/apache2.4/bin/httpd -M
- AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the'ServerName' directive globally to suppress this message
- 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)
(static 静态, 直接把模块编译进主二进制文件 httpd;
shared 扩展模块, 文件目录在 / usr/local/apache2.4/modules)
. 启动 apache:
- [root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl start
- AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the'ServerName' directive globally to suppress this message
- [root@localhost apache2.4]# ps aux | grep httpd
- root 56398 0.0 0.2 70896 2204 ? Ss 23:28 0:00 /usr/local/apache2.4/bin/httpd -k start
- daemon 56399 0.0 0.4 359860 4244 ? Sl 23:28 0:00 /usr/local/apache2.4/bin/httpd -k start
- daemon 56400 0.0 0.4 359860 4244 ? Sl 23:28 0:00 /usr/local/apache2.4/bin/httpd -k start
- daemon 56401 0.0 0.4 359860 4244 ? Sl 23:28 0:00 /usr/local/apache2.4/bin/httpd -k start
- root 56484 0.0 0.0 112676 984 pts/0 S+ 23:28 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 826/sshd
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1076/master
- tcp6 0 0 :::80 :::* LISTEN 56398/httpd
- tcp6 0 0 :::22 :::* LISTEN 826/sshd
- tcp6 0 0 ::1:25 :::* LISTEN 1076/master
安装时遇到的报错汇总:
1,xml/apr_xml.c:35:19: 致命错误: expat.h: 没有那个文件或目录 #include <expat.h>
解决: 缺少 expat-devel 包
- yum install expat-devel
- 2,configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决:
yum list | grep pcre 查找依赖包
yum install -y pcre-devel
再编译就行了
3,make 报错
collect2: error: ld returned 1 exit status
make[2]: [htpasswd] 错误 1
make[2]: 离开目录 / usr/local/src/httpd-2.4.27/support
make[1]: [all-recursive] 错误 1
make[1]: 离开目录 / usr/local/src/httpd-2.4.27/support
make: *** [all-recursive] 错误 1
解决: 删除文件, 重新解压源码包, 先复制文档, 再 configure 后加 --with-included-apr 再重新编译
- cd /usr/local/src/
- cp -r apr-1.6.3 /usr/local/src/httpd-2.4.29/srclib/apr
- cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.29/srclib/apr-util
- cd /usr/local/src/httpd-2.4.29
- #./configure --with-included-apr --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
- #make &&make install
来源: http://www.bubuko.com/infodetail-2509779.html