4.21 LNMP環境介紹 4.22/23/24 Mariadb安裝 4.25 服務管理

LNMP環境介紹

Mariadb安裝

服務管理

LNMP環境介紹

Linux+Nginx+Mysql/mariadb+phpphp

Nginx:是一個WEB服務器,提供http服務css

Mysql/MariaDB:是個關係型數據,用來存數據的(用戶名、密碼、文章內容)mysql

PHP:是一個編程語言,經常使用來作網站(qq.com baidu.com google.com ask.apelearn.com)linux

Nginx是一個WEB服務器,因此用戶首先訪問到的就是Nginx(靜態的請求,會處理圖片、js、css,接收php的請求,可是不處理)把php的請求轉給後面的php-fpmsql

php-fpm會處理php相關的請求(叫作動態的請求)數據庫

動態與靜態編程

 所謂靜態,指的是Nginx能夠直接處理的圖片、js、css、視頻、音頻、flash等等vim

所謂動態,指的是這些請求須要和數據庫打交道。好比,用戶登陸過程,好比查看一篇文章,或者寫一篇文章centos

 

Mariadb

MariaDB是MySQL的一個分支。 MySQL --> SUN --> Oracle(最終被這家公司收購)  #由於可能有mysql有閉源的風險,想Facebook大公司已放棄了mysql數據庫,轉向marialDB數據庫。服務器

維基百科: https://zh.wikipedia.org/wiki/MariaDB#cite_note-103_release-21

官網 https://mariadb.org/

下載mariadb:

** 選擇免編譯版本** 4-49.png
** 複製連接地址** 4-50.png
在linux中下載到/usr/local/src下

[root@localhost src]# wget https://downloads.mariadb.org/interstitial/mariadb-10.3.11/bintar-linux-x86_64/mariadb-10.3.11-linux-x86_64.tar.gz

mariadb安裝流程

解壓 #建議把安裝包放在以下命令

/usr/local/src/
[root@localhost src]# tar zxvf mariadb-10.3.11-linux-x86_64.tar.gz
tar zxvf XXX.tar.gz    z:針對gz解壓
tar jxvf XXX.tar.bz2   j:針對bz2解壓
tar Jxvf XXX.tar.xz    J:針對xz解壓

壓縮 #拓展命令

tar zxvf XXX.tar.gz  XXX/   
tar jxvf XXX.tar.bz2 XXX/
tar Jxvf XXX.tar.xz XXX/

移動並更名 /usr/local/mysql  #之後工做建議把安裝程序放在這

[root@localhost src]# mv mariadb-10.3.11-linux-x86_64 /usr/local/mysql

建立目錄 及帳號

[root@localhost mysql]# mkdir -p /data/mysql
[root@localhost mysql]# useradd -M -s /sbin/nologin mysql
[root@localhost mysql]# grep mysql /etc/passwd
mysql:x:1000:1000::/home/mysql:/sbin/nologin
[root@localhost mysql]# chown -R mysql:mysql /data/mysql

初始化設置

[root@localhost mysql]# ./scripts/mysql_install_db  --datadir=/data/mysql --usr=mysql
 第一次安裝可能會有以下錯誤
error while loading shared libraries: libaio.so.1: cannot open shared object file: 
No such file or directory  
解決: yum install -y libaio libaio-devel

#注意哦!安裝好上面套件後,注意再次輸入初始化設置命令!

驗證是否成功 輸出是0是正確的 不正確的狀況顯示的是1

[root@localhost mysql]# echo $?    #對前面一條命令驗證是否成功
0

拷貝啓動腳本

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

編輯啓動腳本

[root@localhost mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql

啓動服務

[root@localhost mysql]# /etc/init.d/mysqld start

24. 服務管理

列出系統全部的服務

chkconfig --list    Centos6  (cento7版本也可用)
systemctl list-unit-files  centos7

chkconfig 增長服務

/etc/init.d/下有mysqld 而且權限是755 (前提,這樣才能增長服務)

[root@localhost init.d]# pwd
/etc/init.d
[root@localhost init.d]# ll |grep mys
-rwxr-xr-x. 1 root root 12193 Jan 24 00:39 mysqld
[root@localhost mysql]# chkconfig --add mysqld

開機啓動服務

chkconfig mysqld off
chkconfig mysqld on
# 25. Mariadb安裝(下)

## 修改配置文件my.cnf

 

[root@localhost init.d]# vi /etc/my.cnf

 

datadir=/data/mysql socket=/tmp/mysql.sock log-error=/data/mysql/mariadb.log pid-file=/data/mysql/mariadb.pid

啓動服務

/etc/init.d/mysqld start  == service mysqld start

啓動成功以下

[root@localhost mysql]# service mysqld start Starting mysqld (via systemctl): [ OK ]

用ps aux|grep mysql 或netstat -lnp查看監聽端口是否開啓服務 #3306mariadb端口

接着鏈接數據庫,數據庫加密碼。遠程登陸其餘服務器, 系統環境變量PATH: echo $PATH
PATH的做用:能夠直接用PATH這些路徑裏面的文件,不用敲絕對路徑了(臨時有效)。

[root@test01 mysql]# ps aux |grep mysql  查看一個進程查看一個服務
root       3159  0.0  0.1 115380  1732 ?        S    16:28   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/test01.pid
mysql      3244  0.2  8.4 1254884 84544 ?       Sl   16:28   0:00 /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/mariadb.log --pid-file=/data/mysql/test01.pid --socket=/tmp/mysql.sock
root       3279  0.0  0.0 112664   968 pts/0    S+   16:30   0:00 grep --color=auto mysql

[root@test01 mysql]# netstat -lnp    查看監聽端口,查看有沒有3306端口
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      973/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1253/master         
tcp6       0      0 :::3306                 :::*                    LISTEN      3244/mysqld         
tcp6       0      0 :::22                   :::*                    LISTEN      973/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1253/master         
udp        0      0 127.0.0.1:323           0.0.0.0:*                           630/chronyd         
udp6       0      0 ::1:323                 :::*                                630/chronyd         
raw6       0      0 :::58                   :::*                    7           670/NetworkManager  
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name     Path
unix  2      [ ACC ]     SEQPACKET  LISTENING     12858    1/systemd            /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     14957    1/systemd            /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     19060    1253/master          private/defer
unix  2      [ ACC ]     STREAM     LISTENING     19063    1253/master          private/trace
unix  2      [ ACC ]     STREAM     LISTENING     19066    1253/master          private/verify
unix  2      [ ACC ]     STREAM     LISTENING     19073    1253/master          private/proxymap
unix  2      [ ACC ]     STREAM     LISTENING     19076    1253/master          private/proxywrite
unix  2      [ ACC ]     STREAM     LISTENING     19079    1253/master          private/smtp
unix  2      [ ACC ]     STREAM     LISTENING     19082    1253/master          private/relay
unix  2      [ ACC ]     STREAM     LISTENING     19088    1253/master          private/error
unix  2      [ ACC ]     STREAM     LISTENING     19053    1253/master          private/rewrite
unix  2      [ ACC ]     STREAM     LISTENING     19091    1253/master          private/retry
unix  2      [ ACC ]     STREAM     LISTENING     19094    1253/master          private/discard
unix  2      [ ACC ]     STREAM     LISTENING     19097    1253/master          private/local
unix  2      [ ACC ]     STREAM     LISTENING     19100    1253/master          private/virtual
unix  2      [ ACC ]     STREAM     LISTENING     19103    1253/master          private/lmtp
unix  2      [ ACC ]     STREAM     LISTENING     19106    1253/master          private/anvil
unix  2      [ ACC ]     STREAM     LISTENING     19109    1253/master          private/scache
unix  2      [ ACC ]     STREAM     LISTENING     19045    1253/master          public/qmgr
unix  2      [ ACC ]     STREAM     LISTENING     19056    1253/master          private/bounce
unix  2      [ ACC ]     STREAM     LISTENING     19069    1253/master          public/flush
unix  2      [ ACC ]     STREAM     LISTENING     19085    1253/master          public/showq
unix  2      [ ACC ]     STREAM     LISTENING     19050    1253/master          private/tlsmgr
unix  2      [ ACC ]     STREAM     LISTENING     30687    3244/mysqld          /tmp/mysql.sock
unix  2      [ ACC ]     STREAM     LISTENING     19038    1253/master          public/pickup
unix  2      [ ACC ]     STREAM     LISTENING     19042    1253/master          public/cleanup
unix  2      [ ACC ]     STREAM     LISTENING     8405     1/systemd            /run/systemd/journal/stdout
unix  2      [ ACC ]     STREAM     LISTENING     12784    1/systemd            /run/systemd/private


[root@test01 mysql]# ls -l /tmp/
總用量 20
lrwxrwxrwx. 1 root  root     5 1月  23 22:42 333.txt -> 1.txt
lrwxrwxrwx. 1 root  root    11 1月  23 22:48 44.txt -> /root/1.txt
-rw-r--r--. 1 root  root  1572 1月  16 20:09 CentOS7-Base-163.repo123
-rw-r--r--. 1 root  root   516 1月  18 17:18 inittab
-rwx------. 1 root  root   836 1月  17 00:03 ks-script-fPPgkL
srwxrwxrwx. 1 mysql mysql    0 1月  24 16:28 mysql.sock
-rw-r--r--. 1 root  root  1044 1月  18 17:27 passwd.txt
drwx------. 3 root  root    17 1月  18 15:10 systemd-private-32ccfac892ba43a891ba41d70c22bae1-vmtools
drwx------. 3 root  root    17 1月  24 14:22 systemd-private-bf6f7e606d70439da08fad1ca2735245-vmtools
drwx------. 3 root  root    17 1月  22 12:10 systemd-private-f6f758ff9d8f483486f4d6e25fabe148-vmtools
-rw-------. 1 root  root     0 1月  16 23:52 yum.log
-rw-r--r--. 1 root  root   385 1月  17 20:31 yu.txt
[root@test01 mysql]# ls -l /tmp/mysql.sock 
srwxrwxrwx. 1 mysql mysql 0 1月  24 16:28 /tmp/mysql.sock

鏈接mySQL/mariaDB
[root@test01 mysql]# /usr/local/mysql/bin/mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.12-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> Bye

定義變量直接登陸mysql
[root@test01 mysql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@test01 mysql]# PATH=$PATH:/usr/local/mysql/bin

[root@test01 mysql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

[root@test01 mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@test01 mysql]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

[root@test01 mysql]# source /etc/profile

[root@test01 mysql]# mysql -uroot    能夠直接用PATH這些路徑裏面的文件,不用敲絕對路徑了。 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.12-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

[root@test01 mysql]# mysqladmin -uroot password "chamlinux"
[root@test01 mysql]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@test01 mysql]# mysql -uroot -pchamlinux
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.3.12-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 


[root@test01 mysql]# mysql -uroot -pchamlinux -S/tmp/mysql.sock  指定sock登陸
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.3.12-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

鏈接遠程其餘服務器數據庫
[root@test01 mysql]# mysql -uroot -pchamlinux -h192.168.28.108 -P3306
相關文章
相關標籤/搜索