MariaDB和Apache安裝

[toc]php

MariaDB安裝

11.6 MariaDB安裝

擴展 apache dso https://yq.aliyun.com/articles/6298html

apache apxs http://man.chinaunix.net/newsoft/ApacheMenual_CN_2.2new/programs/apxs.htmlmysql

apache工做模式 http://www.cnblogs.com/fnng/archive/2012/11/20/2779977.htmllinux

1.下載安裝包到統一目錄/usr/local/src/

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

由於MariaDB的二進制包鏡像源在國外地址,因此預先下載了該包到本地物理機,使用lrzsz工具將該包上傳至虛擬機/usr/local/src目錄進行安裝。nginx

[root@xavi src]# yum install -y lrzsz 
[root@xavi src]# rz

2.解壓二進制安裝包並移動至/usr/local下

[root@xavi src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
[root@xavi src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb

3.初始化,指定basedir和datadir

3.1 這裏說下進入/usr/local/mariadb/的三種方法

① cd /usr/local/mariadb/sql

② cd $! //上一條指令移動到的位置就是該路徑,全部可實現數據庫

③ cd ../mariab //當前src的路徑和mariab相同因此能實現apache

[root@xavi src]# cd /usr/local/mariadb/ 
[root@xavi mariadb]# ./scripts/mysql_install_db  --user=mysql --basedir=/usr/local/mariadb --datadir=/data/mariadb

3.2 初始化以後查看是否成功,只出現1個OK,再用echo $?確認是否錯誤

mark

[root@xavi mariadb]# echo $?
0

3.3 對比mariadb和mysql的數據存儲目錄

[root@xavi mariadb]# ls /data/mariadb/
aria_log.00000001  ibdata1      mysql
aria_log_control   ib_logfile0  performance_schema
ib_buffer_pool     ib_logfile1  test

[root@xavi mariadb]# ls /data/mysql/
auto.cnf     localhost.localdomain.err  xavi.err
ibdata1      mysql                      xavi.pid
ib_logfile0  performance_schema
ib_logfile1  test

4.拷貝配置文件並編輯(my-small.cnf)

4.1 查看下該路徑下有哪些文件/support-files/找到my-small.cnf

[root@xavi 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

進入support-files目錄,發現其和mysql下的support-files是有區別的vim

[root@xavi mariadb]# ls 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

mark

4.2 my-small.cnf的做用根據你的內存大小,合理分配,根據系統運行狀況

[root@xavi mariadb]# vim support-files/my-small.cnf

打開後有不少參數 markwindows

[root@xavi mariadb]# free
              total        used        free      shared  buff/cache   available
Mem:        1867292      625788      973228        9120      268276     1045700
Swap:       3905532           0     3905532

4.3把my-small.cnf拷貝到/usr/local/mariadb/my.cnf,編輯指定basedir和datadir

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

mark

mark

basedir=/usr/local/mariadb datadir=/data/mariadb

mark

5.拷貝啓動腳本至/etc/init.d/目錄下,並修改內容

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

mark

mark

mark

  • 由於在配置Mariadb的my.cnf過程當中,把/support-files/下的my-small.cnf文件複製到了/usr/local/mariadb/路徑下,因此這裏自定義一個變量conf來指引該路徑
[root@xavi mariadb]# ps aux |grep mysql
root       1073  0.0  0.0 115392  1668 ?        S    20:39   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/xavi.pid
mysql      1354  0.2 24.5 1368672 458540 ?      Sl   20:39   0:11 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/xavi.err --pid-file=/data/mysql/xavi.pid
root       3762  0.0  0.0 112676   976 pts/0    S+   21:55   0:00 grep --color=auto mysql
[root@xavi mariadb]# ps aux |grep mariadb
root       3764  0.0  0.0 112676   972 pts/0    S+   21:55   0:00 grep --color=auto mariadb

6.啓動mariadb:/etc/init.d/mariadb start或者service mariadb start

[root@xavi mariadb]# /etc/init.d/mariadb start
Reloading systemd:                                         [  肯定  ]
Starting mariadb (via systemctl):                          [  肯定  ]
[root@xavi mariadb]# ps aux |grep mariadb
root       3693  0.0  0.0 112676   972 pts/0    S+   21:50   0:00 grep --color=auto mariadb

6.1 這裏出現了錯誤,有多是mysql服務沒有關,查看一下:ps aux |grep mysql

[root@xavi mariadb]# ps aux |grep mysql
root       1073  0.0  0.0 115392  1668 ?        S    20:39   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/xavi.pid
mysql      1354  0.2 24.5 1302876 458540 ?      Sl   20:39   0:10 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/xavi.err --pid-file=/data/mysql/xavi.pid
root       3478  0.0  0.0 112676   976 pts/0    S+   21:48   0:00 grep --color=auto mysql

6.2 先把mysql服務關閉,而後打開mariadb

[root@xavi mariadb]# service mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@xavi mariadb]# service mariadb start
Starting mariadb (via systemctl):                          [  肯定  ]

6.3 再次查看ps aux |grep mariadb

[root@xavi mariadb]# ps aux |grep mariadb
root       3990  0.1  0.0 115392  1720 ?        S    22:06   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/xavi.pid
mysql      4112  1.4  3.1 1585872 58176 ?       Sl   22:06   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/xavi.err --pid-file=/data/mariadb/xavi.pid --socket=/tmp/mysql.sock --port=3306

6.4 netstat -lntp查看3306端口

[root@xavi 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:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2183/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1045/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1044/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1597/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      4112/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::22                   :::*                    LISTEN      1045/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1044/cupsd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      1597/master

有疑問的是?

mark 這個沒法解釋,單從3306端口來看mariadb應該是啓動了--這裏是由於配置過程當中mysql和mariadb的socket配置都是同樣,沒有改3306變端口.

killall mysqld先殺死所有mysqld進程,mysql和mariadb用的都是一個端口且mysqld進程program.

[root@xavi mariadb]# killall mysqld
[root@xavi mariadb]# ps aux |grep mysql
root       4566  0.0  0.0 112676   976 pts/0    R+   22:39   0:00 grep --color=auto mysql
[root@xavi mariadb]# service mariadb start
Starting mariadb (via systemctl):                          [  肯定  ]

老師有個問題:(視頻中的問題,在安裝php配置是待驗證)

若是我指定的數據庫是mariadb,php編譯時,提示沒有libmysqlclient_r.so;確實mariadb安裝後其/lib目錄下是沒有這個模塊的

那該怎麼辦呢


error: Cannot find libmysqlclient_r under /usr/local/mysql.

Note that the MySQL client library is not bundled anymore!

解決辦法是作個軟連接 ln -s /usr/local/mysql/lib/libmariadb.so.3 /usr/local/mysql/lib/libmysqlclient_r.so

修改主機名字

[root@localhost ~]# hostnamectl set-hostname xavi
[root@localhost ~]# 
[root@localhost ~]# init 6

重啓後,即[root@xavi ~]#

11.7~11.9 Apache安裝

Apache實際上是一個軟件基金會組織的名字,早期他們開發的Web Server軟件很是流行,當時的名字就叫作Apache,不事後來更名字叫作httpd了。

htppd目前主流版本是2.4,咱們先來2.4入手。2.2和2.4安裝不太同樣。2.4須要依賴軟件apr。apr和apr-util是一個通用的函數庫,它讓httpd能夠不關心底層的操做系統平臺,能夠很方便地移植(從linux移植到windows)

1. 下載所需源碼包到指定目錄/usr/local/src

[root@xavi mariadb]# cd /usr/local/src
[root@xavi src]#  wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.29.tar.gz   //2.4源碼包
[root@xavi  src]#  wget  http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz       //apr-1.6.3r包
[root@xavi src]#  wget  http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz  //apr-util-1.6.1包

1.1 查看是否都已下載徹底:ls

[root@xavi src]# ls
apr-1.6.3              httpd-2.4.29.tar.gz
apr-1.6.3.tar.gz       mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-util-1.6.1         mysql-5.5.55
apr-util-1.6.1.tar.gz  mysql-5.5.55.tar.gz
httpd-2.4.29           mysql-5.6.36-linux-glibc2.5-x86_64.tar.g

2.解壓源碼包

[root@xavi src]# tar zxvf httpd-2.4.29.tar.gz 
[root@xavi src]# tar zxvf apr-1.6.3.tar.gz 
[root@xavi src]# tar zxvf apr-util-1.6.1.tar.gz

3.安裝源碼包

apr(包含apr和apr-unit)能夠理解成一個通用的函數庫,主要爲上層應用提供支持,這裏,httpd是依賴apr和apr-util的,若是不安裝這兩個東西,httpd就沒法工做

3.1 安裝apr-1.6.3包:#./configure --prefix=/usr/local/apr

[root@xavi src]# cd /usr/local/src/apr-1.6.3
[root@xavi apr-1.6.3]# ./configure --prefix=/usr/local/apr    //執行配置命令
[root@xavi apr-1.6.3]# echo $?
0 //確認有無錯誤
進行編譯安裝:make && make install
[root@xavi apr-1.6.3]# make && make install

3.3 安裝apr-unit包

查看apr下有4個目錄

[root@xavi apr-1.6.3]# ls /usr/local/apr
bin  build-1  include  lib
[root@xavi apr-1.6.3]# cd ../apr-util-1.6.1/

[root@xavi apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@xavi apr-util-1.6.1]# make && make install
出現了錯誤:expat.h:沒有那個文件或目錄
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*相關的軟件包
[root@xavi apr-util-1.6.1]# yum install -y expat*

mark

再次安裝make && make install,在apr-util/下生產了3個子目錄

mark

[root@xavi apr-util-1.6.1]# echo $?
0
[root@xavi apr-util-1.6.1]# ls /usr/local/apr-util/  
bin  include  lib

3.7 安裝httpd包,回到src目錄下

[root@xavi apr-util-1.6.1]# cd ..
[root@xavi src]# cd httpd-2.4.29

配置apache2.4: ./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@xavi httpd-2.4.29]# ./configure\ --prefix=/usr/local/apache2.4\ --with-apr=/usr/local/apr\ --with-apr-util=/usr/local/apr-util\ --enable-so --enable-mods-shared=most\

每句最後的反斜槓是轉義字符,加上它咱們能夠把一行命令寫成多行.

解析:

  • [ ] --prefix指定安裝目錄,
  • [ ] --enable-so表示啓用DSO.DSO的意思是把某些功能以模塊(一個功能模塊就是一個so文件,這些文件在編譯完htppd後會看到)的形式展示出來,
  • [ ] --enable-mods-shared=most表示以共享的方式安裝大多數功能模塊,安裝後會在modules目錄下面看到這些文件。

報錯:

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解決報錯:yum list |grep pcre
[root@xavi httpd-2.4.29]# yum list |grep pcre
安裝:yum install -y pcre-devel
[root@xavi httpd-2.4.29]# yum install -y pcre--devel

安裝成功

mark

複習時,啓動apache報錯,如今從新安裝apr 包(apr和apr-util)

1.找到配置前的路徑,makeclean其全部配置內容:

[root@xavi apr-util-1.6.1]# cd /usr/local/src/apr-1.6.3
[root@xavi apr-1.6.3]# make clean
[root@xavi apr-1.6.3]# ./configure --prefix=/usr/local/apr  
[root@xavi apr-1.6.3]# yum install -y expat-devel

用echo$?查看下一句是否錯誤,然make&make install

[root@xavi apr-1.6.3]# cd /usr/local/src/apr-util-1.6.1
[root@xavi apr-util-1.6.1]# make clean
[root@xavi apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

同理從新配置httpd,而後安裝

[root@xavi apr-util-1.6.1]# cd /usr/local/src/httpd-2.4.29 

[root@xavi httpd-2.4.29]# make clean

報錯:

checking for APR... configure: error: the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.

mark

從新安裝成功 mark

5.查看httpd的目錄結構以及modules下面的模塊文件

查看目錄結構

[root@xavi httpd-2.4.29]# ls /usr/local/apache2.4
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
  • [ ] bin 就是可執行的二進制文件
  • [ ] conf 配置文件所在目錄
  • [ ] htdocs 存放網站的地方
  • [ ] logs 日誌相關(錯誤,訪問)
  • [ ] man 幫助文檔
  • [ ] modules 擴展模塊(每一個模塊表明着一個功能)

查看加載的模塊,分爲兩種類型①static ②shared

[root@xavi httpd-2.4.29]# /usr/local/apache2.4/bin/httpd -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)
 rewrite_module (shared)
 php7_module (shared)

分爲兩種類型①static ②shared

static:httpd系統內置(看不到),直接和主程序/usr/local/appache2.4/bin/httpd綁定在一塊兒. shared:擴展的模塊,獨立存在,modules目錄下的.so文件 既是。

從新分析這個報錯:

[root@xavi httpd-2.4.29]# /usr/local/apache2.4/bin/apachectl start
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

其真正緣由是80端口被佔用了

檢查80端口的使用狀況:lsof -i :80

[root@xavi httpd-2.4.29]# lsof -i :80
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1076   root    7u  IPv4  21187      0t0  TCP *:http (LISTEN)
nginx   1080 nobody    7u  IPv4  21187      0t0  TCP *:http (LISTEN)
nginx   1082 nobody    7u  IPv4  21187      0t0  TCP *:http (LISTEN)

關閉nginx服務,查看80端口狀態:netstat -lnp|grep 80

[root@xavi httpd-2.4.29]# /etc/init.d/nginx stop
Stopping nginx (via systemctl):                            [  肯定  ]
[root@xavi httpd-2.4.29]# !net
netstat -lnp|grep 80
unix  2      [ ACC ]     STREAM     LISTENING     22280    1677/master          public/flush

再次開啓httpd

[root@xavi httpd-2.4.29]# /usr/local/apache2.4/bin/apachectl start

原由是本身在開機啓動項裏面加了開關

[root@xavi httpd-2.4.29]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。 
      若是您想列出 systemd 服務,請執行 'systemctl list-unit-files'。
      欲查看對特定 target 啓用的服務請執行
      'systemctl list-dependencies [target]'。

mysqld         	0:關	1:關	2:開	3:開	4:開	5:開	6:關
netconsole     	0:關	1:關	2:關	3:關	4:關	5:關	6:關
network        	0:關	1:關	2:開	3:關	4:關	5:關	6:關
nginx          	0:關	1:關	2:開	3:開	4:開	5:開	6:關
php-fpm        	0:關	1:關	2:開	3:開	4:開	5:開	6:關
相關文章
相關標籤/搜索