2019-05-8筆記.2

Day48

課堂筆記

2019年5月8日

LNMP全yum部署安裝和集群架構(gòu)遷移

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 ????????????#<==測(cè)試訪問。

--2019-05-04 11:05:37-- ?http://127.0.0.1/

正在連接127.0.0.1:80...已連接。

已發(fā)出HTTP請(qǐng)求,正在等待回應(yīng)... 200 OK

長(zhǎng)度: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)配置測(cè)試PHP

a.調(diào)整轉(zhuǎn)發(fā)PHP請(qǐng)求

[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

?

?

測(cè)試:

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)配置測(cè)試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

?

mount -t nfs 172.16.1.31:/data/blog_nfs ?/usr/share/nginx/html/blog/wp-content/uploads

ls /usr/share/nginx/html/blog/wp-content/uploads

別忘了,開機(jī)自動(dòng)掛載。

?

?

WEB01:lnmp單機(jī)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 時(shí)光不待,草木有序,春風(fēng)一夜間吻醒千樹萬樹的李花,那漫山遍野的皓白,如同雪落人間,裝帖這座南方的小鎮(zhèn)。李花...
    伊朵雪閱讀 663評(píng)論 2 13
  • 一個(gè)男人想要事業(yè)成功,必然有該做和不該做的事情之分,那其中就應(yīng)該悟透六件事。 01 戒掉貪婪 一個(gè)男人如果貪婪,那...
    軍旅之晴閱讀 339評(píng)論 0 0
  • 調(diào)優(yōu)參考:https://developer.aliyun.com/article/690392 高級(jí)程序員必不可...
    AI賀賀閱讀 4,423評(píng)論 0 31
  • 在你面前出現(xiàn)了三條路,一條是前路,就是往前走,前面可能有我們預(yù)知不到的美好的糟糕的事情;一條是后路,就是往后退,退...
    我與夏天與你閱讀 186評(píng)論 0 1
  • 昨晚打開喜馬拉雅,系統(tǒng)推送信息說,有3300多人聽過我的聲音,打開頓時(shí)把我嚇了一跳,自己沒啥錄聲音居然有這么多人聽...
    舒文姑娘閱讀 1,457評(píng)論 4 13

友情鏈接更多精彩內(nèi)容