1. 程式人生 > >2018-2-27 9周5次課MariaDB、Apache安裝

2018-2-27 9周5次課MariaDB、Apache安裝

MariaDB Apache

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.cnf、my-large.cnf、my-medium.cnf、my-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


2018-2-27 9周5次課MariaDB、Apache安裝