CentOS7/8下安装Node.js

官网

官网传送门:官网
CentOS安装: YUM安装

在 RHEL, CentOS, CloudLinux 或 Fedora 使用root权限

Node.js v18.x

As root

1
curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -

Node.js v17.x

As root

1
curl -fsSL https://rpm.nodesource.com/setup_17.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_17.x | sudo bash -

Node.js v16.x

As root

1
curl -fsSL https://rpm.nodesource.com/setup_16.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -

Node.js LTS (16.x)

As root

1
curl -fsSL https://rpm.nodesource.com/setup_lts.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -

NodeJS 14.x

root权限

1
curl -sL https://rpm.nodesource.com/setup_14.x | bash -

非root权限

1
curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -

NodeJS 13.x

root权限

1
curl -sL https://rpm.nodesource.com/setup_13.x | bash -

非root权限

1
curl -sL https://rpm.nodesource.com/setup_13.x | sudo bash -

NodeJS 12.x

root权限

1
curl -sL https://rpm.nodesource.com/setup_12.x | bash -

非root权限

1
curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -

NodeJS 10.x

root权限

1
curl -sL https://rpm.nodesource.com/setup_10.x | bash -

非root权限

1
curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -

安装构建工具

1
yum install gcc-c++ make

更多版本Linux安装请移步: GitHub

Linux

常用命令

CPU占用最多的前10个进程

1
ps auxw|head -1;ps auxw|sort -rn -k3|head -10

内存消耗最多的前10个进程

1
ps auxw|head -1;ps auxw|sort -rn -k4|head -10

虚拟内存使用最多的前10个进程

1
ps auxw|head -1;ps auxw|sort -rn -k5|head -10

下载文件

1
wget XXXX

多线程下载

1
2
3
4
# 软件安装
yum install axel
# 执行下载
axel -n 10 -o /tmp/ http://XXXX

查询当前目录下各文件大小

1
2
3
4
5
du -h --max-depth=1  | sort -nr | head

# 按文件大小排序
du --max-depth=1 /opt | sort -nr | head

清空文件内容

1
cat /dev/null> access.log

限制 /var/log/journal 文件大小

1
2
3
4
5
# 保留最近一周
journalctl --vacuum-time=1w

# 限制文件大小为500MB
journalctl --vacuum-size=500M

CentOS7 安装更高版本git

1
yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm

CentOS7 安装code-server

更多: 安装code-server

CentOS7 安装C++17

1
2
3
4
5
6
7
yum install centos-release-scl

yum-config-manager --enable rhel-server-rhscl-7-rpms

yum install devtoolset-7

scl enable devtoolset-7 bash

CentOS 防火墙

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
# 开放多个端口
firewall-cmd --zone=public --add-port=80-90/tcp --permanent && firewall-cmd --reload

#删除端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent
#查看防火墙所有信息
firewall-cmd --list-all

#查看防火墙开放的端口信息
firewall-cmd --list-ports

#启动
systemctl start firewalld

#查看状态
systemctl status firewalld

#开机不启动
systemctl disable firewalld

#关闭
systemctl stop firewalld

#开机启动
systemctl enable firewalld


nginx 调优

nginx 很优秀

实施步骤

按下面内容进行

下载阿里开源镜像的EPEL源

1
2
3
4
5
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo

# 缓存数据
yum clean all
yum makecache

操作系统

1
2
ulimit -n   # 系统打开文件数
ulimit -u # 用户打开文件数

添加base auth

1
2
3
4
5
6
7
# 创建用户
htpasswd -b ./htpasswd user30 zWQ7GnzL

#在 nginx.conf中添加
auth_basic "Please enter your username and password";
auth_basic_user_file /etc/nginx/htpasswd;

Nginx

连接数 打开文件数 事件

1
2
3
4
5
6
7
8
9
10
11
user nginx;
worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
worker_rlimit_nofile 65535;

events {
use epoll; #事件模式
worker_connections 204800; # 打开连接数
multi_accept on;
}

其它配置

代理socket

1
2
3
4
5
6
7
8
9
10
11
12
stream {
upstream cloudsocket {
hash $remote_addr consistent;
server xxx.xxx.xxx.xx:3306 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 3306;#数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
proxy_pass cloudsocket;
}
}

代理http

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
server {
listen 80;
server_name xxx.com;
root html;
index index.html index.htm;

location /favicon.ico {
root /usr/share/nginx/html/;
}

location /api {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://127.0.0.1:8080;
}

location / {
root /dist;
index index.html index.htm;
try_files $uri $uri/ @rewrites;
}

location @rewrites{
rewrite ^(.+)$ /index.html last;
}

# 匹配/node /info /search
location ~* ^/(node|info|search)/ {
proxy_pass http://localhost:8080;
}
}

## 代理多个
location ~* ^/(sys|app|api|oss|login|getInfo|logout) {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_cache_valid 200 60m;
proxy_cache_min_uses 2;
proxy_cache_methods GET;
proxy_pass http://127.0.0.1:9090;
}

## 添加层级目录
location ~^/ddchain/ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
proxy_pass http://127.0.0.1:8089;
rewrite "^/ddchain(.*)$" $1 break;
}



隐藏版本号

1
2
# 在http中
server_tokens off;

防止爬虫抓取

1
2
3
4
if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot")
{
return 403;
}

HEXO使用

官网:Hexo!
文档:documentation
FAQ:troubleshooting
反馈:GitHub

快速入门

创建文章

1
$ hexo new "My New Post"

更多: Writing

运行服务

1
$ hexo server

更多: Server

生成静态文件

1
$ hexo generate

更多: Generating

部署到远程服务器

1
$ hexo deploy

更多: Deployment

多语言支持

更多: https://pygments.org/docs/lexers/

创建新的分类

1
$ hexo new page categories

RSS插件

安装

1
$ npm install hexo-generator-feed

配置

1
2
3
4
5
6
7
8
# Extensions
plugins:
hexo-generator-feed
#Feed Atom
feed:
type: atom
path: atom.xml
limit: 20

引用站内文章

1
{% post_link 文章文件名(不要后缀) 文章标题(可选) %}

安装图片支持

1
npm install https://github.com/CodeFalling/hexo-asset-image --save

安装加密

1
npm install --save hexo-blog-encrypt