2019獨角獸企業重金招聘Python工程師標準>>>
LNMP環境介紹 Mariadb安裝 服務管理 LNMP環境介紹 Linux+Nginx+Mysql/mariadb+php
Nginx:是一個WEB服務器,提供http服務
Mysql/MariaDB:是個關系型數據,用來存數據的(用戶名、密碼、文章內容)
PHP:是一個編程語言,常用來做網站(qq.com baidu.com google.com ask.apelearn.com)
Nginx是一個WEB服務器,所以用戶首先訪問到的就是Nginx(靜態的請求,會處理圖片、js、css,接收php的請求,但是不處理)把php的請求轉給后面的php-fpm
php-fpm會處理php相關的請求(叫做動態的請求)
動態與靜態
?所謂靜態,指的是Nginx可以直接處理的圖片、js、css、視頻、音頻、flash等等
所謂動態,指的是這些請求需要和數據庫打交道。比如,用戶登錄過程,比如查看一篇文章,或者寫一篇文章
?
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:
** 選擇免編譯版本** ** 復制鏈接地址** 在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 ServerCopyright (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 ServerCopyright (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 ServerCopyright (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 ServerCopyright (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
?
轉載于:https://my.oschina.net/u/4080783/blog/3013197
總結
以上是生活随笔 為你收集整理的4.21 LNMP环境介绍 4.22/23/24 Mariadb安装 4.25 服务管理 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。