當前為:centos 7 ,此文是在學習linux時做一個指令合集,方便自己查閱 shell命令框建議使用xshell,文件上傳建議使用xftp(界面化軟體,非常好用) 進文件夾:cd xxx 返回最上級文件夾:cd / 查看當前文件夾的所有文件:ls前期準備:安裝netcore環境(點擊直接跳轉) ...
當前為:centos 7 ,此文是在學習linux時做一個指令合集,方便自己查閱
shell命令框建議使用xshell,文件上傳建議使用xftp(界面化軟體,非常好用)
進文件夾:cd xxx 返回最上級文件夾:cd / 查看當前文件夾的所有文件:ls
前期準備:安裝netcore環境(點擊直接跳轉),參照https://www.cnblogs.com/v587yy/p/12148087.html
netcore網站發佈後可使用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; } }