LAMP架構mariadb/apache的安裝及基本使用

 
11月12日任務
11.6 MariaDB安裝
11.7/11.8/11.9 Apache安裝
 

MariaDB安裝(相似於mysql安裝)

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.gzphp

  1. 解壓二進制已編譯包
[root@localhost src]# tar zxf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  1. 移動至/usr/local/下
[root@localhost src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
[root@localhost local]# cd mariadb/
  1. 初始化腳本,指定basedir和datadir
# 這裏跟mysql安裝不一樣的地方是須要額外指定basedir

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

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/local/mariadb//bin/mysqladmin' -u root password 'new-password'
'/usr/local/mariadb//bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'/usr/local/mariadb//bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr/local/mariadb/' ; /usr/local/mariadb//bin/mysqld_safe --datadir='/data/mariadb'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mariadb//mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
  1. 拷貝配置文件(按服務器內存選擇,這裏測試選擇my-small.cnf
# 這裏是實現mysql和mariadb同存於一個機器中的作法
# 若是你的主機內只有mariadb,那麼直接複製到/etc命令下,命名爲my.cnf也行;對於的basedir也一樣修改便可
[root@localhost mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
[root@localhost mariadb]# vi /usr/local/mariadb/my.cnf 
在[mysqld]下插入下面的內容
basedir=/usr/local/mariadb
datadir=/data/mariadb
  1. 拷貝啓動腳本至/etc/init.d/目錄下,並修改內容
[root@localhost mariadb]# cp support-files/mysql.server /etc/init.d/mariadb
[root@localhost mariadb]# vi /etc/init.d/mariadb 
修改內容
basedir=/usr/local/mariadb
datadir=/data/mariadb
confdir=$basedir/my.cnf    #新增

並在下面啓動項內添加--defaults-file選項加載指定的配置文件
$bindir/mysqld_safe --defaults-file="$confdir" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
  1. 啓動腳本並驗證是否成功
[root@localhost mariadb]# /etc/init.d/mariadb start
Reloading systemd:                                         [  肯定  ]
Starting mariadb (via systemctl):                          [  肯定  ]

[root@localhost mariadb]# ps aux | grep mysql
root       3466  0.5  0.1 115392  1736 ?        S    13:04   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      3588 12.7  5.7 1125028 57864 ?       Sl   13:04   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       3624  0.0  0.0 112676   972 pts/0    S+   13:04   0:00 grep --color=auto mysql

注意第4步中拷貝、重命名配置文件的過程你能夠任意存儲,只要在啓動腳本內指定好配置文件的路徑,就能夠安裝啓動成功。html

安裝apache

apache是一個基金會的名字,httpd纔是要安裝的軟件包,其早期名字爲apache。mysql

Apache官網 www.apache.orglinux

軟件包下載地址

因爲軟件更新,下面的地址連接截止爲...
到http://mirrors.cnnic.cn/apache/查看當前版本號

httpd:      http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.28.tar.gz 
apr:       http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
apr-util:   http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz

軟件安裝

apr和apr-utilc++

  1. 先安裝apr
[root@localhost src]# tar -zxvf apr-1.6.3.tar.gz
[root@localhost src]# cd apr-1.6.3/
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr

# 判斷是否編譯成功
[root@localhost src]# echo $?
0
[root@localhost src]# make && make install
  1. 安裝apr-util
[root@localhost src]# tar -zxvf apr-util-1.6.1.tar.gz 
[root@localhost src]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/loca/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# echo $?
0
[root@localhost src]# make && make install
  1. 安裝apache2.4
[root@localhost src]# tar -zxvf httpd-2.4.28.tar.gz
[root@localhost src]# cd httpd-2.4.28
[root@localhost httpd-2.4.28]# ./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@localhost httpd-2.4.28]# echo $?
0
[root@localhost httpd-2.4.28]# make && make install

編譯參數說明:sql

--enable-so 支持動態擴展模塊
如php模塊,其實質爲一個.so文件,經過apache的配置文件制定php模塊位置,來加載php,在apache須要php解析時才調用。
--enable-mods-shared=most 容許大多數的模塊擴展到apache主進程

查看編譯時的參數apache

[root@localhost ~]# cat /usr/local/apache/build/config.nice 
#! /bin/sh
#
# Created by configure

"./configure" \
"--prefix=/usr/local/apache" \
"--with-apr=/usr/local/apr" \
"--with-apr-util=/usr/local/apr-util/" \
"--enable-so" \
"--enable-mods-shared=most" \
"$@"

apache文件目錄說明

  1. bin目錄
# apache二進制文件存放目錄
[root@localhost apache2.4]# ls bin/
ab         checkgid   envvars-std   htdbm     httpd       rotatelogs
apachectl  dbmmanage  fcgistarter   htdigest  httxt2dbm
apxs       envvars    htcacheclean  htpasswd  logresolve
  1. conf目錄
# apache配置文件存放目錄
[root@localhost apache2.4]# ls conf/
extra  httpd.conf  magic  mime.types  original
  1. htdocs目錄
# 訪問apache網絡服務時的默認網頁存放目錄
[root@localhost apache2.4]# ls htdocs/
index.html
  1. modules目錄
# apache可加載模塊文件存放目錄
[root@localhost apache2.4]# ls modules/
httpd.exp                   mod_lbmethod_heartbeat.so
mod_access_compat.so        mod_log_config.so
mod_actions.so              mod_log_debug.so
mod_alias.so                mod_logio.so
mod_allowmethods.so         mod_macro.so
mod_auth_basic.so           mod_mime.so
mod_auth_digest.so          mod_negotiation.so
mod_auth_form.so            mod_proxy_ajp.so
mod_authn_anon.so           mod_proxy_balancer.so
mod_authn_core.so           mod_proxy_connect.so
...

查看當前已加載模塊服務器

# 其中static爲已經編譯進二進制文件bin/httpd內的模塊;
# shared爲動態加載模塊,須要在編譯時添加參數--enable-so
[root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl -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)

啓動/關閉apache

# 啓動
[root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl start

[root@localhost apache2.4]# ps aux | grep httpd
root      40316  0.1  0.2  70908  2204 ?        Ss   19:44   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    40317  0.0  0.4 359872  4256 ?        Sl   19:44   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    40318  0.0  0.4 359872  4256 ?        Sl   19:44   0:00 /usr/local/apache2.4/bin/httpd -k start
daemon    40319  0.0  0.4 359872  4256 ?        Sl   19:44   0:00 /usr/local/apache2.4/bin/httpd -k start
root      40402  0.0  0.0 112680   972 pts/0    R+   19:44   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      1598/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2415/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      1968/mysqld         
tcp6       0      0 :::80                   :::*                    LISTEN      40316/httpd         
tcp6       0      0 :::22                   :::*                    LISTEN      1598/sshd           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2415/master         

# 關閉
[root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl stop

軟件安裝時可能會遇到的問題

  1. ./configure編譯apr時提示(不是錯誤):
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands

[root@localhost apr-1.6.3]# echo $?
0
  1. make安裝apr-util時報錯:
xml/apr_xml.c:35:19: 致命錯誤:expat.h:沒有那個文件或目錄
 #include <expat.h>
                   ^
編譯中斷。

解決:缺乏expat-devel包網絡

yum install -y expat-devel
  1. ./configure httpd時報錯:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

解決:缺乏prce庫(正則相關的庫)dom

yum install -y pcre-devel
  1. make http時報錯:
...
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] 錯誤 1
make[2]: 離開目錄「/usr/local/src/httpd-2.4.28/support」
make[1]: *** [all-recursive] 錯誤 1
make[1]: 離開目錄「/usr/local/src/httpd-2.4.28/support」
make: *** [all-recursive] 錯誤 1

解決:安裝libxml2-devel包

詳細步驟參見:https://my.oschina.net/LuCastiel/blog/1590706

可能缺乏的軟件包

編譯安裝前提

yum install -y gcc gcc-c++

安裝apr/apr-util/httpd

yum install -y expat-devel pcre-devel
相關文章
相關標籤/搜索