用yum源配合源码包安装openresty、mariadb、php7服务
在開(kāi)始部署之前,有必要先簡(jiǎn)單介紹一下!
????OpenResty 是一個(gè)基于 Nginx 與 Lua 的高性能 Web 平臺(tái),其內(nèi)部集成了大量精良的 Lua 庫(kù)、第三方模塊以及大多數(shù)的依賴(lài)項(xiàng)。用于方便地搭建能夠處理超高并發(fā)、擴(kuò)展性極高的動(dòng)態(tài) Web 應(yīng)用、Web 服務(wù)和動(dòng)態(tài)網(wǎng)關(guān)。
????MariaDB服務(wù)器是一個(gè)在世界上最流行的數(shù)據(jù)庫(kù)服務(wù)器。這是由原始開(kāi)發(fā)者的MySQL,并保證保持開(kāi)放源碼。MariaDB是因?yàn)樗俣瓤?#xff0c;可擴(kuò)展性和魯棒性,具有豐富的生態(tài)系統(tǒng),存儲(chǔ)引擎,插件和許多其他工具,使各種各樣的用例非常靈活。
????PHP,我想就不必再絮叨多少了吧。
那我們就開(kāi)始新的學(xué)習(xí)之旅吧!
1、? 前期準(zhǔn)備(最小化安裝的系統(tǒng))
? ? 1.更新系統(tǒng)
????yum makecache && yum -y update
????2.安裝常用基礎(chǔ)軟件
????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
先關(guān)閉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資源庫(kù)
????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 查看安裝包,官方給出的只要安裝server和client就行,其他的根據(jù)?
??????自己的需要來(lái)
????yum?install?MariaDB-server?MariaDB-client????注意:雖然說(shuō)是只需添加系統(tǒng)服務(wù),并啟動(dòng)數(shù)據(jù)庫(kù)就完事了,但我也有幾次還是報(bào)錯(cuò)(個(gè)人建議使
??????????用我以下的步驟)
????[root@localhost ~]# yum search mariadb
????這時(shí)會(huì)出現(xiàn)好多的軟件,你只需用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
????網(wǎng)上也有帖子說(shuō)是要初始化一下,我也試了,無(wú)非就是設(shè)置數(shù)據(jù)庫(kù)的一些配置,像是否刪除測(cè)試數(shù)據(jù)庫(kù),是否禁止遠(yuǎn)程登錄數(shù)據(jù)庫(kù),是否刪除用命用戶什么的,后面可以跟配置項(xiàng)—defaults-file、--datadir、--user等,感覺(jué)沒(méi)多大卵用(廢話有點(diǎn)多,回到原題)
? ? [root@localhost my.cnf.d]# mysql_secure_installation
????3.加入系統(tǒng)服務(wù)
??????[root@localhost ~]# systemctl enable mariadb
????? [root@localhost ~]# systemctl start mariadb.service
????? [root@localhost ~]# systemctl stop mariadb.service
???????提醒:通過(guò)yum裝很多東西都是默認(rèn)的,不像源碼編譯或者自己DOWN安裝包可以各種指定,列
?????一些比較重要的路徑出來(lái)
? ? yum 安裝會(huì)自動(dòng)創(chuàng)建mysql 用戶和用戶組
? ? Yum安裝會(huì)自動(dòng)創(chuàng)建 /etc/my.cnf 以及/etc/my.cnf.d 文件架(并存放 server.conf????client.conf ?tokudb.conf 等文件)
??? 默認(rèn)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開(kāi)頭的,其他的都放到back目錄里【建一個(gè)目錄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 相應(yīng)的 yum源:
????[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
????
????4.直接yum安裝php7:
????[root@localhost ~]# yum install php70w
????5.記得手動(dòng)裝一下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運(yùn)行核心配置文件:
????????2、php-fpm.conf是 php-fpm 進(jìn)程服務(wù)的配置文件:
????????3、配置www.conf(在php-fpm.d目錄下)
???????????www.conf這是 php-fpm 進(jìn)程服務(wù)的擴(kuò)展配置文件:
???????????php服務(wù)的一些文件路徑在/
????
5、? 安裝openresty? (編譯安裝)
????1.依賴(lài)關(guān)系
????openresty依賴(lài)于perl5.6.1+, libreadline, libpcre, libssl,首先安裝依賴(lài)關(guān)系。
????[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.gz(17年4月份)
????https://openresty.org/download/openresty-1.11.2.2.tar.gz? (16年11月)
????使用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
默認(rèn), –prefix=/usr/local/openresty程序會(huì)被安裝到/usr/local/openresty目錄。
我們可以指定各種選項(xiàng),比如
./configure --prefix=/opt/openresty \
??????????? --with-luajit \
? ??????????--without-http_redis2_module \
? ? ? ? ? ? --with-http_iconv_module \
? ? ? ? ? ? --with-http_postgres_module
具體用法參考./configure–help 或者官方文檔
?5.?編譯、安裝
[root@localhostopenresty-1.11.2.3]# gmake && gmake install
6.將nginx添加到系統(tǒng)變量
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.默認(rèn)項(xiàng)目路徑
/opt/openresty/nginx/html
? 8.啟動(dòng)、關(guān)閉、重啟nginx
nginx -c /opt/openresty/nginx/conf/nginx.conf?? //啟動(dòng)并加載配置文件
nginx? -s stop??? //停止
nginx? -s reload??? //重啟
? 9.給nginx做語(yǔ)法檢測(cè)
[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
啟動(dòng)nginx服務(wù)
[root@localhost openresty-1.11.2.3]# nginx
給80端口設(shè)置防火墻規(guī)則:
[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指令實(shí)現(xiàn)nginx多虛擬主機(jī)配置? (nginx文件設(shè)置)
? 1.創(chuàng)建nginx賬戶和組
? ? [root@localhost~]# groupadd ?www-data
? ? [root@localhost~]# useradd ?-g ?www-data ?www-data
????????
2.配置nginx.conf文件:?? 內(nèi)容如下(程序代碼)
user? www-data;
worker_processes? 1;
?
error_log/opt/openresty/nginx/logs/error.log crit;
pid?????? /opt/openresty/nginx/logs/nginx.pid;
?
?
events {
#使用的網(wǎng)絡(luò)I/)模型,Linux系統(tǒng)推薦采用epoll模型,FreeBSD系統(tǒng)推薦采用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 來(lái)代替的,這里支持通配符.
?
###################################################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的虛擬主機(jī)配置(www_test_com.conf, www_test1_com.conf, www_test2_com.conf)文件里,設(shè)置access.log,error.log
????????[root@localhost~]# mkdir -p?/host/nginx/logs/test{"",1,2}
? ? 4.在conf目錄下創(chuàng)建虛擬主機(jī)配置文件目錄vhost,在vhost目錄下分別根據(jù)域名建立相應(yīng)的
????????www_test_com.conf,www_test1_com.conf,www_test2_com.conf3個(gè)文件.
##我把虛擬主機(jī)配置文件放在了這個(gè)目錄下,只不過(guò)需要先手動(dòng)創(chuàng)建目錄和.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; ? ###換成自個(gè)的IP地址(我是基于域名的虛擬主機(jī),所以是相同IP不同端口。
???????client_max_body_size 100M;
???????server_name? www.test.com; ? ? ? ? ?###換成自個(gè)要用的域名
???????charset utf-8; ? ? ? ? ? ? ? ? ? ? ?###字符集:utf-8
???????root?? /var/www/test/; ? ? ? ? ? ? ?###站點(diǎn)路徑——存放網(wǎng)頁(yè)的目錄
???????index? ?index.php index.html index.htm;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ###追加index.php讓nginx服務(wù)器默認(rèn)支持index.php為首頁(yè):
???????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/;?????? #你的站點(diǎn)路徑
???????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/; ? ? ? ? ###自個(gè)的站點(diǎn)路徑——網(wǎng)頁(yè)存放路徑
???????????charset???? on;
???????}
???????#將客戶端請(qǐng)求裝交給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請(qǐng)求被傳送到后端的php-fpm模塊,默認(rèn)情況下php配置塊是被注釋的,此時(shí)去
??????????????掉注釋并修改,這里面很多都是默認(rèn)的,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;
??????????????? }
?????????????????? #網(wǎng)站的圖片較多,更改較少,將它們?cè)跒g覽器本地緩存15天
???????location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
??????????????? expires????? 15d;
??????????????? }
?????????????????? #網(wǎng)站會(huì)加載很多JS、CSS,將它們?cè)跒g覽器本地緩存1天
???????location ~ .*\.(js|css)?$ {
??????????????? expires????? 1d;
??????????????? }
???????location /(WEB-INF)/ {
??????????????? deny all;
??????????????? }
}
?
注意:www_test1_com.conf配置代碼和www_test2_com.conf配置代碼跟www_test_com.conf(除了
和網(wǎng)頁(yè)存放路徑不一樣外)一樣。
? ? 5.創(chuàng)建/var/www/test,/var/www/test1,/var/www/test2這三個(gè)目錄,并在這三個(gè)目錄下分別創(chuàng)建?index.php,還要給它們屬主和屬組權(quán)限。
? ? [root@www ~]# ls /var/www/test
?test/? test1/ test2/
?[root@www ~]# vi/var/www/test/index.php
?<?php
?phpinfo();
??>
給網(wǎng)頁(yè)文檔目錄/var/www/test{“”,1,2}添加屬主和屬組權(quán)限。
[root@localhosttest]# chown -R www-data:www-data /var/www/test{"",1,2}
其他兩個(gè)測(cè)試文件(注意目錄)一樣。
7、php文件配置:
? 1.php-fpm.conf配置文件
[root@www~]# vi /etc/php-fpm.conf
在[global]配置項(xiàng)下,把pid = /var/run/php-fpm/php-fpm.pid前的分號(hào)注釋去掉,還有就是include=/etc/php-fpm.d/*.conf這一項(xiàng),設(shè)置配置文件路徑
2.php-fpm.d/www.conf配置文件
[root@www~]# vi /etc/php-fpm.d/www.conf
在[www]配置項(xiàng)下有user = ,group= 兩配置項(xiàng),都改了
user= www-data
group= www-data
?
8、檢查nginx配置是否有錯(cuò)
nginx?????? -t
啟動(dòng)Nginx服務(wù)
[root@localhost~]#?Nginx????##nginx啟動(dòng)命令
啟動(dòng)PHP服務(wù)
[root@localhost~]#?php-fpm????##PHP啟動(dòng)命令
啟動(dòng)mariadb服務(wù)
[root@localhost~]# systemctl enable mariadb
9、配置防火墻規(guī)則:
??? [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系統(tǒng)中C:\WINDOWS\system32\drivers\etc下的hosts文件中做域名映射
11、可以查看訪問(wèn)了
轉(zhuǎn)載于:https://blog.51cto.com/12092502/1929825
總結(jié)
以上是生活随笔為你收集整理的用yum源配合源码包安装openresty、mariadb、php7服务的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 数据挖掘算法学习(四)PCA算法
- 下一篇: redis安装全过程