11.6 MariaDB安装

 

将二进制包下载到/usr/local/src:

[root@hyc-01-01 ~]# cd /usr/local/src

[root@hyc-01-01 src]# ls

mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz

mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz

 

解压包:

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

 

移动文件到/usr/local下并改名:

[root@hyc-01-01 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb

 

创建mysql用户

 

初始化创建datadir

[root@hyc-01-01 mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb

最好指定basedir(包的路径),否则有可能会用mysql的包文件初始化

[root@hyc-01-01 mariadb]# echo $?

0

[root@hyc-01-01 mariadb]# ls /data/mariadb

aria_log.00000001  ib_buffer_pool  ib_logfile0  mysql               test

aria_log_control   ibdata1         ib_logfile1  performance_schema

[root@hyc-01-01 mariadb]# ls /data/mysql

auto.cnf       ibdata1      ib_logfile1  performance_schema

hyc-01-01.err  ib_logfile0  mysql        test

 

拷贝配置文件:

[root@hyc-01-01 mariadb]# cd /usr/local/mariadb

[root@hyc-01-01 mariadb]# ls support-files/

binary-configure        my-large.cnf         mysql-log-rotate  wsrep_notify

magic                   my-medium.cnf        mysql.server

my-huge.cnf             my-small.cnf         policy

my-innodb-heavy-4G.cnf  mysqld_multi.server  wsrep.cnf

mariadbsupport-files目录下有多个配置文件模板;

根据内存大小不同,选择不同的配置文件,可以指定合适的缓存,让mariadb达到更高效的性能;

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

为了与mysql的配置文件区分,放在一个不同的路径下

 

拷贝启动脚本:

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

 

编辑配置文件:

[root@hyc-01-01 mariadb]# vim /usr/local/mariadb/my.cnf

# The MySQL server

[mysqld] 以下为配置文件主要部分

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

 

# Don't listen on a TCP/IP port at all. This can be a security enhancement,

 

编辑启动脚本:

[root@hyc-01-01 mariadb]# vim /etc/init.d/mariadb

basedir=/usr/local/mariadb 指定包路径

datadir=/data/mariadb 指定数据存放路径

conf=$basedir/my.cnf 指定配置文件路径

 

# Default value, in seconds, afterwhich the script should timeout waiting

      # may be overwritten at next upgrade.

      $bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &

      wait_for_ready; return_value=$?

在启动时指定配置文件路径,否则有可能去找/etc/my.cnf

 

启动mariadb

[root@hyc-01-01 mariadb]# ps aux|grep mysql 检查mysqld是否启动(mysqldmariadb监听一个端口)

root     30625  0.0  0.0 112676   980 pts/5    R+   07:36   0:00 grep --color=auto mysql

[root@hyc-01-01 mariadb]# /etc/init.d/mariadb start 启动

Reloading systemd:  Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1)

                                                           [  确定  ]

Starting mariadb (via systemctl):  Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1)

                                                           [  确定  ]

[root@hyc-01-01 mariadb]# echo $? 检查启动是否成功

0

[root@hyc-01-01 mariadb]# ps aux|grep mariadb

root     29830  0.2  0.2 152156  2220 pts/0    T    05:29   0:19 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     30659  0.0  0.1 115388  1732 ?        S    07:38   0:00 /bin/sh /usr/localmariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/hyc-01-01.pid

mysql    30775  1.3  4.9 1125124 49700 ?       Sl   07:38   0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/hyc-01-01.err --pid-file=/data/mysql/hyc-01-01.pid --socket=/tmp/mysql.sock --port=3306

root     30814  0.0  0.0 112676   984 pts/5    R+   07:39   0:00 grep --color=auto mariadb

[root@hyc-01-01 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      849/sshd           

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      953/master         

tcp        0      0 192.168.31.129:1122     0.0.0.0:*               LISTEN      10724/rsync        

tcp6       0      0 :::22                   :::*                    LISTEN      849/sshd           

tcp6       0      0 ::1:25                  :::*                    LISTEN      953/master         

tcp6       0      0 :::3306                 :::*                    LISTEN      30775/mysqld      

 

一台机器安装了mysqlmariadb,两个数据库都会有配置文件

[root@hyc-01-01 mariadb]# ps aux|grep mysql

root     30659  0.0  0.1 115388  1732 ?        S    07:38   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/hyc-01-01.pid

mysql    30775  0.2  4.9 1125124 49832 ?       Sl   07:38   0:01 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/hyc-01-01.err --pid-file=/data/mysql/hyc-01-01.pid --socket=/tmp/mysql.sock --port=3306

root     30817  0.0  0.0 112676   984 pts/5    R+   07:47   0:00 grep --color=auto mysql

由于系统没有在mariadb的配置文件中找到datadir相关参数,所以系统会到/etc/my.cnf下查找datadir参数,此时datadir不是mariadb/data/mariadb,而是my.cnf中的datadir

 

编辑mariadb配置文件,指定datadir

[root@hyc-01-01 mariadb]# vim /usr/local/mariadb/my.cnf

# The MySQL server

[mysqld]

datadir = /data/mariadb 指定datadir

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

[root@hyc-01-01 mariadb]# /etc/init.d/mariadb stop 停止mariadb

Stopping mariadb (via systemctl):                          [  确定  ]

[root@hyc-01-01 mariadb]# /etc/init.d/mariadb start 启动mariadb

Starting mariadb (via systemctl):                          [  确定  ]

[root@hyc-01-01 mariadb]# ps aux|grep mariadb

root      5522  0.1  0.1 115388  1732 ?        S    20: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/hyc-01-01.pid

mysql     5641  3.8  6.1 1125024 62040 ?       Sl   20: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/hyc-01-01.err --pid-file=/data/mariadb/hyc-01-01.pid --socket=/tmp/mysql.sock --port=3310

root      5683  0.0  0.0 112676   984 pts/0    R+   20:16   0:00 grep --color=auto mariadb

 

11.7 Apache安装(上)

 

httpd是一个web服务软件;

Apache是一个基金会,该基金会依靠httpd起家;

在最早的版本中该软件叫apache,从2.0版本开始改名叫httpd

目前主流版本2.4

由于2.4版本涉及aprapr-util,所以2.22.4版本的安装方法略有不同;

aprapr-util是通用函数库,使httpd可以不关心底层操作系统平台,方便移植(将apachewindows放到linux上也可以正常运行);

由于涉及aprapr-util,所以2.2版本和2.4版本依赖的apr版本不同,centos使用yum安装的apr2.4版本不匹配,无法使用,所以需要自己编译;

 

下载相关的包:

[root@hyc-01-01 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.34.tar.gz

[root@hyc-01-01 src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz

[root@hyc-01-01 src]# wget

[root@hyc-01-01 src]# ls

apr-1.6.3.tar.gz       mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz

apr-util-1.6.1.tar.gz  mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz

httpd-2.4.34.tar.gz

 

11.8 Apache安装(中)

 

解压软件包:

[root@hyc-01-01 src]# tar zxvf httpd-2.4.34.tar.gz

[root@hyc-01-01 src]# tar zxvf apr-util-1.6.1.tar.gz

[root@hyc-01-01 src]# tar zxvf apr-1.6.3.tar.gz

 

安装apr

[root@hyc-01-01 apr-1.6.3]# ./configure --prefix=/usr/local/apr

报错

checking for gcc... no

checking for cc... no

checking for cl.exe... no

configure: error: in `/usr/local/src/apr-1.6.3':

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

解决:

[root@hyc-01-01 apr-1.6.3]# yum install -y gcc

 

[root@hyc-01-01 apr-1.6.3]# ./configure --prefix=/usr/local/apr 重新执行

[root@hyc-01-01 apr-1.6.3]# make && make install

 

安装apr-util

[root@hyc-01-01 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

[root@hyc-01-01 apr-util-1.6.1]# make && make install

报错:

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

解决:

[root@hyc-01-01 apr-util-1.6.1]# yum install -y expat-devel

 

[root@hyc-01-01 apr-util-1.6.1]# make && make install 重新执行

 

[root@hyc-01-01 apr-util-1.6.1]# ls /usr/local

apr       bin  games    lib    libexec  mysql  share

apr-util  etc  include  lib64  mariadb  sbin   src

/usr/local下生成了aprapr-util两个目录

 

安装httpd

[root@hyc-01-01 httpd-2.4.34]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most

报错:

checking for pcre-config... false

configure: error: pcre-config for libpcre not found. PCRE is required and available from

解决:

pcre是正则表达式的驱动库,支持正则表达式必须依赖该库;

库相关的包会带有libdevel字样;

[root@hyc-01-01 httpd-2.4.34]# yum list|grep pcre 搜索pcre相关的包

[root@hyc-01-01 httpd-2.4.34]# yum install -y pcre-devel

 

[root@hyc-01-01 httpd-2.4.34]# make

报错:

/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.34/support

make[1]: *** [all-recursive] 错误 1

make[1]: 离开目录“/usr/local/src/httpd-2.4.34/support

make: *** [all-recursive] 错误 1

解决:

[root@hyc-01-01 httpd-2.4.34]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most --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/.

aprapr-util缺失,需要下载并解压到./srclib/目录下

解决:

[root@hyc-01-01 httpd-2.4.34]# cd /usr/local/src

[root@hyc-01-01 src]# cp -r apr-1.6.3 /usr/local/src/httpd-2.4.34/srclib/apr

[root@hyc-01-01 src]# cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.34/srclib/apr-util

 

[root@hyc-01-01 httpd-2.4.34]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most --with-included-apr 重新执行

 

[root@hyc-01-01 httpd-2.4.34]# make 重新编译

[root@hyc-01-01 httpd-2.4.34]# make install

 

11.9 Apache安装(下)

 

查看安装的apache目录文件:

[root@hyc-01-01 httpd-2.4.34]# cd /usr/local/apache2.4

[root@hyc-01-01 apache2.4]# ls

bin    cgi-bin  error   icons    lib   man     modules

build  conf     htdocs  include  logs  manual

[root@hyc-01-01 bin]# du -sh httpd

2.3M        httpd

[root@hyc-01-01 apache2.4]# du -sh modules/

6.4M        modules/

 

[root@hyc-01-01 apache2.4]# /usr/local/apache2.4/bin/httpd –M 查看httpd都加载了哪些模块

[root@hyc-01-01 apache2.4]# /usr/local/apache2.4/bin/apachectl –M 结果同上

apachectl是一个shell文件,它调用了二进制的httpd-M用于列出模块信息

模块分类:

static 模块被编译进了主脚本中,该模块与二进制httpd文件是一个整体

shared 扩展模块,该模块为一个.so文件,在modules目录下,独立于httpd,可以选择是否加载

 

bin:存放可执行文件,该目录下的httpd二进制文件用于启动httpd服务

conf:配置文件所在目录

htdocs:默认网页文件存放在该目录下

logs:存放错误和访问日志

man:帮助文档相关

modules:扩展模块文件(.so),一个模块即一个.so文件,每个模块代表一个功能

 

启动apache

[root@hyc-01-01 apache2.4]# /usr/local/apache2.4/bin/apachectl start

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::d46b:4589:4da1:2f34. Set the 'ServerName' directive globally to suppress this message

[root@hyc-01-01 apache2.4]# echo $?

0

[root@hyc-01-01 apache2.4]# ps aux|grep httpd

root     63943  0.0  0.2  95580  2524 ?        Ss   23:24   0:00 /usr/local/apache2.4/bin/httpd -k start

daemon   63944  0.0  0.4 382408  4424 ?        Sl   23:24   0:00 /usr/local/apache2.4/bin/httpd -k start

daemon   63945  0.0  0.4 382408  4424 ?        Sl   23:24   0:00 /usr/local/apache2.4/bin/httpd -k start

daemon   63946  0.0  0.4 382408  4424 ?        Sl   23:24   0:00 /usr/local/apache2.4/bin/httpd -k start

root     64044  0.0  0.0 112720   984 pts/0    R+   23:24   0:00 grep --color=auto httpd

[root@hyc-01-01 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      889/sshd           

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1142/master        

tcp6       0      0 :::3310                 :::*                    LISTEN      5641/mysqld        

tcp6       0      0 :::80                   :::*                    LISTEN      63943/httpd         

tcp6       0      0 :::22                   :::*                    LISTEN      889/sshd           

tcp6       0      0 ::1:25                  :::*                    LISTEN      1142/master        

tcp6       0      0 :::3306                 :::*                    LISTEN      3381/mysqld