当前为:centos 7 ,此文是在学习linux时做一个指令合集,方便自己查阅
shell命令框建议使用xshell,文件上传建议使用xftp(界面化软件,非常好用)
进文件夹:cd xxx 返回最上级文件夹:cd / 查看当前文件夹的所有文件:ls前期准备:安装netcore环境,参照https://www.cnblogs.com/v587yy/p/12148087.htmlnetcore网站发布后可使用xftp上传到linux服务器,进入网站所在文件夹之后netcore网站可使用dotnet xxx.dll运行,运行后想要在外网访问,需要搭建nginx
1.查看所有进程:ps -ef 2.查看特定进程:ps -ef |grep redis ps:将某个进程显示出来 -A 显示所有程序。 -e 此参数的效果和指定"A"参数相同。 -f 显示UID,PPIP,C与STIME栏位。 grep命令是查找 中间的|是管道命令 是指ps命令与grep同时执行 这条命令的意思是显示有关redis有关的进程 3.kill[参数][进程号] kill -9 4394 kill就是给某个进程id发送了一个信号。默认发送的信号是SIGTERM,而kill -9发送的信号是SIGKILL,即exit。exit信号不会被系统阻塞,所以kill -9能顺利杀掉进程。当然你也可以使用kill发送其他信号给进程。摘自https://www.cnblogs.com/yiyangl/p/11130577.html
创建服务定义文件: sudo nano /etc/systemd/system/kestrel-hellomvc.service 以下是应用的示例服务文件:
[Unit] Description=Example .NET Web API App running on Ubuntu [Service] WorkingDirectory=/var/aspnetcore/hellomvc ExecStart=/usr/bin/dotnet /var/aspnetcore/hellomvc/hellomvc.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 SyslogIdentifier=dotnet-example User=xxx Environment=ASPNETCORE_ENVIRONMENT=Development [Install] WantedBy=multi-user.target
保存文件并启用服务。 systemctl enable kestrel-hellomvc.service 启动服务并验证其是否正在运行。 systemctl start kestrel-hellomvc.service systemctl status kestrel-hellomvc.service 您需要使用应用 dll 的路径将工作目录( 路径到您的应用和Exec Start)设置为文件夹。默认情况下,这就足够了。摘自https://blog.csdn.net/wojiaosha123/article/details/98784936
centos安装.net core 环境 sudo yum update 注册Microsoft签名密钥,每个机器只要注册一次就可以 sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm 安装.Net Core SDK ,这里根据项目环境,需要安装2.2版的。不同的开发环境选择对应的运行时版本 sudo yum install dotnet-sdk-2.2 完成后,通过命令,可以看出.net core的版本 dotnet --version 摘自https://www.cnblogs.com/v587yy/p/12148087.html
安装nginx yum -y install nginx 测试是否安装正确: nginx -t 打印如下: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful CentOS7.0+ nginx实现停止、启动、重启 systemctl stop nginx.service systemctl start nginx.service systemctl restart nginx.service systemctl status nginx.service 开机自启: systemctl enable nginx.service 取消开机自启: systemctl disable nginx.service nginx配置的修改: 修改nginx.conf(位置在/etc/nginx/)文件,可将配置文件放在一个文件夹中,让nginx自己去读取自定义的配置文件,修改结果如下
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
include /etc/nginx/conf.d/*.conf;这一句的意思是从/etc/nginx/conf.d/文件夹中搜索所有*.conf的配置文件填充进配置中,例如我发布了一个网站,端口号是5000,如果不进行nginx映射,只能在linux的内网中进行访问,
无法在外网进行访问
例如我在/etc/nginx/conf.d/中添加了myblog.conf,如下面,重启nginx后,80端口的http请求都会转向到内部的5000端口,这样自己的网站就可以访问了
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
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_ipgrade;
}
}
来源:https://www.cnblogs.com/wangpengzong/p/12397911.html