老男孩Linux運(yùn)維58期yum方式部署LNMP:
1)yum安裝NGINX
[root@web02 ~]# cat /etc/yum.repos.d/nginx.repo #<==配置Nginx官方y(tǒng)um源。
[nginx]
name=Nginx repo by oldboy
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
說明:如果是用epel源安裝需要提前配置epel源,本書安裝系統(tǒng)時(shí)已經(jīng)配置過了epel源了。
[root@web02 ~]# rpm -qa nginx? ? ? ? ? ? ? #<==提前檢查,發(fā)現(xiàn)沒有。
[root@web02 ~]# yum install nginx -y? ? ? #<==開始yum安裝nginx。
[root@web02 ~]# rpm -qa nginx
nginx-1.16.0-1.el7.ngx.x86_64? ? ? ? ? ? ? #<==安裝完畢后檢查,發(fā)現(xiàn)有了。
[root@web02 ~]# systemctl start nginx? ? ? #<==啟動(dòng)Nginx服務(wù)。。
[root@web02 ~]# systemctl enable nginx? ? #<==設(shè)置開機(jī)自啟動(dòng)。
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@web02 ~]# systemctl status nginx? ? #<==查看狀態(tài)。
● nginx.service - nginx - high performance web server
? Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
? Active: active (running) since 六 2019-05-04 11:04:21 CST; 9s ago
[root@web02 ~]# netstat -lntup|grep nginx? #<==檢查端口。
tcp? ? ? ? 0? ? ? 0 0.0.0.0:80? ? 0.0.0.0:*? ? ? LISTEN? ? ? 7854/nginx: master
[root@web02 ~]# wget 127.0.0.1? ? ? ? ? ? #<==測試訪問。
--2019-05-04 11:05:37--? http://127.0.0.1/
正在連接 127.0.0.1:80... 已連接。
已發(fā)出 HTTP 請求,正在等待回應(yīng)... 200 OK
長度:612 [text/html]
正在保存至: “index.html”? ? ? ? ? ? ? #<==出現(xiàn)這個(gè)提示表示,Nginx成功安裝了。
100%[========================================>] 612? ? ? ? --.-K/s 用時(shí) 0s? ? ?
2019-05-04 11:05:37 (39.5 MB/s) - 已保存 “index.html” [612/612])
2) yum安裝PHP
第一個(gè):解決PHP軟件沖突
yum remove php-mysql php php-fpm php-common
第二個(gè):更新yum源信息,用戶安裝php程序
# 準(zhǔn)備yum安裝軟件擴(kuò)展源信息
wget -q https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget -q https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
rpm -Uvh epel-release-latest-7.noarch.rpm
rpm -Uvh webtatic-release.rpm
第三個(gè):直接安裝php服務(wù)相關(guān)軟件
yum install php71w php71w-cli php71w-common php71w-devel php71w-embedded? -y
yum install php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml? -y
yum install php71w-fpm php71w-mysqlnd php71w-opcache? php71w-pecl-memcached? -y
yum install php71w-pecl-redis php71w-pecl-mongodb -y
###############檢查是否安裝成功###############
rpm -qa mod_php71w php71w-cli php71w-common php71w-devel php71w-embedded
rpm -qa php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml
rpm -qa php71w-fpm php71w-mysqlnd php71w-opcache
rpm -qa php71w-pecl-redis php71w-pecl-mongodb php71w-pecl-memcached
啟動(dòng)
php-fpm -t
systemctl start php-fpm
systemctl enable php-fpm
============================================
php71w? ? ? ? --- 主程序軟件
php71w-gd? ? ? --- 和顯示圖形相關(guān)的軟件
php71w-mcrypt? --- 和數(shù)據(jù)傳輸加密相關(guān)
php71w-pdo? ? --- 讓php和數(shù)據(jù)庫建立聯(lián)系
php71w-fpm? ? ---
==========================================
[root@web01 /]# rpm -ql mod_php71w
/etc/httpd/conf.d/php.conf? ? ? ? ? ? ---
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib64/httpd/modules/libphp7-zts.so
/usr/lib64/httpd/modules/libphp7.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session
/var/lib/php/wsdlcache
===========================
[root@web01 /]# rpm -ql php71w-fpm
/etc/logrotate.d/php-fpm
/etc/php-fpm.conf? ? ? ? --- PHP FPM配置
/etc/php-fpm.d
/etc/php-fpm.d/www.conf? --- PHP FPM子目錄配置
/etc/sysconfig/php-fpm
/usr/lib/systemd/system/php-fpm.service
/usr/lib/tmpfiles.d/php-fpm.conf
/usr/sbin/php-fpm? ? ? ? --- PHP FPM啟動(dòng)命令
重要文件和目錄信息
/etc/php-fpm.conf? ? ---php-fpm進(jìn)程的配置文件
? ? ? ? /etc/php-fpm.d? ? ? ---php-fpm進(jìn)程加載配置文件的目錄
/etc/php-fpm.d/www.conf
? ? ? ? user = nginx? ? ? ? --- 利用指定用戶管理php工作進(jìn)程? ? 建議配置和nginx服務(wù)相同的用戶
? ? group = nginx? ? ? --- 利用指定用戶組管理php工作進(jìn)程
? ? ? ? listen = 127.0.0.1:9000? --- 指定php服務(wù)運(yùn)行后, 監(jiān)聽的地址和端口信息
? ? listen.allowed_clients = 127.0.0.1? --- 只允許本地訪問php 9000端口服務(wù)
3) yum安裝mariadb數(shù)據(jù)庫(mysql同源)
yum install mariadb mariadb-server -y
systemctl start mariadb.service
systemctl enable mariadb.service
4)驗(yàn)證MariaDB安裝
[root@web01 ~]# mysql
Welcome to the MariaDB monitor.? Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-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)]>? #<==成功標(biāo)識(shí)。
5)配置測試PHP
a.調(diào)整轉(zhuǎn)發(fā)PHP請求
[root@web01 /etc/nginx/conf.d]# cat blog.conf
server {
? ? ? ? listen? ? ? 80;
? ? ? ? server_name? blog.etiantian.org;
? ? ? ? location / {
? ? root? /usr/share/nginx/html/blog;
? ? ? ? ? ? index? index.php;
location ~ .*\.(php|php5)?$ {
? ? ? ? root? /usr/share/nginx/html/blog;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
? ? ? ? }
? ? }
nginx -t
systemctl reload nginx
netstat -lntup|grep nginx
測試:
echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/test_info.php
php /usr/share/nginx/html/test_info.php
瀏覽器打開。
10.0.0.7/test_info.php
6)配置測試mysql
[root@web01 /usr/share/nginx/html]# mysql
Welcome to the MariaDB monitor.? Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-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)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'oldboy123';
Query OK, 0 rows affected (0.05 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@web01 /usr/share/nginx/html]# cat test_mysql.php
<?php
$link_id=mysqli_connect('localhost','wordpress','oldboy123') or mysql_error();
if($link_id){
echo "mysql successful by oldboy.\n";
}else{
echo mysql_error();
}
?>
[root@web01 /usr/share/nginx/html]# php test_mysql.php
mysql successful by oldboy.
集群調(diào)整:
1)web02 blog數(shù)據(jù)遷移至web01
scp -rp 172.16.1.8:/application/nginx/html/blog /usr/share/nginx/html
2)配置調(diào)整,偽靜態(tài),路徑加blog
[root@web01 /etc/nginx/conf.d]# cat blog.conf
server {
? ? ? ? listen? ? ? 80;
? ? ? ? server_name? blog.etiantian.org;
? ? ? ? location / {
? ? root? /usr/share/nginx/html/blog; ###################
? ? ? ? ? ? index? index.php;
? ? ? ? }
if (-f $request_filename/index.html){
? ? rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
? ? ? ? ? ? rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
? ? rewrite (.*) /index.php;
}
? ? ? ? location ~ .*\.(php|php5)?$ {
? ? ? ? root? /usr/share/nginx/html/blog;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
? ? ? ? }
? ? }
3)共享存儲(chǔ)調(diào)整
yum install rpcbind nfs-utils -y
systemctl start rpcbind
systemctl enable rpcbind