MariaDB、Apache(httpd)安裝

MariaDB安裝


1.將下載的源碼包放到這個目錄下:

[root@gary-tao ~]# cd /usr/local/src


2.下載源碼包:

[root@gary-tao ~]# 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  //這個是國外服務器,下載要四五十分鐘,最後是下載後直接放到指定目錄上。


3.將壓縮包解壓:

[root@gary-tao ~]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz


4.把目錄移動到/usr/local/下並改名爲mariadb:

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


5.進入目錄查看:

[root@gary-tao src]# cd /usr/local/mariadb


6.初始化指定用戶mysql和路徑:

[root@gary-tao mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb

[root@gary-tao mariadb]# ls /data/mariadb

aria_log.00000001  aria_log_control  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  test


7.複製配置文件:

[root@gary-tao mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf     爲了與mysql區分,重新換一個文件路徑


8.編輯配置文件:

#vi /usr/local/mariadb/my.cnf    定義basedir和datadir


如果沒有修改/usr/local/mariadb/my.cnf配置文件,沒有在mysqld中加一行 datadir=/data/mariadb,那麼它就會調用/etc/my.cnf中的datadir,就會出現如圖下的情況。 

linux的MariaDB、Apache(httpd)安裝


那如果修改了/usr/local/mariadb/my.cnf配置文件,在mysqld中加一行 datadir=/data/mariadb,如下:

linux的MariaDB、Apache(httpd)安裝


然後重新啓動mariadb服務,查看服務後如下:

linux的MariaDB、Apache(httpd)安裝


9.複製啓動腳本:

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


10.編輯啓動腳本:

命令:vim /etc/init.d/mariadb 

//定義basedir、datadir、conf以及啓動參數


basedir=/usr/local/mariadb 

datadir=/data/mariadb 

conf=$basedir/my.cnf


示例如下:

[root@gary-tao mariadb]# vim /usr/local/mariadb/my.cnf     配置腳本一般情況下不用更改。

[root@gary-tao mariadb]# vim /etc/init.d/mariadb                按下圖配置修改啓動腳本,修改完成保存退出。

linux的MariaDB、Apache(httpd)安裝

linux的MariaDB、Apache(httpd)安裝



備註:此啓動腳本由於mariadb與mysql裝在一臺機器上,爲了區分開來,需要定義conf與變量,如果只裝mariadb的話就不需要定義。



11.啓動MariaDB,啓動之前看看有沒有mysqld的服務在啓動,如果有它們是會衝突的,因爲它們的監聽端口是一樣的:

[root@gary-tao mariadb]# ps aux |grep mysql      先查看mysql的服務有沒啓動

root        818  0.0  0.0 115376   504 ?        S    15:56   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/gary-tao.pid

mysql      1189  0.0 45.1 1038844 451316 ?      Sl   15:56   0:03 /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/gary-tao.err --pid-file=/data/mysql/gary-tao.pid --socket=/tmp/mysql.sock

root       4853  0.0  0.0 112664   972 pts/0    R+   17:36   0:00 grep --color=auto mysql


[root@gary-tao mariadb]#  service mysqld stop    關閉mysql服務

Shutting down MySQL.. SUCCESS! 


[root@gary-tao mariadb]# service mariadb start //etc/init.d/mariadb start  兩種啓動服務方式

Starting mariadb (via systemctl):                          [  確定  ]


[root@gary-tao mariadb]# ps aux |grep mariadb     服務啓動成功

root       5198  0.0  0.1 115380  1732 ?        S    17:42   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/gary-tao.pid

mysql      5314 10.8  5.4 1125120 54544 ?       Sl   17:42   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/gary-tao.err --pid-file=/data/mysql/gary-tao.pid --socket=/tmp/mysql.sock --port=3306

root       5353  0.0  0.0 112664   972 pts/0    S+   17:42   0:00 grep --color=auto mariadb


[root@gary-tao mariadb]# 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      800/sshd            

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

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

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

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




Apache安裝

Apache是一個基金會的名字,httpd纔是我們要安裝的軟件包,早期它的名字就叫apache。

1.Apache官網地址 www.apache.org

2.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.gz


apr和apr-util是一個通用的函數庫,它讓httpd可以不關心底層的操作系統平臺,可以很方便地移植(從linux移植到windows)


3.下載安裝包到指定目錄:

[root@gary-tao ~]# cd /usr/local/src


4.將壓縮包解壓:

[root@gary-tao src]# tar zxvf httpd-2.4.29.tar.gz 

[root@gary-tao src]# tar zxvf apr-1.6.3.tar.gz 

[root@gary-tao src]# tar zxvf apr-util-1.6.1.tar.gz


5.首先安裝apr,進入apr目錄,然後安裝apr:

[root@gary-tao src]# cd /usr/local/src/apr-1.6.3

[root@gary-tao apr-1.6.3]# ./configure --prefix=/usr/local/apr

[root@gary-tao apr-1.6.3]# echo $?

0

[root@gary-tao apr-1.6.3]# make && make install

[root@gary-tao apr-1.6.3]# ls /usr/local/apr/

bin  build-1  include  lib


安裝時報錯問題解決:

示例如下:

[root@gary-tao apr-1.6.3]# ./configure --prefix=/usr/local/apr

checking build system type... x86_64-pc-linux-gnu

checking host system type... x86_64-pc-linux-gnu

checking target system type... x86_64-pc-linux-gnu

Configuring APR library

Platform: x86_64-pc-linux-gnu

checking for working mkdir -p... yes

APR Version: 1.6.3

checking for chosen layout... 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@gary-tao src]# yum install -y gcc     裝gcc編譯


6.進入apr-util目錄,安裝apr-util,apr-util要指定apr,因爲它依賴apr:

[root@gary-tao apr-1.6.3]# cd ../apr-util-1.6.1/

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

[root@gary-tao apr-util-1.6.1]# make && make install

[root@gary-tao apr-util-1.6.1]# ls /usr/local/apr-util/

bin  include  lib


在編譯安裝的時候可能會遇到圖下的情況,缺少expat的開發庫,所以需要安裝包:yum install expat-devel,安裝完成之後再編譯安裝make && make install:

linux的MariaDB、Apache(httpd)安裝


7.進入http目錄,安裝httpd方法:

[root@gary-tao src]# cd httpd-2.4.29

[root@gary-tao 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 

[root@gary-tao httpd-2.4.29]# echo $?

0

安裝時報錯:

如果沒有安裝pcre這個包,就會出現下圖的錯誤,我們可以使用 yum list |grep 關鍵字,查找關聯的安裝包。這裏需要安裝包:yum install -y pcre-devel.x86_64

linux的MariaDB、Apache(httpd)安裝


make編譯的時候可能會出現下圖的情況,把httpd,apr-util的源碼包刪除掉,然後在重新解壓源碼包,再重新把apr-util,httpd編譯安裝一遍

linux的MariaDB、Apache(httpd)安裝


8.進入apache2.4目錄下的查看文件:

[root@gary-tao httpd-2.4.29]# cd /usr/local/apache2.4/

[root@gary-tao apache2.4]# ls

bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules


針對目錄文件說明:

bin:bin下的文件是可執行的二進制文件或命令,是核心的二進制文件,如httpd;

conf:配置文件所在的目錄;

htdocs:存放了一個訪問網頁,默認的網站會放到這個目錄下;

logs:日誌相關的目錄,錯誤日誌,訪問日誌等;

man:幫助文檔;

modules:擴展模塊,模塊都放在這個目錄下,每一個模塊都代表一個功能;


9.查看加載的模塊:

命令:

/usr/local/apache2.4/bin/httpd -M

/usr/local/apache2.4/bin/apachectl -M         shell文件,去調用了二進制httpd文件,-M就是把模塊例出來。

[root@gary-tao apache2.4]# /usr/local/apache2.4/bin/httpd -M      下面AHOO558不是一個錯誤,只是一個警告,可以在配置文件中定義ServerName使其消失。

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 218.93.250.18. 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裏。有static說明是httpd裏的,靜態模塊是直接跟主程序(/usr/local/apache2.4/bin/httpd)綁定在一起,它們是一個整體。httpd是核心文件。

shared:說明是擴展的模塊,這個模塊是一個文件(文件是在modules目錄下面的.so文件)。


10.啓動httpd(Apache監聽端口是80端口):

[root@gary-tao apache2.4]# /usr/local/apache2.4/bin/apachectl start     執行啓動命令

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 218.93.250.18. Set the 'ServerName' directive globally to suppress this message

[root@gary-tao apache2.4]# ps aux |grep httpd 

root      46077  0.0  0.2  95536  2604 ?        Ss   21:24   0:00 /usr/local/apache2.4/bin/httpd -k start

daemon    46078  0.0  0.4 382364  4452 ?        Sl   21:24   0:00 /usr/local/apache2.4/bin/httpd -k start

daemon    46079  0.0  0.4 382364  4452 ?        Sl   21:24   0:00 /usr/local/apache2.4/bin/httpd -k start

daemon    46080  0.0  0.4 382364  4452 ?        Sl   21:24   0:00 /usr/local/apache2.4/bin/httpd -k start

root      46165  0.0  0.0 112680   972 pts/0    R+   21:24   0:00 grep --color=auto httpd


[root@gary-tao 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      800/sshd            

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

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

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

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

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章