九週五次課

九週五次課html

11.6MariaDB安裝mysql

11.7/11.8/11.9Apache安裝linux

11.6MariaDB安裝web

安裝mariadb

  • cd /usr/local/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
  • tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  • mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
  • cd /usr/local/mariadb
  • ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
  • cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
  • vi /usr/local/mariadb/my.cnf //定義basedir和datadir
  • cp support-files/mysql.server /etc/init.d/mariadb
  • vim /etc/init.d/mariadb //定義basedir、datadir、conf以及啓動參數
  • /etc/init.d/mariadb start

安裝過程

  • mariadb和mysql安裝過程相似

1.首先切換到/usr/local/src目錄下正則表達式

[root@tianqi-01 mysql]# cd /usr/local/src/
[root@tianqi-01 src]# sql

2.而後在官網下載10.2.6版本(官網下載很慢,由於地址在美國),本身百度雲有提早下載好的,只須要下載到windows,而後 rz 命令從windows上傳到linux中shell

  • rz命令,安裝包——>yum install -y lrzsz

文件比較大而上傳出錯的話,採用參數 -e;
若是用不帶參數的rz命令上傳大文件時,經常上傳一半就斷掉了,極可能是rz覺得上傳的流中包含某些特殊控制字符,形成rz提早退出。數據庫

[root@tianqi-01 src]# rz -e
Š z waiting to receive.** B0100000063f694
[root@tianqi-01 src]# ls
?  d?  httpd-2.2.34  httpd-2.2.34.tar.gz  mariadb-10.2.6-linux-x86_64.tar.gz  mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@tianqi-01 src]# express

3.再去使用 tar命令 進行解壓apache

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

4.解壓完,去查看下文件

[root@tianqi-01 src]# ls
httpd-2.2.34         mariadb-10.2.6-linux-x86_64         mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
httpd-2.2.34.tar.gz  mariadb-10.2.6-linux-x86_64.tar.gz
[root@tianqi-01 src]# 

5.並將解壓的包移動到/usr/local下,並更名叫mariadb——>這裏的更名,是爲了以前安裝mysql的名字有所區分

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

6.而後進入到/usr/local/mariadb 目錄下去

[root@tianqi-01 src]# cd !$
cd /usr/local/mariadb
[root@tianqi-01 mariadb]# 

7.建立mysql用戶,建立data——>這裏由於以前安裝mysql的時候,已經建立過了因此不須要建立useradd mysql

[root@tianqi-01 mariadb]# useradd mysql
[root@tianqi-01 mariadb]# mkdir /data/
[root@tianqi-01 mariadb]# 

8.初始化,./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb

  • 定義basedir=/usr/local/mariadb/ 若不定義 ,就會去找mysql了

[root@tianqi-01 mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in '/data/mariadb' ...
OK

9.查看是否初始化成功,看 echo $? 執行結果是否爲0,如果 0 ,則表示初始化成功

[root@tianqi-01 mariadb]# echo $?
0
[root@tianqi-01 mariadb]# 

或者查看/data/mariadb/目錄下,是否生成了一些目錄——>和/data/mysql/ 相似

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

10.拷貝配置文件,定義啓動腳本

  • 配置文件存放在/usr/local/mariadb/suport/files/目錄下,會看到有不少配置文件

[root@tianqi-01 mariadb]# cd /usr/local/mariadb/
[root@tianqi-01 mariadb]# ls support-files/
binary-configure  my-huge.cnf             my-large.cnf   my-small.cnf         mysql-log-rotate  policy     wsrep_notify
magic             my-innodb-heavy-4G.cnf  my-medium.cnf  mysqld_multi.server  mysql.server      wsrep.cnf
[root@tianqi-01 mariadb]# 

11.打開support-files/my-small.cnf 文件

  • my-small.cnf、my-medium.cnf、my-large.cnf這三個配置文件區別在於 緩存的數值大小不一樣
    • 根據內存大小的不一樣,它能夠給你指定合適的緩存,這樣可以讓你的mysql達到更高效的性能

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

其中下面的配置文件

[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

12.由於咱們作實驗,內存原本就不大,可使用最小的一個my-small.cnf ,拷貝過去

  • 如果內存有幾十個G,可使用my-huge.cnf拷貝過去,而後根據實際的運行狀況 ,去適當的調整參數

13.拷貝文件到/usr/local/mariadb/my.cnf

  • mariadb這裏就不放到/etc/my.cnf下了,由於這是mysql用的,這裏爲了區分到/usr/local/mariadb/my.cnf

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

14.編輯配置文件 /usr/local/mariadb/my.cnf——>這裏面配置不用修改

[root@tianqi-01 mariadb]# vim !$
vim /usr/local/mariadb/my.cnf

配置參數在[mysqld]這一塊

server-id = 1     //這是作主從複製的

15.拷貝啓動腳本到 /etc/init.d/mariadb

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

16.編輯啓動腳本

[root@ip-172-31-21-107 mariadb]# vim /etc/init.d/mariadb

定義 basedir=/usr/local/mariadb

定義 datadir=/data/mariadb

自定義參數 conf=$basedir/my.cnf

在定義conf後,還須要在 啓動命令下面指定下——>在通常模式下,搜索 /start 啓動命令

在 $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" & 中,增長

--defaults-file="$conf",最後爲 $bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &

並保存退出

17.在啓動前,先查看是否有mysql服務在啓動

[root@tianqi-01 mariadb]# ps aux |grep mysql
root       1231  0.0  0.0 112660   984 pts/0    S+   17:57   0:00 grep --color=auto mysql
[root@tianqi-01 mariadb]# 

18.啓動mariadb服務,並去查看是否啓動

  • 查看是否啓動,用ps aux |grep mysql 也能夠,啓動的服務進程是mysqld,由於mariadb是mysql的一個分支

[root@tianqi-01 mariadb]# /etc/init.d/mariadb start
Starting MySQL.180227 18:01:59 mysqld_safe Logging to '/data/mysql/tianqi-01.err'.
180227 18:01:59 mysqld_safe Starting mysqld daemon with databases from /data/mysql
.....                                                      [  OK  ]
[root@tianqi-01 mariadb]# ps aux |grep mariadb
root       1253  0.1  0.1 113264  1648 pts/0    S    18:01   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/tianqi-01.pid
mysql      1369 13.7  5.4 1122944 54820 pts/0   Sl   18:01   0:03 /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/tianqi-01.err --pid-file=/data/mysql/tianqi-01.pid --socket=/tmp/mysql.sock --port=3306
root       1425  0.0  0.0 112660   980 pts/0    S+   18:02   0:00 grep --color=auto mariadb
[root@tianqi-01 mariadb]# 

[root@tianqi-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      778/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1009/master         
tcp6       0      0 :::22                   :::*                    LISTEN      778/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1009/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      1369/mysqld         
[root@tianqi-01 mariadb]# 

19.如果在服務器上只安裝了mariadb,沒有mysql,那徹底能夠把my.cnf放在/etc目錄下,那啓動腳本就不須要conf變量了

機器裝了mysql和mariadb

  • 一臺機器上裝了mysql,又裝了mariadb (這種既裝了mysql和mariadb的機率很低),由於有多個配置文件在/etc/my.cnf,不管是在初始化的時候,仍是啓動多個mysql服務的時候,它都會影響正常的結果,因此要麼不把 my.cnf 放在etc目錄下,一旦放了,頗有可能受到影響。
  • 問題:
  • 用ps aux |grep mysql會發現其中的--datadir=/data/mysql,並非咱們預期的--datadir=/data/mariadb
  • 這是由於調用了/etc/my.cnf中的配置,有人可能會問,不是已經指定了--defaults-file=/usr/local/mariadb/my.cnf 配置文件,爲何還要去加載/etc/my.cnf中的配置呢,是由於--defaults-file=/usr/local/mariadb/my.cnf文件中,並無去定義dataidr 這個選項,而後去調用的時候,沒有在配置文件中找到這個參數,而後在/etc/my.cnf中調用
  • 解決方法:
  • 1.須要去編輯指定的配置文件,在 /usr/local/mariadb/my.cnf 文件中的 [mysqld] 下加入datadir= /data/mariadb (如果datadir加在其餘地方是無效的)
    • 固然不是隻能擁有一個數據庫,只要將各個參數配置完善,一個機器上能夠跑多個mysql服務
  • 2.在修改完配置文件後,啓動/etc/init.d/mariadb start (第一次啓動mariadb服務)——>如果mariadb服務已經啓動了,則/etc/init.d/mariadb restart ,但顯示的結果還未正常,那咱們就直接killall mysqld服務,而後再ps aux |grep mysql查看下服務是否殺死
  • 3.最後再來 /etc/init.d/mariadb restart 開啓mariadb服務,會看到顯示正常。

[root@tianqi-01 mariadb]# ps aux |grep mysql
root       1253  0.0  0.1 113264  1648 pts/0    S    18:01   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/tianqi-01.pid
mysql      1369  1.2  6.2 1122944 62448 pts/0   Sl   18:01   0:03 /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/tianqi-01.err --pid-file=/data/mysql/tianqi-01.pid --socket=/tmp/mysql.sock --port=3306
root       1429  0.0  0.0 112660   980 pts/0    S+   18:07   0:00 grep --color=auto mysql
[root@tianqi-01 mariadb]#

11.7/11.8/11.9Apache安裝

安裝Apache

  • Apache是一個基金會的名字,httpd纔是咱們要安裝的軟件包,早期它的名字就叫apache
  • Apache官網www.apache.org
  • 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
  • apr和apr-util是一個通用的函數庫,它讓httpd能夠不關心底層的操做系統平臺,能夠很方便地移植(從linux移植到windows)
  • tar zxvf httpd-2.4.29.tar.gz
  • tar zxvf apr-util-1.6.1.tar.bz2
  • tar zxvf apr-1.6.3.tar.gz
  • cd /usr/local/src/apr-1.6.3
  • ./configure --prefix=/usr/local/apr
  • make && make install
  • cd /usr/local/src/apr-util-1.6.1
  • ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  • make && make install
  • cd /usr/local/src/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
  • make && make install
  • ls /usr/local/apache2.4/modules
  • /usr/local/apache2.4/bin/httpd -M //查看加載的模塊

Apache介紹

  • Apache是一個基金會的名字,它最先就是由httpd起家的,由於httpd使用的人不少,很流行,因此當時就以基金會的名字來命名的web服務軟件 ,在早期的時候,名字就叫作Apache,而不是叫httpd,後來在http的2.0版本開始,就更名叫httpd,可是不少人仍是習慣叫作Apache
  • Apache的主流版本,在以前是 1.3版本比較流行,後來出了2.0版本,2.2版本,2.4版本,如今主流版本是 2.4版本

Apache(2.4版本)

  • 2.2版本和2.4版本的區別
    • 安裝的方法不一樣,涉及到一個安依賴軟件apr版本不同
  • apr和apr-util是一個通用的函數庫,它讓httpd能夠不關心底層的操做系統平臺,能夠很方便地進行移植(從linux移植到windows)
  • 2.2版本和2.4版本所依賴的apr版本是不一樣的
    • 而centos系統,默認自帶的apr,也就是yum安裝的apr和2.4版本是不匹配的,因此沒法使用yum安裝的apr,因此須要本身去手動編譯
  • Apache2.4版本編譯起來麻煩,就是由於須要手動編譯 apr 和 apr-util 這兩個包

安裝過程

1.首先切換到/usr/local/src目錄下

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

2.下載Apache 2.4源碼包、apr、apr-util這三個包

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

3.在下載完成後,查看下下載的包

[root@tianqi-01 src]# ls
apr-util-1.6.1.tar.bz2  httpd-2.2.34         httpd-2.4.29.tar.gz                 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz    apr-1.6.3.tar.gz                       httpd-2.2.34.tar.gz  mariadb-10.2.6-linux-x86_64.tar.gz
[root@tianqi-01 src]# 

4.解壓下載的包,並查看

[root@tianqi-01 src]# tar zxvf httpd-2.4.29.tar.gz

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

[root@tianqi-01 src]# tar xjvf apr-util-1.6.1.tar.bz2

[root@tianqi-01 src]# ls
apr-1.6.3.tar.gz  apr-util-1.6.1.tar.bz2  httpd-2.2.34         httpd-2.4.29         mariadb-10.2.6-linux-x86_64.tar.gz                            apr-1.6.3  apr-util-1.6.1     httpd-2.2.34.tar.gz  httpd-2.4.29.tar.gz  mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@tianqi-01 src]# 

在解壓完成後,首先安裝apr

5.切換到/usr/local/src/apr-1.6.3,並安裝apr

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

在安裝的時候,有時會出現如下狀況

  • 只須要安裝gcc包便可——>yum install -y gcc

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@tianqi-01 apr-1.6.3]# yum install -y gcc

6.在安裝完成後,能夠用 echo $? 檢查是否安裝成功

[root@tianqi-01 apr-1.6.3]# echo $?
0
[root@tianqi-01 apr-1.6.3]# 

7.執行make && make install 命令

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

8.查看下apr,會看到有四個目錄

[root@tianqi-01 apr-1.6.3]# ls /usr/local/apr/
bin  build-1  include  lib
[root@tianqi-01 apr-1.6.3]# 

9.安裝apr-util-1.6.1,首先切換到/usr/local/src/apr-util-1.6.1目錄下

[root@tianqi-01 apr-1.6.3]# cd /usr/local/src/apr-util-1.6.1
[root@tianqi-01 apr-util-1.6.1]# 

10.安裝apr-util

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

11.而後使用echo $?檢查是否安裝成功

[root@tianqi-01 apr-util-1.6.1]# echo $?
0
[root@tianqi-01 apr-util-1.6.1]# 

12.而後make && make install

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

問題

  • 可是在執行make && make install,出現如下錯誤

xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
 #include <expat.h>
                   ^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/src/apr-util-1.6.1'
make: *** [all-recursive] Error 1

解決方法

  • 是由於缺乏了xml解釋器,只須要yum安裝 expat-devel 包便可

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

  • 這時再去執行make && make install 會正常執行

13.--enable-so \ 表示支持動態擴展模塊,Apache和PHP它們都會支持以一個模塊的形式存在

  • PHP是Apache的一個模塊,這個模塊實際上就是一個文件,就是 .so 後綴名的文件,那他以Apache的一個模塊形式存在,因此Apache自己是一個進程,是一個服務,在這個進程裏面,經過一些配置文件指定一個模塊的路徑,那就能夠去調用模塊。
  • PHP模塊是用來解析PHP的,執行PHP腳本的,因此就能夠經過PHP腳本將PHP模塊加載到進程裏面去,加載到主進程裏面去,
    • 當它遇到PHP解析的需求時,它就會去調用這個模塊,去執行一些操做
    • 這些模塊是一些獨立的文件
  • 並且還能夠指定有哪些動態擴展的模塊,須要加載哪些,這裏指定是most
    • --enable-mods-shared=most
      • most,就是絕大多數,大多數會用到的模塊,都會加載進來

14.查看/usr/local/apr-util/目錄下,會看到生成三個子目錄

[root@tianqi-01 apr-util-1.6.1]# ls /usr/local/apr-util
bin  include  lib
[root@tianqi-01 apr-util-1.6.1]# 

15.安裝httpd-2.4.29,首先切換到httpd-2.4.29/

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

16.安裝httpd-2.4.29

[root@tianqi-01 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

問題:

  • 這裏遇到了錯誤,以下

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

解決方法:

  • pcre是正則表達式的驅動庫,支持正則表達式
  • 能夠先yum list |grep pcre 查看,由於是缺乏庫,因此只須要找帶有 devel 或 lib 字符的,因此只須要安裝pcre-devel包便可——>yum install -y pcre-devel

[root@tianqi-01 httpd-2.4.29]# yum list |grep pcre
pcre.x86_64                                 8.32-17.el7                @anaconda
pcre.i686                                   8.32-17.el7                base     
pcre-devel.i686                             8.32-17.el7                base     
pcre-devel.x86_64                           8.32-17.el7                base     
pcre-static.i686                            8.32-17.el7                base     
pcre-static.x86_64                          8.32-17.el7                base     
pcre-tools.x86_64                           8.32-17.el7                base     
pcre2.i686                                  10.23-2.el7                base     
pcre2.x86_64                                10.23-2.el7                base     
pcre2-devel.i686                            10.23-2.el7                base     
pcre2-devel.x86_64                          10.23-2.el7                base     
pcre2-static.i686                           10.23-2.el7                base     
pcre2-static.x86_64                         10.23-2.el7                base     
pcre2-tools.x86_64                          10.23-2.el7                base     
pcre2-utf16.i686                            10.23-2.el7                base     
pcre2-utf16.x86_64                          10.23-2.el7                base     
pcre2-utf32.i686                            10.23-2.el7                base     
pcre2-utf32.x86_64                          10.23-2.el7                base     
[root@tianqi-01 httpd-2.4.29]# 

  • 下載pcre-devel包

[root@tianqi-01 httpd-2.4.29]# yum install -y pcre-devel

17.再次安裝,使用echo $?檢查是否安裝成功,這裏會看到成功安裝

[root@tianqi-01 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@tianqi-01 httpd-2.4.29]# echo $?
0
[root@tianqi-01 httpd-2.4.29]# 

18.執行make && make install

[root@tianqi-01 httpd-2.4.29]# make && make install

  • 錯誤:

collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory `/usr/local/src/httpd-2.4.29/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/httpd-2.4.29/support'
make: *** [all-recursive] Error 1

解決方法:

  • 刪除源碼包,從新解壓,從新編譯安裝,從新作一遍便可
    • 進入到/usr/local/src 目錄下,刪除源碼包

重作以後,仍然出現問題。

解決辦法:在後面添加 --with-included-apr

[root@tianqi-01 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 --with-included-apr

但是加上--with-included-apr編譯以後,出現瞭如下問題:

configure: Configuring Apache Portable Runtime library...
configure: 
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

解決辦法:

[root@tianqi-01 httpd-2.4.29]# cd /usr/local/src
[root@tianqi-01 src]# cp -r apr-1.6.3 /usr/local/src/httpd-2.4.29/srclib/apr
[root@tianqi-01 src]#  cp -r apr-util-1.6.1 /usr/local/src/httpd-2.4.29/srclib/apr-util
[root@tianqi-01 src]# 

而後再次編譯,則不會出現問題,並且make時也不會出現問題。

[root@tianqi-01 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 --with-included-apr

[root@tianqi-01 httpd-2.4.29]# echo $?
0
[root@tianqi-01 httpd-2.4.29]# make && make install

[root@tianqi-01 httpd-2.4.29]# echo $?
0

19.接下來便會完成安裝Apache

Apache安裝完成後

1.在安裝完成後,進入到/usr/local/apache2.4/目錄下,並 ls 查看有哪些目錄

[root@tianqi-01 httpd-2.4.29]# cd /usr/local/apache2.4
[root@tianqi-01 apache2.4]# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules
[root@tianqi-01 apache2.4]# 

2.在之後會接觸到的目錄就是 bin目錄,conf目錄,htdocs目錄

  • /bin目錄下,是可執行文件。也就是說,要啓動一個服務,它就是在bin/httpd下面有一個文件或者命令,bin/httpd也是核心的二進制文件

[root@tianqi-01 apache2.4]# ls bin/httpd
bin/httpd
[root@tianqi-01 apache2.4]# ls -l bin/httpd
-rwxr-xr-x 1 root root 2334360 Feb 27 19:38 bin/httpd
[root@tianqi-01 apache2.4]# du -sh !$
du -sh bin/httpd
2.3M    bin/httpd
[root@tianqi-01 apache2.4]# 

  • conf目錄,是配置文件所在目錄

[root@tianqi-01 apache2.4]# ls conf/
extra  httpd.conf  magic  mime.types  original
[root@tianqi-01 apache2.4]# 

  • htdocs目錄,是存放了一個訪問頁。啓動完httpd服務後,去訪問網站,默認的網站會放到 htdocs/目錄下

[root@tianqi-01 apache2.4]# ls htdocs/
index.html
[root@tianqi-01 apache2.4]# 

  • logs目錄,就是日誌相關的目錄
    • 包含:錯誤日誌,訪問日誌,
  • man目錄,就是一些幫助文檔

[root@tianqi-01 apache2.4]# ls man
man1  man8
[root@tianqi-01 apache2.4]# 

  • modules擴展模塊目錄,全部模塊都放到了modules目錄下
    • 每個模塊都表明着一個功能

[root@tianqi-01 apache2.4]# ls modules
httpd.exp             mod_authz_groupfile.so  mod_ext_filter.so           mod_proxy_balancer.so  mod_session_cookie.so
mod_access_compat.so  mod_authz_host.so       mod_file_cache.so           mod_proxy_connect.so   mod_session_dbd.so
mod_actions.so        mod_authz_owner.so      mod_filter.so               mod_proxy_express.so   mod_session.so
mod_alias.so          mod_authz_user.so       mod_headers.so              mod_proxy_fcgi.so      mod_setenvif.so
mod_allowmethods.so   mod_autoindex.so        mod_include.so              mod_proxy_fdpass.so    mod_slotmem_shm.so
mod_auth_basic.so     mod_buffer.so           mod_info.so                 mod_proxy_ftp.so       mod_socache_dbm.so
mod_auth_digest.so    mod_cache_disk.so       mod_lbmethod_bybusyness.so  mod_proxy_hcheck.so    mod_socache_memcache.so
mod_auth_form.so      mod_cache.so            mod_lbmethod_byrequests.so  mod_proxy_http.so      mod_socache_shmcb.so
mod_authn_anon.so     mod_cache_socache.so    mod_lbmethod_bytraffic.so   mod_proxy_scgi.so      mod_speling.so
mod_authn_core.so     mod_cgid.so             mod_lbmethod_heartbeat.so   mod_proxy.so           mod_status.so
mod_authn_dbd.so      mod_dav_fs.so           mod_log_config.so           mod_proxy_wstunnel.so  mod_substitute.so
mod_authn_dbm.so      mod_dav.so              mod_log_debug.so            mod_ratelimit.so       mod_unique_id.so
mod_authn_file.so     mod_dbd.so              mod_logio.so                mod_remoteip.so        mod_unixd.so
mod_authn_socache.so  mod_dir.so              mod_macro.so                mod_reqtimeout.so      mod_userdir.so
mod_authz_core.so     mod_dumpio.so           mod_mime.so                 mod_request.so         mod_version.so
mod_authz_dbd.so      mod_env.so              mod_negotiation.so          mod_rewrite.so         mod_vhost_alias.so
mod_authz_dbm.so      mod_expires.so          mod_proxy_ajp.so            mod_sed.so             mod_watchdog.so
[root@tianqi-01 apache2.4]# 

[root@tianqi-01 apache2.4]# du -sh modules/
6.3M    modules/
[root@tianqi-01 apache2.4]# 

3.查看Apache加載了哪些模塊

  • /usr/local/apache2.4/bin/httpd -M //查看加載的模塊
    • -M 把全部的模塊列出來等於
  • /usr/local/apache2.4/bin/apachectl -M //查看加載的模塊——>這是一個shell文件,它調用了二進制的httpd

[root@tianqi-01 apache2.4]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::1eb9:8f9e:264a:7159. 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)
[root@tianqi-01 apache2.4]# 

[root@tianqi-01 apache2.4]# /usr/local/apache2.4/bin/apachectl -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::1eb9:8f9e:264a:7159. 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)
[root@tianqi-01 apache2.4]# 

  • 在模塊的右側有小括號,裏面是 static 或 shared ,static是靜態
  • 靜態和動態的區別
    • 靜態是直接把模塊編譯進了主腳本或主二進制文件裏面
  • http是一個核心文件,這個文件加載了哪些模塊
  • 若是是static,那也就意味這個模塊在httpd裏面,和它綁定在了一塊兒,它們是一個總體
  • 若是是shared,說明它是一個擴展的模塊,這個模塊是一個文件,咱們能夠看到的 .so 文件,文件的目錄是在/usr/local/apache2.4/modules目錄下

啓動Apache2.4

1.在安裝完成Apache2.4後,Apache啓動不須要定義啓動腳本,也不須要放到/etc/init.d下去,直接使用命令行啓動就行

  • /usr/local/apache2.4/bin/apachectl start //命令行啓動Apache腳本
    • 啓動腳本後,雖然出現提示,但不表示啓動失敗
      • 若不想要出現提示,只須要編輯配置文件便可

[root@tianqi-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::1eb9:8f9e:264a:7159. Set the 'ServerName' directive globally to suppress this message
[root@tianqi-01 apache2.4]# 

2.查看Apache是否啓動,看httpd進程是否存在

[root@tianqi-01 apache2.4]# ps aux |grep httpd
root      53549  0.0  0.2  95528  2532 ?        Ss   19:52   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    53550  0.0  0.4 382356  4432 ?        Sl   19:52   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    53551  0.0  0.4 382356  4432 ?        Sl   19:52   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    53552  0.0  0.4 382356  4432 ?        Sl   19:52   0:00 /usr/local/apache2.4/bin/httpd -k start
root      53635  0.0  0.0 112660   984 pts/0    R+   19:53   0:00 grep --color=auto httpd

3.查看端口號——>httpd默認監聽端口爲80,mysqld默認監聽端口爲3306,25端口是發郵件的,22端口是遠程登陸的

[root@tianqi-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      778/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1009/master         
tcp6       0      0 :::80                   :::*                    LISTEN      53549/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      778/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1009/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      2164/mysqld         
[root@tianqi-01 apache2.4]#

友情連接:阿銘Linux

相關文章
相關標籤/搜索