1. 程式人生 > >安裝mariadb和apache服務

安裝mariadb和apache服務

comm address get auth 進程 instr 準備 -h all

安裝mariadb數據庫

準備工作:
下載mariadb
官網:https://mariadb.com,選擇download下載免編譯安裝的版本
創建mariadb運行用戶,創建用戶組,創建數據存儲目錄,在初始化時需要指定這些項

[root@localhost ]# useradd mysql
[root@localhost ]# mkdir -p /data/mariadb/

解壓至當前目錄,並移動到/usr/local/目錄下重命名為mariadb,並進入mariadb目錄下

[root@localhost src]# tar zxf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz -C .
[root@localhost src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb

創建mariadb數據存儲目錄(如/data/mariadb),創建運行用戶,運行用戶和mysql使用同一個用戶,並初始化mariadb數據庫

[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 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/
[root@localhost mariadb]# echo $?
0                      <----初始化成功

拷貝mariadb的配置文件和啟動腳本

[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配置文件,這裏不對mariadb做更高級的功能,這裏保持默認不進行更改

[root@localhost mariadb]# vim /usr/local/mariadb/my.cnf 

# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it‘s important that the mysqld daemon
# doesn‘t use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3306
data   = /data/mariadb/            <-------指定保存數據的目錄
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

更改啟動腳本文件,指定安裝目錄、數據存儲目錄、配置文件路徑信息,start下的--default-file=需要指定出mariadb的配置文件路徑的變量,以便讓服務正常啟動並使用

# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mariadb
datadir=/data/mariadb
conf=$bashdir/my.cnf
--------------------------------------省略內容---------------------------------
 ‘start‘)
    # Start daemon

    # Safeguard (relative paths, core dumps..)
    cd $basedir

    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" "$@" &

啟動mariadb服務

[root@localhost mariadb]# /etc/init.d/mariadb start
Reloading systemd: [ 確定 ]
Starting mariadb (via systemctl): [ 確定 ]
[root@localhost mariadb]# ps -aux |grep mariadb
root 2090 0.0 0.0 112724 976 pts/1 R+ 02:39 0:00 grep --color=auto mariadb
mysql 23181 0.0 17.9 1112632 182888 ? Sl 7月28 0:06 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/usr/local/mysql/data/localhost.pid --port=3306
[root@localhost mariadb]# netstat -ntlp |grep 3306
tcp6 0 0 :::3306 :::* LISTEN 23181/mysqld 

安裝apache

apache是一個基金會的名字,httpd是服務需要安裝的包,早期的名字叫做apache
apache官網:www .apache .org
這裏下載的是2.4.33版本的安裝包
httpd-2.4.33.tar.gz
安裝apache還要安裝底層的一個apr和apr-util的函數庫,這裏使用的版本如下
apr-1.6.3.tar.gz
apr-util-1.6.1.tar.gz

apr安裝步驟

安裝apr和apr-util的通用函數庫,可以讓httpd服務不關心底層系統平臺,可方便的再linux和windows間移植,文章中地址僅參考,請不要直接復制下載!

[root@localhost src]# wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.3.tar.gz
--2018-07-28 23:45:55-- http://mirrors.hust.edu.cn/apache/apr/apr-1.6.3.tar.gz
正在解析主機 mirrors.hust.edu.cn (mirrors.hust.edu.cn)... 202.114.18.160
正在連接 mirrors.hust.edu.cn (mirrors.hust.edu.cn)|202.114.18.160|:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:1072661 (1.0M) [application/octet-stream]
正在保存至: “apr-1.6.3.tar.gz”

100%[======================================================>] 1,072,661 130KB/s 用時 8.8s   
2018-07-28 23:46:04 (119 KB/s) - 已保存 “apr-1.6.3.tar.gz” [1072661/1072661])
[root@localhost src]# ls
apr-1.6.3.tar.gz httpd-2.4.33.tar.gz mariadb-10.0.16-linux-glibc_214-x86_64.tar.gz pip-10.0.1 Python-3.7.0.tgz tmp
cmake-3.12.0.tar.gz jiaoben mysql-5.7.22 pip-10.0.1.tar.gz setuptools-39.2.0 user
httpd-2.4.33 jisuan.py mysql-5.7.22.tar.gz Python-3.7.0 setuptools-39.2.0.zip
[root@localhost src]# wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
--2018-07-28 23:46:17-- http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
正在解析主機 mirrors.hust.edu.cn (mirrors.hust.edu.cn)... 202.114.18.160
正在連接 mirrors.hust.edu.cn (mirrors.hust.edu.cn)|202.114.18.160|:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:554301 (541K) [application/octet-stream]
正在保存至: “apr-util-1.6.1.tar.gz”

100%[==================================================>] 554,301 110KB/s 用時 5.5s   

2018-07-28 23:46:23 (98.4 KB/s) - 已保存 “apr-util-1.6.1.tar.gz” [554301/554301])

[root@localhost src]# tar zxf apr-1.6.3.tar.gz -C .
[root@localhost src]# cd apr-1.6.3/
[root@localhost 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
----------------------省略過程-----------------------
config.status: executing libtool commands
rm: cannot remove ‘libtoolT‘: No such file or directory          <---有提示但並不是錯誤
config.status: executing default commands
[root@localhost apr-1.6.3]# echo $?
0
[root@localhost apr-1.6.3]# make;make install
------------------------過程省略
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 644 /usr/local/src/apr-1.6.3/build/apr_common.m4 /usr/local/apr/build-1
/usr/bin/install -c -m 644 /usr/local/src/apr-1.6.3/build/find_apr.m4 /usr/local/apr/build-1
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
[root@localhost apr-1.6.3]# echo $?
0

編譯安裝apr-util

解壓apr-util的打包文件,編譯安裝apr-util,編譯apr-util函數庫時需要指定apr的安裝路徑,這樣才可以正確的編譯

[root@localhost src]# tar zxf apr-util-1.6.1.tar.gz -C .
[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
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
---------------------------過程省略------------------
config.status: executing default commands
[root@localhost apr-util-1.6.1]# echo $?
0
[root@localhost apr-util-1.6.1]# make;make install
make[1]: 進入目錄“/usr/local/src/apr-util-1.6.1”
---------------------------過程省略------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
[root@localhost apr-util-1.6.1]# echo $?
0

編譯安裝apache

解壓apache打包文件,並進入執行(這裏反斜杠表示脫意,把一條命令寫成多行輸入)
./configure \
--prefix=/usr/local/httpd \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-so \ 添加--enable-so支持動態擴展的模塊
--enable-mods-shared=most 添加大部分需要用到的功能模塊

[root@localhost httpd-2.4.33]# ./configure > --prefix=/usr/local/httpd > --with-apr=/usr/local/apr > --with-apr-util=/usr/local/apr-util > --enable-so > --enable-mods-shared=most
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
------------------------省略過程--------------------
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:
    Server Version: 2.4.33
    Install prefix: /usr/local/httpd
    C compiler:     gcc -std=gnu99
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E

[root@localhost httpd-2.4.33]# echo $?
0
[root@localhost httpd-2.4.33]# make;make install
--------------------編譯過程省略--------------------------
mkdir /usr/local/httpd/manual
make[1]: 離開目錄“/usr/local/src/httpd-2.4.33”
[root@localhost httpd-2.4.33]# echo $?
0                                       <---------------編譯結果無報錯

編譯過程中如果有報錯不存在某個庫,就根據報錯的信息安裝對應的包,庫安裝包一般是以level或devel字眼的軟件包,使用yum list可以查找出對應的安裝包

apache每個目錄存儲文件簡單了解

[root@localhost httpd]# ll -h bin/httpd 
-rwxr-xr-x 1 root root 2.3M 7月 29 00:32 bin/httpd            <------apache的啟動文件
[root@localhost httpd]# ls conf/             
extra httpd.conf magic mime.types original       <-----配置文件所在目錄
[root@localhost httpd]# ls htdocs/
index.html                                     <-----默認網站的根目錄
[root@localhost httpd]# ls logs/             <---------日誌文件目錄
[root@localhost httpd]# ls modules/          <--------已經加載的模塊,static是靜態模塊,shared是動態加載的模塊
httpd.exp mod_authz_dbd.so mod_deflate.so mod_log_config.so mod_proxy_scgi.so mod_socache_dbm.so
mod_access_compat.so mod_authz_dbm.so mod_dir.so mod_log_debug.so mod_proxy.so mod_socache_memcache.so
mod_actions.so mod_authz_groupfile.so mod_dumpio.so mod_logio.so mod_proxy_uwsgi.so mod_socache_shmcb.so
mod_alias.so mod_authz_host.so mod_env.so mod_macro.so mod_proxy_wstunnel.so mod_speling.so
mod_allowmethods.so mod_authz_owner.so mod_expires.so mod_mime.so mod_ratelimit.so mod_ssl.so
mod_auth_basic.so mod_authz_user.so mod_ext_filter.so mod_negotiation.so mod_remoteip.so mod_status.so
mod_auth_digest.so mod_autoindex.so mod_file_cache.so mod_proxy_ajp.so mod_reqtimeout.so mod_substitute.so
mod_auth_form.so mod_buffer.so mod_filter.so mod_proxy_balancer.so mod_request.so mod_unique_id.so
mod_authn_anon.so mod_cache_disk.so mod_headers.so mod_proxy_connect.so mod_rewrite.so mod_unixd.so
mod_authn_core.so mod_cache.so mod_include.so mod_proxy_express.so mod_sed.so mod_userdir.so
mod_authn_dbd.so mod_cache_socache.so mod_info.so mod_proxy_fcgi.so mod_session_cookie.so mod_version.so
mod_authn_dbm.so mod_cgid.so mod_lbmethod_bybusyness.so mod_proxy_fdpass.so mod_session_dbd.so mod_vhost_alias.so
mod_authn_file.so mod_dav_fs.so mod_lbmethod_byrequests.so mod_proxy_ftp.so mod_session.so mod_watchdog.so
mod_authn_socache.so mod_dav.so mod_lbmethod_bytraffic.so mod_proxy_hcheck.so mod_setenvif.so
mod_authz_core.so mod_dbd.so mod_lbmethod_heartbeat.so mod_proxy_http.so mod_slotmem_shm.so
[root@localhost httpd]# /usr/local/httpd/bin/httpd -M
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using ::1. 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)

啟動apache編譯安裝的默認沒有啟動腳本,這裏可以使用命令的方式來進行啟動,啟動後並查看相應進程及端口號

[root@localhost httpd]# /usr/local/httpd/bin/apachectl start
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using ::1. Set the ‘ServerName‘ directive globally to suppress this message
[root@localhost httpd]# ps -axu |grep httpd
root 873 0.0 0.2 70952 2252 ? Ss 01:19 0:00 /usr/local/httpd/bin/httpd -k start
daemon 874 0.0 0.2 359916 2220 ? Sl 01:19 0:00 /usr/local/httpd/bin/httpd -k start
daemon 875 0.0 0.2 359916 2220 ? Sl 01:19 0:00 /usr/local/httpd/bin/httpd -k start
daemon 876 0.0 0.2 359916 2220 ? Sl 01:19 0:00 /usr/local/httpd/bin/httpd -k start
root 959 0.0 0.0 112724 976 pts/2 R+ 01:19 0:00 grep --color=auto httpd
[root@localhost httpd]# netstat -nltp
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 1085/sshd           
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1388/master         
tcp6 0 0 :::3306 :::* LISTEN 23181/mysqld        
tcp6 0 0 :::80 :::* LISTEN 873/httpd           
tcp6 0 0 :::22 :::* LISTEN 1085/sshd           
tcp6 0 0 ::1:25 :::* LISTEN 1388/master 

安裝mariadb和apache服務