时间:2018年05月17日 | 作者 : aaronyang | 分类 : .NET CORE | 浏览: 2927次 | 评论 0 人
centos7 安装完以后,我是最小安装,安装了GNOME,打开了网络
====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======请不要转载谢谢了。=========
ifconfig -a
查看ip
安装
curl -o nginx.rpm http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx.rpm
yum install nginx #安装
这里发现是1.14 版本的nginx
systemctl start nginx #启动nginx
systemctl enable nginx #设置nginx的开机启动
浏览器:访问 192.168.242.128
此时客户机 虚拟机可以互ping,但是无法访问站点。
192.168.242.128
应该是防火墙了。
打开终端
firewall-cmd --zone=public --add-port=80/tcp --permanent #(开放80端口)
systemctl restart firewalld #(重启防火墙以使配置即时生效)
拓展知识:
Centos 7 firewall 命令:
查看已经开放的端口:
firewall-cmd --list-ports
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload #重启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
如要开放80,22,8080 端口,输入以下命令即可
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
然后保存:
/etc/rc.d/init.d/iptables save
查看打开的端口:
/etc/init.d/iptables status
关闭防火墙
1) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop
查看防火墙状态: service iptables status
下面说下CentOS7和6的默认防火墙的区别
CentOS 7默认使用的是firewall作为防火墙,使用iptables必须重新设置一下
1、直接关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
2、设置 iptables service
yum -y install iptables-services
如果要修改防火墙配置,如增加防火墙端口3306
vi /etc/sysconfig/iptables
增加规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
保存退出后
systemctl restart iptables.service #重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
最后重启系统使设置生效即可。
systemctl start iptables.service #打开防火墙
systemctl stop iptables.service #关闭防火墙
虚拟机外面电脑 客户端测试访问:
====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======请不要转载谢谢了。=========
接下来安装net core环境:
https://www.microsoft.com/net/learn/get-started/linux/centos
终端输入:
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update
sudo yum install libunwind libicu
sudo yum install dotnet-sdk-2.1.200
创建APP测试
dotnet new console -o myApp
进入文件夹
cd myApp
然后编译和运行
dotnet restore
dotnet run #运行应用程序
hello world输出 , .net core的环境已经装好了。
"#"是注释
shirf + insert 粘贴 (不能ctrl + c v 有点不习惯)
ctrl + insert 复制
====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======请不要转载谢谢了。=========
接下来,下载WINSCP
点击登录,可以看到centos的目录了。
打开VS2017新建core项目
这里大家还是选择2.0的吧,
新建完,按下F5
接下来,发布一下,
发布完成后,P1文件夹内容如下
右键在home文件夹下,创建一个文件夹
双击进入文件夹
拖动桌面的文件到 此文件夹去
然后点击终端,输入命令
发现报错,因为 linux下的asp.net core2.1-rc1-final没这个 兼容的framework,看来我只能降级,先用2.0版本了。
同1个我们建立2.0的发布一下
删掉文件夹重新建立aynetcore文件夹,然后建立core的web项目AYTestCore2,发布后,拖动上去
执行 dotnet AYTestCore2.dll 看到这个说明正确了。
此时物理机无法访问5000端口,同上解决80端口的问题,修改防火墙
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --permanent --zone=public --add-port=5000/tcp
sudo firewall-cmd --reload
发现还是不能访问,如果出现端口占用,先查询出来,kill掉
ps -ef|grep dotnet
kill -9 88081
到此为止,你已经会基本调整了,我们接下来,在2.0的AYTestCore2这个项目,修改Program.cs的部分代码
public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args).UseKestrel().UseUrls("http://*:6000") .UseStartup<Startup>() .Build();
然后在防火墙设置 6000可以访问,重启防火墙。
然后发布,和拷贝项目
此时发布后,我在虚拟机中的 部署站点的机器不给访问,但是外部的浏览器已经可以访问了。
设置nginx转发, 80端口跳转到6000
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { proxy_pass http://...:6000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }
访问502错误
将nginx添加至SELinux的白名单,否则会报502错误。
下面4步执行一下
nginx -s reload #使其即时生效
yum install policycoreutils-python #(选y)
cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
semodule -i mynginx.pp
接下来启动 dotnet 那个 core项目
物理机可以打开浏览器,通过80访问6000的端口的网页了。虚拟机的浏览器也可以访问了。
接下来,需要配置守护服务,不能让 网站在终端端口关闭,就自动停止了。
需要安装
yum install python-setuptools
easy_install supervisor #安装Supervisor
mkdir /etc/supervisor
使用echo_supervisord_conf 查看默认的配置文件
; Sample supervisor config file. ; ; For more information on the config file, please see: ; http://supervisord.org/configuration.html ; ; Notes: ; - Shell expansion ("~" or "$HOME") is not supported. Environment ; variables can be expanded using this syntax: "%(ENV_HOME)s". ; - Quotes around values are not supported, except in the case of ; the environment= options as shown below. ; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". ; - Command will be truncated if it looks like a config file comment, e.g. ; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ". [unix_http_server] file=/tmp/supervisor.sock ; the path to the socket file ;chmod=0700 ; socket file mode (default 0700) ;chown=nobody:nogroup ; socket file uid:gid owner ;username=user ; default is no username (open server) ;password=123 ; default is no password (open server) ;[inet_http_server] ; inet (TCP) server disabled by default ;port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface ;username=user ; default is no username (open server) ;password=123 ; default is no password (open server) [supervisord] logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 loglevel=info ; log level; default info; others: debug,warn,trace pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid nodaemon=false ; start in foreground if true; default false minfds=1024 ; min. avail startup file descriptors; default 1024 minprocs=200 ; min. avail process descriptors;default 200 ;umask=022 ; process file creation umask; default 022 ;user=chrism ; default is current user, required if root ;identifier=supervisor ; supervisord identifier, default is 'supervisor' ;directory=/tmp ; default is not to cd during start ;nocleanup=true ; don't clean up tempfiles at start; default false ;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP ;environment=KEY="value" ; key value pairs to add to environment ;strip_ansi=false ; strip ansi escape codes in logs; def. false ; The rpcinterface:supervisor section must remain in the config file for ; RPC (supervisorctl/web interface) to work. Additional interfaces may be ; added by defining them in separate [rpcinterface:x] sections. [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface ; The supervisorctl section configures how supervisorctl will connect to ; supervisord. configure it match the settings in either the unix_http_server ; or inet_http_server section. [supervisorctl] serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket ;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket ;username=chris ; should be same as in [*_http_server] if set ;password=123 ; should be same as in [*_http_server] if set ;prompt=mysupervisor ; cmd line prompt (default "supervisor") ;history_file=~/.sc_history ; use readline history if available ; The sample program section below shows all possible program subsection values. ; Create one or more 'real' program: sections to be able to control them under ; supervisor. ;[program:theprogramname] ;command=/bin/cat ; the program (relative uses PATH, can take args) ;process_name=%(program_name)s ; process_name expr (default %(program_name)s) ;numprocs=1 ; number of processes copies to start (def 1) ;directory=/tmp ; directory to cwd to before exec (def no cwd) ;umask=022 ; umask for process (default None) ;priority=999 ; the relative start priority (default 999) ;autostart=true ; start at supervisord start (default: true) ;startsecs=1 ; # of secs prog must stay up to be running (def. 1) ;startretries=3 ; max # of serial start failures when starting (default 3) ;autorestart=unexpected ; when to restart if exited after running (def: unexpected) ;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) ;stopsignal=QUIT ; signal used to kill process (default TERM) ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) ;stopasgroup=false ; send stop signal to the UNIX process group (default false) ;killasgroup=false ; SIGKILL the UNIX process group (def false) ;user=chrism ; setuid to this UNIX account to run the program ;redirect_stderr=true ; redirect proc stderr to stdout (default false) ;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO ;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) ;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) ;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) ;stdout_events_enabled=false ; emit events on stdout writes (default false) ;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO ;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) ;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) ;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) ;stderr_events_enabled=false ; emit events on stderr writes (default false) ;environment=A="1",B="2" ; process environment additions (def no adds) ;serverurl=AUTO ; override serverurl computation (childutils) ; The sample eventlistener section below shows all possible eventlistener ; subsection values. Create one or more 'real' eventlistener: sections to be ; able to handle event notifications sent by supervisord. ;[eventlistener:theeventlistenername] ;command=/bin/eventlistener ; the program (relative uses PATH, can take args) ;process_name=%(program_name)s ; process_name expr (default %(program_name)s) ;numprocs=1 ; number of processes copies to start (def 1) ;events=EVENT ; event notif. types to subscribe to (req'd) ;buffer_size=10 ; event buffer queue size (default 10) ;directory=/tmp ; directory to cwd to before exec (def no cwd) ;umask=022 ; umask for process (default None) ;priority=-1 ; the relative start priority (default -1) ;autostart=true ; start at supervisord start (default: true) ;startsecs=1 ; # of secs prog must stay up to be running (def. 1) ;startretries=3 ; max # of serial start failures when starting (default 3) ;autorestart=unexpected ; autorestart if exited after running (def: unexpected) ;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) ;stopsignal=QUIT ; signal used to kill process (default TERM) ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) ;stopasgroup=false ; send stop signal to the UNIX process group (default false) ;killasgroup=false ; SIGKILL the UNIX process group (def false) ;user=chrism ; setuid to this UNIX account to run the program ;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners ;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO ;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) ;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) ;stdout_events_enabled=false ; emit events on stdout writes (default false) ;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO ;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) ;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) ;stderr_events_enabled=false ; emit events on stderr writes (default false) ;environment=A="1",B="2" ; process environment additions ;serverurl=AUTO ; override serverurl computation (childutils) ; The sample group section below shows all possible group values. Create one ; or more 'real' group: sections to create "heterogeneous" process groups. ;[group:thegroupname] ;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions ;priority=999 ; the relative start priority (default 999) ; The [include] section can just contain the "files" setting. This ; setting can list multiple files (separated by whitespace or ; newlines). It can also contain wildcards. The filenames are ; interpreted as relative to this file. Included files *cannot* ; include files themselves. ;[include] ;files = relative/directory/*.ini
使用echo_supervisord_conf > /etc/supervisord.conf命令将配置文件保存在xx下面,然后修改配置文件。推荐的方式是将最后一行修改到某个固定文件夹,如下:
echo_supervisord_conf > /etc/supervisor/supervisord.conf #配置Supervisor
编辑,修改最后一行 为
[include]
files = conf.d/*.conf
进入目录 /etc/supervisor/ 新建 conf.d文件夹,conf.d文件夹下新建AYTestCore2.conf文件,编辑内容
备注
[program:simpleserver]
command=python -m SimpleHTTPServer # 执行的命令 ,若是虚拟环境则需要注意命令的路径,见配置2
directory=/home/wang/Downloads # 执行命令的路径
user=wang # 执行命令的用户
autorestart=true # 出错后自动重启
redirect_stderr=true # 错误日志重定向
stdout_logfile=/home/wang/Log/SimpleHTTPServer.log # 日志的路径
loglevel=info # 日志的级别
然后终端,加载这个配置文件
supervisord -c /etc/supervisor/supervisord.conf
ps -ef | grep AYTestCore2
supervisorctl reload #重新加载
此时关掉那个监听终端,网站也可以访问了,但是给予supervisord的,所以,需要配置supervisord开机启动
/usr/lib/systemd/system/ 新建文件 supervisord.service
# dservice for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
开启启动了。
systemctl enable supervisord
systemctl is-enabled supervisord #来验证是否为开机启动
接下来我们把端口号 5000和6000关闭
# firewall-cmd --zone=public --remove-port=5000/tcp --permanent
# firewall-cmd --zone=public --remove-port=6000/tcp --permanent
====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======请不要转载谢谢了。=========
到此 ASP.NET CORE 基本环境解决了。
1 需要.net core环境,安装nginx的web容器,自启动
2 设置端口号,防火墙的问题
3 nginx跳转80到6000端口
4 配置守护服务,让core站点一直运行,不依赖终端。
5 配置守护服务自启动,这样开机自启动站点了
=======================
可选装 mysql
http://www.cnblogs.com/starof/p/4680083.html (我用的方法二)
下载 http://www.rarsoft.com/download.htm
把文件放服务器上。然后cd到这个目录执行
tar -zxvf rarlinux-x64-5.4.0.tar.gz # rarlinux-x64-5.4.0.tar.gz是你下载的文件名cd rarmakerar #安装
安装好了后我们就可以打命令解压文件了
cd #跳到压缩文件目录rar x ceshi.rar #解压到当前文件夹 ceshi.rar是压缩文件名rar a abc.rar ceshi #压缩文件夹 到 abc.rar
在CentOS中安装完rar命令,会自动安装zip命令
cd /home #进入/home目录zip -r mydata.zip mydata #把/home目录下面的mydata目录压缩为mydata.zipunzip mydata.zip -d mydatabak #把/home目录下面的mydata.zip解压到mydatabak目录里面zip -r abc123.zip abc 123.txt #把/home目录下面的abc文件夹和123.txt压缩成为abc123.zipunzip wwwroot.zip #把/home目录下面的wwwroot.zip直接解压到/home目录里面 unzip abc\*.zip #把/home目录下面的abc12.zip、abc23.zip、abc34.zip同时解压到/home目录里面 unzip -v wwwroot.zip #查看把/home目录下面的wwwroot.zip里面的内容 unzip -t wwwroot.zip #验证/home目录下面的wwwroot.zip是否完整 unzip -j wwwroot.zip #把/home目录下面wwwroot.zip里面的所有文件解压到第一级目录
推荐您阅读更多有关于“net core2,”的文章
抖音:wpfui 工作wpf,目前主maui
招聘合肥一枚WPF工程师,跟我一个开发组,10-15K,欢迎打扰
目前在合肥市企迈科技就职
AYUI8全源码 Github地址:前往获取
杨洋(AaronYang简称AY,安徽六安人)和AY交流
高中学历,2010年开始web开发,2015年1月17日开始学习WPF
声明:AYUI7个人与商用免费,源码可购买。部分DEMO不免费
不是从我处购买的ayui7源码,我不提供任何技术服务,如果你举报从哪里买的,我可以帮你转正为我的客户,并送demo
查看捐赠AYUI7.X MVC教程 更新如下:
第一课 第二课 程序加密教程
额 本文暂时没人评论 来添加一个吧
发表评论