5.1 11.6-11.9听课笔记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5.1 11.6-11.9听课笔记相关的知识,希望对你有一定的参考价值。

11.6 mariaDB安装

 

下载二进制源码包:

mysql

解压:

[[email protected] mariadb]#tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz

将解压的文件放到/usr/local/下并更名:

[[email protected] src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb

运行scripts,指定用户为mysql指定mariaDB生成数据库目录存放数据位置

1 用户使用之前创建的mysql用户;

2 mariadb执行初始化

[[email protected] mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb

检验初始化是否成功:

1 查看初始化过程是否出现2ok

2 使用echo $?,为0则成功

[[email protected] mariadb]# echo $?

0

查看初始化生成的目录:

[[email protected] mariadb]# ls /data/mariadb

aria_log.00000001  ibdata1      mysql

aria_log_control   ib_logfile0  performance_schema

ib_buffer_pool     ib_logfile1  test

*定义basedir:如果不定义basedir,则系统有可能去找之前/usr/local/下的mysql目录

拷贝配置文件模板:

mysql5.1前的版本类似,存在多个配置文件模板:

*配置文件最大的区别在于配置的缓存大小不同,可以根据内存大小不同选择不同缓存的配置文件以达到更高的性能

*文件拷贝后可根据情况适当调整配置文件的某些参数

[[email protected]ocalhost support-files]# cp my-small.cnf /usr/local/mariadb/my.cnf

*为与之前安装的mysql区分,不将配置文件放在默认的etc

拷贝启动脚本:

[[email protected] support-files]# cp mysql.server /etc/init.d/mariadb

修改启动脚本、配置文件参数:

Changes

# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

 

# If you change base dir, you must also change datadir. These may get

# overwritten by settings in the MySQL configuration files.

 

basedir=/usr/local/mariadb

datadir=/data/mariadb

conf=$basedir/my.cnf 为了不与mysql的配置文件产生冲突,指定配置文件路径

    echo $echo_n "Starting MySQL"

    if test -x $bindir/mysqld_safe

    then

      # Give extra arguments to mysqld with the my.cnf file. This script

      # may be overwritten at next upgrade.

      $bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "[email protected]" &

*defaults-file设置默认配置文件路径

由于mysqldmariadb监听相同端口,所以两个服务同时启动会产生冲突:

1 检查是否有mysqld服务启动:

[[email protected] support-files]# ps aux |grep mysql

root     11826  0.0  0.0 113260   552 ?        S    22:18   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql

mysql    11951  0.1 44.0 1300784 444104 ?      Sl   22:18   0:06 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock

root     13415  0.0  0.0 112676   980 pts/2    R+   23:41   0:00 grep --color=auto mysql

[[email protected] support-files]# service mysqld stop 终止进程

Shutting down MySQL.. SUCCESS!

[[email protected] support-files]# ps aux |grep mysql

root     13442  0.0  0.0 112676   984 pts/2    S+   23:42   0:00 grep --color=auto mysql

启动mariadb并检查启动是否成功:

[[email protected] support-files]# /etc/init.d/mariadb start

Reloading systemd:                                         [  确定  ]

Starting mariadb (via systemctl):                          [  确定  ]

[[email protected] support-files]# echo $?

0

[[email protected] support-files]# ps aux|grep mariadb 查看mariadb启动是否成功

root     13483  0.0  0.1 115388  1732 ?        S    23: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    13599  1.2  5.2 1125124 53408 ?       Sl   23:47   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/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306

root     13686  0.0  0.0 112676   984 pts/2    R+   23:49   0:00 grep --color=auto mariadb

查看服务端口:

[[email protected] support-files]# netstat -ltnp

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      790/sshd           

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

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

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

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

 

问题:

机器上同时安装mysqlmariadb,启动服务后发现datadir不是预期的/data/mariadb

原因:mariadb配置文件中没有配置datadir这个参数,所以服务调用了mysql/etc/my.cnf

[[email protected] support-files]# ps aux|grep mariadb

root     13483  0.0  0.1 115388  1732 ?        S    23: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    13599  1.2  5.2 1125124 53408 ?       Sl   23:47   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/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306

root     13686  0.0  0.0 112676   984 pts/2    R+   23:49   0:00 grep --color=auto mariadb

 

解决办法:

编辑指定的配置文件,指定datadir参数:

[mysqld]

datadir = /data/mariadb

port            = 3306

socket          = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 16K

max_allowed_packet = 1M

重启服务:

[[email protected] support-files]# /etc/init.d/mariadb restart

Restarting mariadb (via systemctl):                        [  确定  ]

[roo[email protected] support-files]# ps aux|grep mariadb

root     14510  0.0  0.1 115388  1732 ?        S    00:20   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    14629  4.1  5.5 1125024 55824 ?       Sl   00:20   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     14665  0.0  0.0 112676   980 pts/2    R+   00:20   0:00 grep --color=auto mariadb

*datadir已经改变成配置文件指定的datadir,仅在启动脚本中定义datadir无效

 

11.7 Apache安装

 

Apachehttpdhttpd的早期版本被这样称呼,从2.0版本开始改名叫httpd

早期主流版本1.3,目前主流版本为2.42.2.2.4由于依赖软件apr不同导致安装方法不同;

Yum默认安装的apr可以给2.2版本使用,但与2.4版本不匹配,此时无法使用yum安装的apr,需要自己编译;

Apr为一个通用函数库,可以让httpd不关心底层操作系统平台,方便进行移植(将linux上运行的服务放到windows上可以照常运行)

 

11.8 Apache 安装

 

[[email protected] apr-1.6.3]# ./configure --prefix=/usr/local/apr 编译源文件

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

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

*第一次由于缺少gcc套件导致检查出现问题

[[email protected] apr-1.6.3]# echo $?

0

*Apr-util编译依赖于已经安装的apr,所以需要指定apr路径

[[email protected] apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

[[email protected] apr-util-1.6.1]# echo $?

0

[[email protected] 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

[[email protected] apr-util-1.6.1]# yum install -y expat-devel

[[email protected] apr-util-1.6.1]# make && make install

[[email protected] apr-util-1.6.1]# echo $?

0

[[email protected] httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4.29 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most 编译httpd文件,指定支持动态模块,且指定支持大多数动态模块

*checking for pcre-config... false

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

[[email protected] httpd-2.4.29]# yum list |grep pcre 查找相关软件

[[email protected] httpd-2.4.29]# yum install -y pcre-devel

[[email protected] httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4.29 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most

[[email protected] httpd-2.4.29]# echo $?

0

[[email protected] httpd-2.4.29]# make && make install

[[email protected] httpd-2.4.29]# echo $?

0

*第一次编译、安装httpd包出现问题,将aprapr-utilhttpd包全部重新安装后问题解决

 

11.9 Apache安装

Apache安装完成,查看apache安装的文件

[[email protected] local]# cd apache2.4.29

[[email protected] apache2.4.29]# ls

bin    cgi-bin  error   icons    logs  manual

build  conf     htdocs  include  man   modules

[[email protected] apache2.4.29]# cd bin

[[email protected] bin]# ls

ab         dbmmanage    htcacheclean  httpd

apachectl  envvars      htdbm         httxt2dbm

apxs       envvars-std  htdigest      logresolve

checkgid   fcgistarter  htpasswd      rotatelogs

[[email protected] bin]# pwd

/usr/local/apache2.4.29/bin

Bin目录用于存放apache启动服务运行的二进制可执行文件

Conf是配置文件所在目录

Htdocs放置网站默认访问的页面(一般是网站主页)

Logs日志(错误日志、访问日志等)

Man帮助文档

Modules扩展模块,每个模块对应一个功能,该目录是整个apache文件中较大的目录

[[email protected] apache2.4.29]# du -sh modules

6.3M        modules

[[email protected] apache2.4.29]# /usr/local/apache2.4.29/bin/httpd –M 查看httpd都启用了哪些模块

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 (staticstatic表示模块被直接编译进了主脚本(主二进制文件)即httpd

 authn_file_module (shared) shared表示为一个扩展模块,一个.so文件,均被存放于modules

 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)

[[email protected] apache2.4.29]# /usr/local/apache2.4.29/bin/apachectl –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

httpd (pid 27496) already running 不是错误提示,暂时可以忽略

/usr/local/apache2.4.29/bin/apachectl是一个shell文件,帮助用户调用二进制httpd-M将模块列出

 

启动apache

[[email protected] apache2.4.29]# /usr/local/apache2.4.29/bin/apachectlAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

httpd (pid 27496) already running

[[email protected] apache2.4.29]# ps aux|grep httpd 查看httpd进程是否启动

root     27496  0.0  0.2  70896  2208 ?        Ss   22:59   0:00 /usr/local/apache2.4.29/bin/httpd

daemon   27497  0.0  0.4 359860  4256 ?        Sl   22:59   0:00 /usr/local/apache2.4.29/bin/httpd

daemon   27498  0.0  0.4 359860  4256 ?        Sl   22:59   0:00 /usr/local/apache2.4.29/bin/httpd

daemon   27499  0.0  0.4 359860  4256 ?        Sl   22:59   0:00 /usr/local/apache2.4.29/bin/httpd

root     27658  0.0  0.0 112676   984 pts/1    R+   23:14   0:00 grep --color=auto httpd

查看端口号

[[email protected] apache2.4.29]# 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      793/sshd           

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

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

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

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


以上是关于5.1 11.6-11.9听课笔记的主要内容,如果未能解决你的问题,请参考以下文章

python 听课笔记- 序(鸡汤)

APIO2017听课笔记关键词

听课笔记

Daily dictation 听课笔记

Struts+Hibernate 听课笔记

3.12 听课笔记