用yum源配合源码包安装openresty、mariadb、php7服务

2024-06-06 00:57:11

在开始部署之前,有必要先简单介绍一下!

OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

MariaDB服务器是一个在世界上最流行的数据库服务器。这是由原始开发者的MySQL,并保证保持开放源码。MariaDB是因为它速度快,可扩展性和鲁棒性,具有丰富的生态系统,存储引擎,插件和许多其他工具,使各种各样的用例非常灵活。

PHP,我想就不必再絮叨多少了吧。

那我们就开始新的学习之旅吧!

1、 前期准备(最小化安装的系统)

1.更新系统

yum makecache && yum -y update

2.安装常用基础软件

yum -y install bash-completion vim net-tools bind-utilswget screen

最后别忘了重启

2、 更新yum源(阿里云源:mirrors.aliyun.com

[root@localhost~]# mv /etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup

[root@localhost~]# ls /etc/yum.repos.d/

CentOS-Base.repo.backup  CentOS-fasttrack.repo  CentOS-Vault.repo

CentOS-CR.repo          CentOS-Media.repo

CentOS-Debuginfo.repo   CentOS-Sources.repo

先关闭fastestmirror

[root@localhostyum.repos.d]# vi /etc/yum/pluginconf.d/fastestmirror.conf  (enabled=0)

[root@localhost yum.repos.d]# wget -O/etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@localhost yum.repos.d]# yumclean all

[root@localhost yum.repos.d]# yum makecache

3、 安装mariadb

1.添加mariadb yum资源库

vi /etc/yum.repos.d/MariaDB.repo

[mariadb]

name= MariaDB

baseurl= http://yum.mariadb.org/10.1/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

2.可以使用yum search MariaDB 查看安装包,官方给出的只要安装serverclient就行,其他的根据

自己的需要来

    yum install MariaDB-server MariaDB-client

注意:虽然说是只需添加系统服务,并启动数据库就完事了,但我也有几次还是报错(个人建议使

用我以下的步骤)

[root@localhost ~]# yum search mariadb

这时会出现好多的软件,你只需用yum安装即可

[root@localhost ~]# yum -y install MariaDB-backupMariaDB-client MariaDB-common MariaDB-compat MariaDB-connect-engineMariaDB-cracklib-password-check MariaDB-devel MariaDB-gssapi-clientMariaDB-gssapi-server MariaDB-oqgraph-engine MariaDB-server  MariaDB-shared MariaDB-test mariadb-benchmariadb-devel mariadb-embedded mariadb-embedded-devel mariadb-libs mariadb

网上也有帖子说是要初始化一下,我也试了,无非就是设置数据库的一些配置,像是否删除测试数据库,是否禁止远程登录数据库,是否删除用命用户什么的,后面可以跟配置项—defaults-file--datadir--user等,感觉没多大卵用(废话有点多,回到原题)

[root@localhost my.cnf.d]# mysql_secure_installation

3.加入系统服务

[root@localhost ~]# systemctl enable mariadb

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# systemctl stop mariadb.service

提醒:通过yum装很多东西都是默认的,不像源码编译或者自己DOWN安装包可以各种指定,列

一些比较重要的路径出来

yum 安装会自动创建mysql 用户和用户组

Yum安装会自动创建 /etc/my.cnf 以及/etc/my.cnf.d 文件架(并存放 server.conf    client.conf  tokudb.conf 等文件)

默认rpm路径

basedir =/usr/bin

datadir=/var/lib/mysql

.h=/usr/include/mysql

plung=/usr/lib64/mysql

share=/usr/share/mysql(confcharset etc)

4、 安装PHP7

1.先看下yum

[root@localhost ~]# ls /etc/yum.repos.d/

back webtatic-archive.repo webtatic.repo webtatic-testing.repo

[root@localhost ~]# ls /etc/yum.repos.d/back/

#/etc/yum.repo.d/目录下,只留webstaic头的,其他的都放到back目录里【建一个目录back

CentOS7-Base-163.repo     CentOS-CR.repo         CentOS-Media.repo    epel.repo

CentOS-Base.repo.backup   CentOS-Debuginfo.repo  CentOS-Sources.repo  epel-testing.repo   CentOS-Base.repo.backup1  CentOS-fasttrack.repo  CentOS-Vault.repo

2.删除之前的PHP版本

[root@localhost ~]#yum remove php* php-common

3.rpm 安装Php7 相应的 yum源:

[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

4.直接yum安装php7:

[root@localhost ~]# yum install php70w

5.记得手动装一下php-fpm

[root@localhost ~]#yum –y  install php-fpm

[root@localhost ~]# ls /etc/php

php.d/    php-fpm.conf  php-fpm.d/    php.ini      php-zts.d/

6.看下PHP的版本:

[root@localhost~]# php -v

PHP 7.0.18 (cli) (built: Apr 15 2017 07:09:11) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

注意:

1、php.ini是php运行核心配置文件:

2、php-fpm.conf是 php-fpm 进程服务的配置文件:

3、配置www.conf(在php-fpm.d目录下)

www.conf这是 php-fpm 进程服务的扩展配置文件:

php服务的一些文件路径在/

5、 安装openresty  (编译安装)

1.依赖关系

openresty依赖于perl5.6.1+, libreadline, libpcre, libssl,首先安装依赖关系。

[root@localhost ~]# yum  –y  install   perl 5.6.1+  libreadline libpcre  libssl

[root@localhost~]# yum  -y  install readline-devel  pcre-devel  openssl-devel  gcc

2下载源码

https://openresty.org/download/openresty-1.11.2.3.tar.gz174月份)

https://openresty.org/download/openresty-1.11.2.2.tar.gz  1611月)

使用wget下载(可以登录http://openresty.org查看最新版本)

[root@localhost~]# wget https://openresty.org/download/openresty-1.11.2.3.tar.gz

3.解压下载好的压缩包

[root@localhost ~]# tar zxf openresty-1.11.2.3.tar.gz

4.配置./configure

[root@localhost openresty-1.11.2.3]# cd openresty-1.11.2.3/

[root@localhost openresty-1.11.2.3]# ./configure  --prefix=/opt/openresty  --with-luajit

默认, prefix=/usr/local/openresty程序会被安装到/usr/local/openresty目录。

我们可以指定各种选项,比如

./configure --prefix=/opt/openresty \

--with-luajit \

--without-http_redis2_module \

--with-http_iconv_module \

--with-http_postgres_module

具体用法参考./configurehelp 或者官方文档

5. 编译、安装

[root@localhostopenresty-1.11.2.3]# gmake && gmake install

6.将nginx添加到系统变量

PATH=/opt/openresty/nginx/sbin:$PATH

export PATH         或者

[root@localhost openresty-1.11.2.3]# echo

"export PATH=$PATH:/opt/openresty/nginx/sbin/" >>/etc/profile && source /etc/profile

7.默认项目路径

/opt/openresty/nginx/html

8.启动、关闭、重启nginx

nginx -c /opt/openresty/nginx/conf/nginx.conf   //启动并加载配置文件

nginx  -s stop    //停止

nginx  -s reload    //重启

9.nginx做语法检测

[root@localhost openresty-1.11.2.3]# nginx -t

nginx: the configuration file/opt/openresty/nginx/conf/nginx.conf syntax is ok

nginx: configuration file/opt/openresty/nginx/conf/nginx.conf test is successful

启动nginx服务

[root@localhost openresty-1.11.2.3]# nginx

80端口设置防火墙规则:

[root@localhost openresty-1.11.2.3]# cd

[root@localhost ~]# firewall-cmd--add-port=80/tcp --permanent

success

[root@localhost ~]# firewall-cmd –reload

Success

6、用include指令实现nginx多虚拟主机配置  (nginx文件设置)

1.创建nginx账户和组

[root@localhost~]# groupadd  www-data

[root@localhost~]# useradd  -g  www-data  www-data

2.配置nginx.conf文件:   内容如下(程序代码)

user  www-data;

worker_processes  1;

error_log/opt/openresty/nginx/logs/error.log crit;

pid       /opt/openresty/nginx/logs/nginx.pid;

events {

#使用的网络I/)模型,Linux系统推荐采用epoll模型,FreeBSD系统推荐采用kqueue模型

use epoll;

worker_connections  1024;

}

http {

include     /opt/openresty/nginx/conf/mime.types;

default_type  application/octet-stream;

charset utf-8;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

keepalive_timeout 60;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 128k;

fastcgi_buffers 4 128k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

client_body_temp_path/opt/openresty/nginx/client_body_temp;

proxy_temp_path/opt/openresty/nginx/proxy_temp;

fastcgi_temp_path/opt/openresty/nginx/fastcgi_temp;

gzip on;

gzip_min_length  1k;

gzip_buffers     4 16k;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types       text/plain application/x-javascripttext/css application/xml;

gzip_vary on;

client_header_timeout  10;

client_body_timeout    10;

send_timeout          10;

sendfile                on;

tcp_nopush              on;

tcp_nodelay            on;

#virtual host

include      /host/nginx/conf/vhost/www_test_com.conf;

include      /host/nginx/conf/vhost/www_test1_com.conf;

include      /host/nginx/conf/vhost/www_test2_com.conf;

#也可以使用 include /host/nginx/conf/vhost/*.conf 来代替的,这里支持通配符.

###################################################partingline########################################################

# another virtual host using mix of IP-,name-, and port-based configuration

#

#server {

#   listen       8000;

#   listen       somename:8080;

#   server_name  somename  alias another.alias;

#   location / {

#       root   html;

#       index  index.html index.htm;

#   }

#}

# HTTPS server

#

#server {

#   listen       443 ssl;

#   server_name  localhost;

#   ssl_certificate      cert.pem;

#   ssl_certificate_key  cert.key;

#   ssl_session_cache   shared:SSL:1m;

#   ssl_session_timeout  5m;

#   ssl_ciphers  HIGH:!aNULL:!MD5;

#   ssl_prefer_server_ciphers  on;

#   location / {

#       root   html;

#       index  index.html index.htm;

#   }

#}

}

3.Nginx的虚拟主机配置(www_test_com.conf, www_test1_com.conf, www_test2_com.conf)文件里,设置access.logerror.log

[root@localhost~]# mkdir -p /host/nginx/logs/test{"",1,2}

4.conf目录下创建虚拟主机配置文件目录vhost,vhost目录下分别根据域名建立相应的

www_test_com.conf,www_test1_com.conf,www_test2_com.conf3个文件.

##我把虚拟主机配置文件放在了这个目录下,只不过需要先手动创建目录和.conf文件

[root@www test]#ls /host/nginx/conf/vhost/

www_test1_com.conf  www_test2_com.conf  www_test_com.conf

www_test_com.conf配置代码:

vi /host/nginx/conf/vhost/www_test_com.conf

server {

listen    80;   ###换成自个的IP地址(我是基于域名的虚拟主机,所以是相同IP不同端口。

client_max_body_size 100M;

server_name  www.test.com;          ###换成自个要用的域名

charset utf-8;                      ###字符集:utf-8

root   /var/www/test/;              ###站点路径——存放网页的目录

index   index.php index.html index.htm                                                                                ###追加index.php让nginx服务器默认支持index.php为首页:

autoindex       on;

access_log   /host/nginx/logs/test/test.access.log;

error_log   /host/nginx/logs/test/test.error.log;

if (-d $request_filename) {

rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;

}

error_page  404              /404.html;

location = /40x.html {

root  /var/www/test/;       #你的站点路径

charset    on;

}

# redirect server error pages to the static page /50x.html

#

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   /var/www/test/;         ###自个的站点路径——网页存放路径

charset     on;

}

#将客户端请求装交给fastcgi,老大要求用fpm模块(修改)

location ~ \.php$ {

root          /var/www/test/;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include        fastcgi_params;

}

注意:配置.php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去

掉注释并修改,这里面很多都是默认的,root是配置php程序放置的根目录,主要修改

的就是fastcgi_param中的/scripts$document_root

例如:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

location~ .*\.(php|php5|php4|shtml|xhtml|phtml)?$ {

fastcgi_pass   127.0.0.1:9000;

include /opt/openresty/nginx/conf/fastcgi_params;

}

#网站的图片较多,更改较少,将它们在浏览器本地缓存15

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {

expires      15d;

}

#网站会加载很多JSCSS,将它们在浏览器本地缓存1

location ~ .*\.(js|css)?$ {

expires      1d;

}

location /(WEB-INF)/ {

deny all;

}

}

注意:www_test1_com.conf配置代码和www_test2_com.conf配置代码跟www_test_com.conf(除了

和网页存放路径不一样外)一样。

5.创建/var/www/test,/var/www/test1,/var/www/test2这三个目录,并在这三个目录下分别创建 index.php,还要给它们属主和属组权限。

[root@www ~]# ls /var/www/test

test/  test1/ test2/

[root@www ~]# vi/var/www/test/index.php

<?php

phpinfo();

?>

给网页文档目录/var/www/test{“”,1,2}添加属主和属组权限。

[root@localhosttest]# chown -R www-data:www-data /var/www/test{"",1,2}

其他两个测试文件(注意目录)一样。

7、php文件配置:

1.php-fpm.conf配置文件

[root@www~]# vi /etc/php-fpm.conf

在[global]配置项下,把pid = /var/run/php-fpm/php-fpm.pid前的分号注释去掉,还有就是include=/etc/php-fpm.d/*.conf这一项,设置配置文件路径

2.php-fpm.d/www.conf配置文件

[root@www~]# vi /etc/php-fpm.d/www.conf

在[www]配置项下有user = ,group= 两配置项,都改了

user= www-data

group= www-data

8、检查nginx配置是否有错

nginx       -t

启动Nginx服务

[root@localhost~]#Nginx##nginx启动命令

启动PHP服务

[root@localhost~]#php-fpm    ##PHP启动命令

启动mariadb服务

[root@localhost~]# systemctl enable mariadb

9、配置防火墙规则:

[root@www~]# firewall-cmd --add-port=80/tcp –permanent    #nginx:80

[root@www~]# firewall-cmd --add-port=3306/tcp –permanent  #mariadb:3306

[root@www~]# firewall-cmd --add-port=3306/tcp –permanent #PHP:9000

[root@www~]# firewall-cmd –reload

10、在windows系统中C:\WINDOWS\system32\drivers\etc下的hosts文件中做域名映射

wKiom1kny67A3mihAAAJCEqXDWA054.png-wh_50

11、可以查看访问了

wKiom1knzGCDjbPaAACsnK5u96g185.png-wh_50

转载于:https://blog.51cto.com/12092502/1929825

用yum源配合源码包安装openresty、mariadb、php7服务相关推荐

  1. 编译安装openresty+mariadb+php7

    2019独角兽企业重金招聘Python工程师标准>>> 1.准备 1.更新系统 yum makecache && yum -y update 2.安装常用基础软件 y ...

  2. Linux系统中软件的“四”种安装原理详解:源码包安装、RPM二进制安装、YUM在线安装、脚本安装包...

    一.Linux软件包分类 1.1 源码包 优点: 开源,如果有足够的能力,可以修改源代码: 可以自由选择所需的功能: 软件是编译安装,所以更加适合自己的系统,更加稳定.效率更高: 卸载方便: 缺点: ...

  3. yum更换本地源、yum下载和源码包安装

    7.6 yum更换国内源 恢复系统默认yum源配置: [root@gaohanwei Packages]# cd /etc/yum.repos.d [root@gaohanwei yum.repos. ...

  4. 7.6 yum更换国内源 7.7 yum下载rpm包 7.8/7.9 源码包安装

    2019独角兽企业重金招聘Python工程师标准>>> 7.6.yum更换国内源 自定义yum源: [root@bogon ~]# cd /etc/yum.repos.d [root ...

  5. yum更换国内源、yum下载rpm包、源码包安装

    2019独角兽企业重金招聘Python工程师标准>>> 更换yum仓库源 cd /etc/yum.repos.d/ rm -f dvd.repo wget http://mirror ...

  6. Linux学习笔记(二十二)yum更换国内源、yum下载rpm包、源码包安装

    一.yum更换国内源 首先 cd /etc/yum.repos.d/ rm -f dvd.repo 删除之前添加的本地仓库,将原来的仓库恢复回来 cp /etc/yum.repos.d.bak/* / ...

  7. yum下载rpm包、源码包安装

    一: yum如何下载rpm包到本地(只下载,不安装) 安装yum-downloadonly yum install -y yum-plugin-downloadonly.noarch 下载包到指定目录 ...

  8. linux软件安装——rpm、yum、源码包安装

    一.软件包分类 源码包(原始的c语言文件,开源) 二进制包(系统默认包,将源码编译为机器语言,省略了编译过程,安装较快,但是用户看不到源码,安装有依赖性,centos中都是rpm包) 二.rpm命令管 ...

  9. 更换yum源,安装扩展源,yum下载rpm包,源码包安装软件

    2019独角兽企业重金招聘Python工程师标准>>> 更换国内yum源 我们的Linux中默认的yum源是国外的,有的时候网络不好,而我么需要下载的包过大的时候更换成国内的yum源 ...

最新文章

  1. 彻底剖析室内、室外激光SLAM关键算法原理、代码和实战(cartographer+LOAM+LIO-SAM)
  2. 判断接收的数据中是否有中文
  3. 学python要多少钱-学python去培训班要多少钱?
  4. 贪吃蛇一直显示正在连接服务器,贪吃蛇大作战进不去怎么办 解决方法
  5. git reset 回退以前某个版本_远程仓库版本回退方法--Git(二)
  6. 从零开始搭建口袋妖怪管理系统(3)-实现一个简单的SPA管理系统
  7. lsqnonneg函数_matlab中线性最小二乘问题求解
  8. php分割文本读入数组,PHP fgets按行读取字符串和explode分割字符串为数组
  9. 为什么要学习Linux操作系统?
  10. 构建大型 Mobx 应用的几个建议
  11. 介绍 Android 的 Camera 框架
  12. linux中vsftpd登陆慢卡问题解决方法
  13. 10.22~10.28一周经典题目整理(meeting,BZOJ4377,POJ3659)
  14. 智能配电台区监控系统方案
  15. 简单实现Android图片三级缓存机制
  16. Photoneo为IKEA提供家具零件包装自动化解决方案
  17. Python:利用多种方式解微分方程(以二阶微分系统零状态响应为例)
  18. 基于51单片机的心形流水灯
  19. 天嵌开发版 imx6 移植qt
  20. 山大郝老师 计算机学院,相约山大 一起扬帆远航

热门文章

  1. (动态,静态)(解释,编译)(强类型,弱类型)
  2. GreenPlum的并行查询优化策略
  3. js页面排序-----基础篇
  4. java scanner类int_Java之 Scanner类
  5. Kafka消息的可靠性
  6. 各IO 模型对比与总结
  7. MyBatis 核心对象
  8. Spring MVC 源码-初始化阶段
  9. 每次请求都要建立连接吗?
  10. EasyExcel实现读操作