5.1 11.6-11.9聽課筆記
下載二進制源碼包:
同mysql
解壓:
[root@localhost mariadb]#tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
將解壓的文件放到/usr/local/下並更名:
[root@localhost src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
運行scripts,指定用戶為mysql,指定mariaDB生成數據庫目錄存放數據位置:
1 用戶使用之前創建的mysql用戶;
2 對mariadb執行初始化
[root@localhost mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
檢驗初始化是否成功:
1 查看初始化過程是否出現2個ok
2 使用echo $?,為0則成功
[root@localhost mariadb]# echo $?
0
查看初始化生成的目錄:
[root@localhost mariadb]# ls /data/mariadb
aria_log.00000001 ibdata1 mysql
aria_log_control ib_logfile0 performance_schema
ib_buffer_pool ib_logfile1 test
*定義basedir:如果不定義basedir,則系統有可能去找之前/usr/local/下的mysql目錄
拷貝配置文件模板:
與mysql5.1前的版本類似,存在多個配置文件模板:
*配置文件最大的區別在於配置的緩存大小不同,可以根據內存大小不同選擇不同緩存的配置文件以達到更高的性能
*文件拷貝後可根據情況適當調整配置文件的某些參數
[root@localhost support-files]# cp my-small.cnf /usr/local/mariadb/my.cnf
*為與之前安裝的mysql區分,不將配置文件放在默認的etc下
拷貝啟動腳本:
[root@localhost support-files]# cp mysql.server /etc/init.d/mariadb
修改啟動腳本、配置文件參數:
…
Changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mariadb
datadir=/data/mariadb
conf=$basedir/my.cnf 為了不與mysql的配置文件產生沖突,指定配置文件路徑
…
echo $echo_n "Starting MySQL"
if test -x $bindir/mysqld_safe
then
# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
*defaults-file設置默認配置文件路徑
由於mysqld與mariadb監聽相同端口,所以兩個服務同時啟動會產生沖突:
1 檢查是否有mysqld服務啟動:
[root@localhost support-files]# ps aux |grep mysql
root 11826 0.0 0.0 113260 552 ? S 22:18 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
mysql 11951 0.1 44.0 1300784 444104 ? Sl 22:18 0:06 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock
root 13415 0.0 0.0 112676 980 pts/2 R+ 23:41 0:00 grep --color=auto mysql
[root@localhost support-files]# service mysqld stop 終止進程
Shutting down MySQL.. SUCCESS!
[root@localhost support-files]# ps aux |grep mysql
root 13442 0.0 0.0 112676 984 pts/2 S+ 23:42 0:00 grep --color=auto mysql
啟動mariadb並檢查啟動是否成功:
[root@localhost support-files]# /etc/init.d/mariadb start
Reloading systemd: [ 確定 ]
Starting mariadb (via systemctl): [ 確定 ]
[root@localhost support-files]# echo $?
0
[root@localhost support-files]# ps aux|grep mariadb 查看mariadb啟動是否成功
root 13483 0.0 0.1 115388 1732 ? S 23: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 13599 1.2 5.2 1125124 53408 ? Sl 23:47 0:01 /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/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root 13686 0.0 0.0 112676 984 pts/2 R+ 23:49 0:00 grep --color=auto mariadb
查看服務端口:
[root@localhost support-files]# 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 790/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 905/master
tcp6 0 0 :::22 :::* LISTEN 790/sshd
tcp6 0 0 ::1:25 :::* LISTEN 905/master
tcp6 0 0 :::3306 :::* LISTEN 13599/mysqld
問題:
機器上同時安裝mysql和mariadb,啟動服務後發現datadir不是預期的/data/mariadb
原因:mariadb配置文件中沒有配置datadir這個參數,所以服務調用了mysql的/etc/my.cnf
[root@localhost support-files]# ps aux|grep mariadb
root 13483 0.0 0.1 115388 1732 ? S 23: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 13599 1.2 5.2 1125124 53408 ? Sl 23:47 0:01 /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/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root 13686 0.0 0.0 112676 984 pts/2 R+ 23:49 0:00 grep --color=auto mariadb
解決辦法:
編輯指定的配置文件,指定datadir參數:
…
[mysqld]
datadir = /data/mariadb
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
…
重啟服務:
[root@localhost support-files]# /etc/init.d/mariadb restart
Restarting mariadb (via systemctl): [ 確定 ]
[root@localhost support-files]# ps aux|grep mariadb
root 14510 0.0 0.1 115388 1732 ? S 00:20 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 14629 4.1 5.5 1125024 55824 ? Sl 00:20 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 14665 0.0 0.0 112676 980 pts/2 R+ 00:20 0:00 grep --color=auto mariadb
*datadir已經改變成配置文件指定的datadir,僅在啟動腳本中定義datadir無效
11.7 Apache安裝 上
Apache即httpd,httpd的早期版本被這樣稱呼,從2.0版本開始改名叫httpd
早期主流版本1.3,目前主流版本為2.4,2.2.與2.4由於依賴軟件apr不同導致安裝方法不同;
Yum默認安裝的apr可以給2.2版本使用,但與2.4版本不匹配,此時無法使用yum安裝的apr,需要自己編譯;
Apr為一個通用函數庫,可以讓httpd不關心底層操作系統平臺,方便進行移植(將linux上運行的服務放到windows上可以照常運行)
11.8 Apache 安裝 中
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr 編譯源文件
configure: error: in `/usr/local/src/apr-1.6.3':
configure: error: no acceptable C compiler found in $PATH
*第一次由於缺少gcc套件導致檢查出現問題
[root@localhost apr-1.6.3]# echo $?
0
*Apr-util編譯依賴於已經安裝的apr,所以需要指定apr路徑
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# echo $?
0
[root@localhost apr-util-1.6.1]# make && make install 安裝文件
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
[root@localhost apr-util-1.6.1]# yum install -y expat-devel
[root@localhost apr-util-1.6.1]# make && make install
[root@localhost apr-util-1.6.1]# echo $?
0
[root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4.29 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most 編譯httpd文件,指定支持動態模塊,且指定支持大多數動態模塊
*checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@localhost httpd-2.4.29]# yum list |grep pcre 查找相關軟件
[root@localhost httpd-2.4.29]# yum install -y pcre-devel
[root@localhost httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4.29 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@localhost httpd-2.4.29]# echo $?
0
[root@localhost httpd-2.4.29]# make && make install
[root@localhost httpd-2.4.29]# echo $?
0
*第一次編譯、安裝httpd包出現問題,將apr、apr-util、httpd包全部重新安裝後問題解決
11.9 Apache安裝 下
Apache安裝完成,查看apache安裝的文件
[root@localhost local]# cd apache2.4.29
[root@localhost apache2.4.29]# ls
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@localhost apache2.4.29]# cd bin
[root@localhost bin]# ls
ab dbmmanage htcacheclean httpd
apachectl envvars htdbm httxt2dbm
apxs envvars-std htdigest logresolve
checkgid fcgistarter htpasswd rotatelogs
[root@localhost bin]# pwd
/usr/local/apache2.4.29/bin
Bin目錄用於存放apache啟動服務運行的二進制可執行文件
Conf是配置文件所在目錄
Htdocs放置網站默認訪問的頁面(一般是網站主頁)
Logs日誌(錯誤日誌、訪問日誌等)
Man幫助文檔
Modules擴展模塊,每個模塊對應一個功能,該目錄是整個apache文件中較大的目錄
[root@localhost apache2.4.29]# du -sh modules
6.3M modules
[root@localhost apache2.4.29]# /usr/local/apache2.4.29/bin/httpd –M 查看httpd都啟用了哪些模塊
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) static表示模塊被直接編譯進了主腳本(主二進制文件)即httpd中
authn_file_module (shared) shared表示為一個擴展模塊,一個.so文件,均被存放於modules下
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@localhost apache2.4.29]# /usr/local/apache2.4.29/bin/apachectl –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
httpd (pid 27496) already running 不是錯誤提示,暫時可以忽略
/usr/local/apache2.4.29/bin/apachectl是一個shell文件,幫助用戶調用二進制httpd,-M將模塊列出
啟動apache
[root@localhost apache2.4.29]# /usr/local/apache2.4.29/bin/apachectlAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
httpd (pid 27496) already running
[root@localhost apache2.4.29]# ps aux|grep httpd 查看httpd進程是否啟動
root 27496 0.0 0.2 70896 2208 ? Ss 22:59 0:00 /usr/local/apache2.4.29/bin/httpd
daemon 27497 0.0 0.4 359860 4256 ? Sl 22:59 0:00 /usr/local/apache2.4.29/bin/httpd
daemon 27498 0.0 0.4 359860 4256 ? Sl 22:59 0:00 /usr/local/apache2.4.29/bin/httpd
daemon 27499 0.0 0.4 359860 4256 ? Sl 22:59 0:00 /usr/local/apache2.4.29/bin/httpd
root 27658 0.0 0.0 112676 984 pts/1 R+ 23:14 0:00 grep --color=auto httpd
查看端口號
[root@localhost apache2.4.29]# 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 793/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1056/master
tcp6 0 0 :::80 :::* LISTEN 27496/httpd
tcp6 0 0 :::22 :::* LISTEN 793/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1056/master
5.1 11.6-11.9聽課筆記