centos7配置nginx+php56+mysql56+netcore20.docx
- 文档编号:25169058
- 上传时间:2023-06-05
- 格式:DOCX
- 页数:11
- 大小:172.99KB
centos7配置nginx+php56+mysql56+netcore20.docx
《centos7配置nginx+php56+mysql56+netcore20.docx》由会员分享,可在线阅读,更多相关《centos7配置nginx+php56+mysql56+netcore20.docx(11页珍藏版)》请在冰豆网上搜索。
centos7配置nginx+php56+mysql56+netcore20
Centos7配置.netcore+nginx+mysql+php
1安装nginx
yuminstallepel-release
yuminstallnginx
启动nginx服务
systemctlrestartnginx
检查服务是否起来
ps–ef|grepnginx
修改配置文件
cd/etc/nginx
cpnginx.confnginx.conf.bak
cpnginx.conf.defaultnginx.conf
浏览器访问,测试是否安装成功
加入守护进程,使其开机自启动
sytemctlenablenginx
配置文件位置:
/etc/nginx/nginx.conf
网站位置:
/usr/share/nginx/htm
2安装.netcore2.0
检查系统安装glibc的版本
cd/usr/lib64
stringslibstdc++.so.6|grepGLIBC
GLIBCXX大于3.4.18
rpm--import
sh-c'echo-e"[packages-microsoft-com-prod]\nname=packages-microsoft-com-prod\nbaseurl=>/etc/yum.repos.d/dotnetdev.repo'
yumupdate
yuminstalllibunwindlibicu
yuminstalldotnet-sdk-2.0.0
dotnet–version命令验证安装是否成功
3安装mysql5.6
检查是否已经安装mysql
yumlistinstalled|grepmysql
给centos源,并选择较新的源
wget
yumlocalinstallmysql-community-release-el7-5.noarch.rpm
yumrepolistall|grepmysql
如果执行yum-config-manager报没有该命令,执行下面语句
【yum-yinstallyum-utils】
yum-config-manager--disablemysql55-community
yum-config-manager--disablemysql57-community
yum-config-manager--disablemysql57-community-dmr
查看可以安装版本
yumrepolistenabled|grepmysql
yuminstallmysql-community-server
启动myql数据库服务
servicemysqldstart
添加守护进程,使其可以开机自启动
systemctlenablemysqld
4安装php5.6
yumlistinstalled|grepphp
yuminstallepel-release
rpm-ivh
查看5.6的可安装包
yumlist--enablerepo=remi--enablerepo=remi-php56|grepphp
yuminstall--enablerepo=remi--enablerepo=remi-php56phpphp-fpmphp-gdphp-ldapphp-odbcphp-pearphp-xmlphp-xmlrpcphp-mbstringphp-snmpphp-soapcurlcurl-develphp-mysql
启动php-fpm
systemctlstartphp-fpm
添加php-fpm为守护进程
systemctlenablephp-fpm
5部署.net项目
做一个测试项目
创建一个项目文件夹
mkdir/var/webtest
dotnetnewmvc
dotnetrestore
dotnetpublish–crelease
启动.netcore项目
[root@localhostpublish]#dotnetwebtest.dll
在nginx配置方向代理
编辑nginx配置文件
server{
listen80;
server_name;
location/{
proxy_passhttp:
//localhost:
5000;
proxy_http_version1.1;
proxy_set_headerUpgrade$http_upgrade;
proxy_set_headerConnectionkeep-alive;
proxy_set_headerHost$host;
proxy_cache_bypass$http_upgrade;
}
}
测试访问
如果出现网关502错误,因为selinux保护机制所导致
yuminstallpolicycoreutils-python
sudocat/var/log/audit/audit.log|grepnginx|grepdenied|audit2allow-Mmynginx
sudosemodule-imynginx.pp
6配置.netcore项目为守护进程
目前存在三个问题
问题1:
ASP.NETCore应用程序运行在shell之中,如果关闭shell则会发现ASP.NETCore应用被关闭,从而导致应用无法访问,这种情况当然是我们不想遇到的,而且生产环境对这种情况是零容忍的。
问题2:
如果ASP.NETCore进程意外终止那么需要人为连进shell进行再次启动,往往这种操作都不够及时。
问题3:
如果服务器宕机或需要重启我们则还是需要连入shell进行启动。
为了解决这个问题,我们需要有一个程序来监听ASP.NETCore应用程序的状况。
在应用程序停止运行的时候立即重新启动。
这边我们用到了Supervisor这个工具,Supervisor使用Python开发的。
安装supervisor
yuminstallpython-setuptools
easy_installsupervisor
配置supervisor
mkdir/etc/supervisor
echo_supervisord_conf>/etc/supervisor/supervisord.conf
修改supervisord.conf文件,将文件尾部的配置
;[include]
;files=relative/directory/*.ini
改成
[include]
files=conf.d/*.conf
ps:
如果服务已启动,修改配置文件可用“supervisorctlreload”命令来使其生效
在/etc/supervisor创建conf.d文件夹
mkdirconf.d
创建项目启动文件
touchwebtest.conf
viwebtest.conf
[program:
webtest]
command=dotnetwebtest.dll;
directory=/var/webtest/bin/release/netcoreapp2.0/publish/;
autorestart=true;
stderr_logfile=/var/log/webtest.err.log;
stdout_logfile=/var/log/webtest.out.log;
environment=ASPNETCORE_ENVIRONMENT=Production;
user=root;
stopsignal=INT
启动supervisord程序
supervisord-c/etc/supervisor/supervisord.conf
检查dotnet项目是否启动
ps–ef|grepsupervisord
ps–ef|grepwebtest
7配置supervisord为守护进程
在/etc/init.d目录下创建supervisord
touch/etc/init.d/supervisord
复制下面内容到文件下
vi/etc/ini.d/supervisord
#!
/bin/sh
#
#/etc/rc.d/init.d/supervisord
#
#Supervisorisaclient/serversystemthat
#allowsitsuserstomonitorandcontrola
#numberofprocessesonUNIX-likeoperating
#systems.
#
#chkconfig:
-6436
#description:
SupervisorServer
#processname:
supervisord
#Sourceinitfunctions
./etc/init.d/functions
RETVAL=0
prog="supervisord"
pidfile="/tmp/supervisord.pid"
lockfile="/var/lock/subsys/supervisord"
start()
{
echo-n$"Starting$prog:
"
daemon--pidfile$pidfilesupervisord-c/etc/supervisor/supervisord.conf
RETVAL=$?
echo
[$RETVAL-eq0]&&touch${lockfile}
}
stop()
{
echo-n$"Shuttingdown$prog:
"
killproc-p${pidfile}/usr/bin/supervisord
RETVAL=$?
echo
if[$RETVAL-eq0];then
rm-f${lockfile}${pidfile}
fi
}
case"$1"in
start)
start
;;
stop)
stop
;;
status)
status$prog
;;
restart)
stop
start
;;
*)
echo"Usage:
$0{start|stop|restart|status}"
;;
esac
设置开机自启动
chkconfigsupervisordon
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- centos7 配置 nginx php56 mysql56 netcore20