LAMP架構介紹以及MySQL安裝
11月9日任務
11.1 LAMP架構介紹
11.2 MySQL、MariaDB介紹
11.3/11.4/11.5 MySQL安裝
11.1 、LAMP架構介紹
# Apache和PHP是一體的,必須在一臺伺服器上,但是MySQL可以單獨存在一臺伺服器上,當用戶訪問量很小的時候,三個服務也可以同時放在一臺伺服器上,但當訪問量比較大時就要分開。Apache通過PHP模組從MySQL抽取資料,這個屬於動態檔案。還有一種情況是Apache直接從Apache子目錄裡邊抽取檔案為靜態檔案,例如訪問網頁的logo就是從子目錄裡邊抽取的。
11.2、MySQL_Mar i aDB介紹
11.3、MySQL安裝(上)
-
MySQL的幾個常用安裝包:rpm、原始碼包、二進位制免編譯
-
cd /usr/local/src
-
wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
-
tar -zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
-
mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
-
cd /usr/local/mysql
-
useradd mysql
-
mkdir /data/
-
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
-
cp support-files/my-default.cnf /etc/my.cnf
-
cp support-files/mysql.server /etc/init.d/mysqld
-
vi /etc/init.d/mysqld
-
定義basedir和datadir
-
/etc/init.d/mysqld start
11.4、MySQL安裝(中)
[[email protected] mysql]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz [[email protected] src]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz [[email protected] src]# ls apr-1.6.5 httpd-2.4.34.tar.gz apr-1.6.5.tar.gz mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz apr-util-1.6.1 pcre-8.10 apr-util-1.6.1.tar.gz pcre-8.10.zip httpd-2.4.34 [[email protected] src]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz [[email protected] src]# ls apr-1.6.5 httpd-2.4.34.tar.gz apr-1.6.5.tar.gz mysql-5.7.23-linux-glibc2.12-x86_64 apr-util-1.6.1 mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz apr-util-1.6.1.tar.gz pcre-8.10 httpd-2.4.34 pcre-8.10.zip [[email protected] src]# mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql [[email protected] src]# cd .. [[email protected] local]# ls apache apr-util etc include lib libexec pcre share apr bin games iptables.sh lib64 mysql sbin src [[email protected] local]# cd mysql/ [[email protected] mysql]# ls bin docs lib README support-files COPYING include man share [[email protected] mysql]# useradd mysql [[email protected] mysql]# mkdir /data/ [[email protected] mysql]# ls bin docs man README sql-bench COPYING include my.cnf scripts support-files data lib mysql-test share [[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql [[email protected] mysql]# echo $? 0 [[email protected] mysql]# ls support-files/my-default.cnf support-files/my-default.cnf [[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnf #拷貝配置檔案到預設目錄下 cp:是否覆蓋"/etc/my.cnf"? y
11.5、MySQL安裝(下)
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld #拷貝啟動指令碼 [[email protected] mysql]# vim /etc/init.d/mysqld
[[email protected] mysql]# ls -l /etc/init.d/mysqld -rwxr-xr-x 1 root root 10592 11月 10 11:19 /etc/init.d/mysqld [[email protected] mysql]# chkconfig --add mysqld #加入到開機啟動服務 [[email protected] mysql]# chkconfig --list 注:該輸出結果只顯示 SysV 服務,並不包含 原生 systemd 服務。SysV 配置資料 可能被原生 systemd 配置覆蓋。 要列出 systemd 服務,請執行 'systemctl list-unit-files'。 檢視在具體 target 啟用的服務請執行 'systemctl list-dependencies [target]'。 mysqld 0:關 1:關 2:開 3:開 4:開 5:開 6:關 netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關 network 0:關 1:關 2:開 3:開 4:開 5:開 6:關 [[email protected] mysql]# service mysqld start #手動啟動指令碼 Starting MySQL.Logging to '/data/mysql/zgxlinux-01.err'. . SUCCESS! [[email protected] mysql]# ps aux |grep mysql #檢視程序 root 14195 0.0 0.1 11812 1608 pts/0 S 11:23 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/zgxlinux-01.pid mysql 14303 2.2 44.6 1302720 449776 pts/0 Sl 11:23 0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=zgxlinux-01.err --pid-file=/data/mysql/zgxlinux-01.pid root 14333 0.0 0.0 112720 980 pts/0 R+ 11:23 0:00 grep --color=auto mysql [[email protected] mysql]# netstat -lntp #檢視監聽埠 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 192.168.56.128:873 0.0.0.0:* LISTEN 1885/rsync tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 952/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1114/master tcp6 0 0 :::3306 :::* LISTEN 14303/mysqld tcp6 0 0 :::22 :::* LISTEN 952/sshd tcp6 0 0 ::1:25 :::* LISTEN 1114/master
#停掉服務,這裡注意最好不適用kill命令,因為kill命令是直接關閉,可能會丟資料。killall會先停止當前的寫讀操作,然後把沒有寫入的資料寫入到快取中,當資料寫完後再關閉。以後工作中如果停止mysql程序,一分鐘還沒有關閉,這個時候不要強制關閉,慢慢等著寫入快取。
[[email protected] mysql]# yum install psmisc #killall命令沒有的話安裝這個包 [[email protected] mysql]# killall mysqld [[email protected] mysql]# ps aux |grep mysql root 14424 0.0 0.0 112720 980 pts/0 R+ 11:35 0:00 grep --color=auto mysql