Day48
课堂笔记
2019年5月8日
LNMP全yum部署安装和集群架构迁移
1)yum安装NGINX
[root@web02 ~]# cat /etc/yum.repos.d/nginx.repo #<==配置Nginx官方yum源。
[nginx]
name=Nginx repo by oldboy
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
说明:如果是用epel源安装需要提前配置epel源,本书安装系统时已经配置过了epel源了。
[root@web02 ~]# rpm -qa nginx #<==提前检查,发现没有。
[root@web02 ~]# yum install nginx -y #<==开始yum安装nginx。
[root@web02 ~]# rpm -qa nginx
nginx-1.16.0-1.el7.ngx.x86_64 #<==安装完毕后检查,发现有了。
[root@web02 ~]# systemctl start nginx #<==启动Nginx服务。。
[root@web02 ~]# systemctl enable nginx #<==设置开机自启动。
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@web02 ~]# systemctl status nginx #<==查看状态。
● 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...已连接。
已发出HTTP请求,正在等待回应... 200 OK
长度:612 [text/html]
正在保存至: “index.html” #<==出现这个提示表示,Nginx成功安装了。
100%[========================================>] 612 --.-K/s用时 0s
2019-05-04 11:05:37 (39.5 MB/s) -已保存 “index.html” [612/612])
2) yum安装PHP
第一个:解决PHP软件冲突
yum remove php-mysql php php-fpm php-common
第二个:更新yum源信息,用户安装php程序
#准备yum安装软件扩展源信息
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
第三个:直接安装php服务相关软件
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
启动
php-fpm -t
systemctl start php-fpm
systemctl enable php-fpm
============================================
php71w ---主程序软件
php71w-gd ---和显示图形相关的软件
php71w-mcrypt ---和数据传输加密相关
php71w-pdo ---让php和数据库建立联系
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启动命令
重要文件和目录信息
/etc/php-fpm.conf ---php-fpm进程的配置文件
/etc/php-fpm.d ---php-fpm进程加载配置文件的目录
/etc/php-fpm.d/www.conf
user = nginx ---利用指定用户管理php工作进程 建议配置和nginx服务相同的用户
group = nginx ---利用指定用户组管理php工作进程
listen = 127.0.0.1:9000 ---指定php服务运行后, 监听的地址和端口信息
listen.allowed_clients = 127.0.0.1 ---只允许本地访问php 9000端口服务
3) yum安装mariadb数据库(mysql同源)
yum install mariadb mariadb-server -y
systemctl start mariadb.service
systemctl enable mariadb.service
4)验证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)]> #<==成功标识。
5)配置测试PHP
a.调整转发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.
集群调整:
1)web02 blog数据迁移至web01
scp -rp 172.16.1.8:/application/nginx/html/blog /usr/share/nginx/html
2)配置调整,伪静态,路径加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)共享存储调整
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
别忘了,开机自动挂载。
WEB01:lnmp单机