下载解压

离线包:https://nodejs.org/en/download/

1
2
xz -d node-v14.2.0-linux-x64.tar.xz
tar -xvf node-v14.2.0-linux-x64.tar

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 移动到/usr/local
mv node-v14.2.0-linux-x64 /usr/local/nodejs-v14.2

# 添加环境变量

# 进入 /etc/profile 文件
vim /etc/profile
# 在文件末尾添加
export PATH=$PATH:'/usr/local/nodejs-v14.2/bin'

# 使环境变量生效
source /etc/profile

# 验证
node -v
npm -v

参考:

CentOS 7.3 离线二进制安装 nodeJS

原因

1
unix:///tmp/supervisor.sock no such file

supervisor 默认配置会把 socket 文件和 pid 守护进程生成在/tmp/目录下,/tmp/目录是缓存目录,Linux 会根据不同情况自动删除其下面的文件。

修改配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
vi /etc/supervisord.conf

# 英文分号后的内容为注释
[unix_http_server]
;file=/tmp/supervisor.sock ; (the path to the socket file)
file=/var/run/supervisor.sock ; 修改为 /var/run 目录,避免被系统删除

[supervisord]
;logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile=/var/log/supervisord.log ; 修改为 /var/log 目录,避免被系统删除
pidfile=/var/run/supervisord.pid ; 修改为 /var/run 目录,避免被系统删除
...

[supervisorctl]
; 必须和'unix_http_server'里面的设定匹配
;serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
serverurl=unix:///var/run/supervisor.sock ; 修改为 /var/run 目录,避免被系统删除

可选:

  • 修改权限
1
2
sudo chmod 777 /run
sudo chmod 777 /var/log
  • 创建supervisor.sock
1
2
sudo touch /var/run/supervisor.sock
sudo chmod 777 /var/run/supervisor.sock

更新配置文件

1
supervisorctl update

参考:

“unix:///tmp/supervisor.sock no such file” 错误处理 (亲测)

[https://blog.csdn.net/qq_28885149/article/details/79364685](解决unix:///tmp/supervisor.sock no such file的问题)

常用命令

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
## 启动服务:
systemctl start firewalld.service

## 关闭服务:
systemctl stop firewalld.service

##重启服务:
systemctl restart firewalld.service

##显示服务的状态:
systemctl status firewalld.service

##开机自动启动:
systemctl enable firewalld.service

##禁用开机自动启动:
systemctl disable firewalld.service

##查看版本:
firewall-cmd --version

##查看帮助:
firewall-cmd --help

##显示状态:
firewall-cmd --state

##查看所有打开的端口:
firewall-cmd --zone=public --list-ports

## 开端口/服务
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --zone=public --add-port=5001/tcp --permanent

##更新防火墙规则:
firewall-cmd --reload

##查看区域信息:
firewall-cmd --get-active-zones

##查看指定接口所属区域:
firewall-cmd --get-zone-of-interface=eth0

##拒绝所有包:
## 注意:通过SSH等远程连接,千万不要用,除非可以连接宿主机
--firewall-cmd --panic-on

##取消拒绝状态:
firewall-cmd --panic-off

##查看是否拒绝:
firewall-cmd --query-panic

检查

检查mysql是否存在

1
rpm -qa | grep mysql

检查mysql组合用户是否存在

1
2
3
# 检查mysql组和用户是否存在,如无则创建
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql

查看全部用户:

1
cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F ":" '{print $1 "|" $3 "1" $4}' | more

若不存在,则创建mysql组和用户

1
2
3
4
5
6
7
8
# 创建mysql用户组
groupadd mysql

# 创建一个用户名为mysql的用户,并加入mysql用户组
useradd -g mysql mysql

# 制定mysql用户的password
passwd mysql

注:永久性删除用户账号

1
2
userdel peter
groupdel peter

参考:centos系统添加/删除用户和用户组

下载离线包

官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

版本选择,可以选择一下两种方式:

1
2
Red Hat Enterprise Linux
Linux - Generic

上传离线包到服务器

1
2
3
tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql
mv mysql /usr/local

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 更改所属的组和用户
cd /usr/local/
chown -R mysql mysql/
chgrp -R mysql mysql/
cd mysql/
mkdir data
chown -R mysql:mysql data

[centos系统添加/删除用户和用户组](https://www.cnblogs.com/nyfz/p/8557137.html)

# 创建my.cnf文件

# 进入/usr/local/mysql文件夹下
cd /usr/local/mysql

# 创建my.cnf文件
touch my.cnf #或者cd ''>my.conf

# 编辑my.cnf
vim my.cnf

注意:/etc/目录下可能会存在 my.cnf,需要删除

1
2
ls /etc/ | grep my.cnf
rm -rf /etc/my.cnf

my.cnf:

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
# 对其他远程连接的mysql客户端的配置
[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8mb4

# 解决 this is incompatible with sql_mode=only_full_group_by 的错误
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

# 本地mysql服务的配置
[mysqld]
socket=/var/lib/mysql/mysql.sock
bind-address=0.0.0.0
# set mysql server port
port = 3306 #默认是3306,防止端口冲突发生,可以避免使用 3306 mysql默认端口
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
# 设置置 MySQL 的最大连接,按你实际情况适当设置。出现 'Too many connections' 错误,是因为 max_connections 的值太低,需要设置更高的链接数,
# max_connection 值被设高之后的缺陷是当服务器运行超过设置阈值或更高的活动事务时会变的没有响应。
max_connections=3000
character-set-client-handshake = FALSE
# set server charactre default encoding
character-set-server=utf8mb4
collation-server = utf8mb4_unicode_ci
# the storage engine
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true

# 解决 this is incompatible with sql_mode=only_full_group_by 的错误
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[mysql.server]
user=mysql
basedir=/usr/local/mysql

# 对本地的mysql客户端的配置
[client]
default-character-set = utf8mb4

注:在MySQL中,utf8 编码只支持每个字符最多三个字节,而真正的 UTF-8 是每个字符最多四个字节,
MySQL 的 utf8mb4 才是真正的 UTF-8
utf8mb4 的最低mysql版本支持版本为5.5.3+,若不是,请升级到较新版本。

参考:

语法
chown [-cfhvR] [–help] [–version] user[:group] file…
参数 :

user : 新的文件拥有者的使用者 ID
group : 新的文件拥有者的使用者组(group)
-c : 显示更改的部分的信息
-f : 忽略错误信息
-h :修复符号链接
-v : 显示详细的处理信息
-R : 处理指定目录以及其子目录下的所有文件
–help : 显示辅助说明
–version : 显示版本

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 进入mysql
cd /usr/local/mysql

# 安装mysql
bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

cp ./support-files/mysql.server /etc/init.d/mysqld

# 设置文件及目录权限
chmod +x /etc/init.d/mysqld
chown 777 my.cnf
chown -R mysql:mysql data
mkdir /var/lib/mysql/
chown -R mysql:mysql /var/lib/mysql/

ls -l

启动mysql

1
2
3
4
5
# 启动
/etc/init.d/mysqld start

# 重启
/etc/init.d/mysqld restart

注:错误日志在 /usr/local/mysql/dataXXXX.err 文件。

报错:

1
2
3
4
[root@renshelaodongbangong-sj0001 mysql]# /etc/init.d/mysqld restart
MySQL server PID file could not be found! [FAILED]
Starting MySQL.Logging to '/usr/local/mysql/data/renshelaodongbangong-sj0001.err'.
[ OK ]

解决方案:

1
2
3
4
5
6
7
8
9
10
11
12
#找到是否已经有进程占用
ps aux|grep mysql
kill -9 100684

# 确定是否还有占用
ps aux|grep mysql

# 启动
/etc/init.d/mysqld start

# 重启
/etc/init.d/mysqld restart

开机启动

1
2
3
4
5
6
7
8
chkconfig --level 35 mysqld on
chkconfig --list mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld

#检查状态
service mysqld status

修改配置

1
2
3
4
5
6
7
8
9
10
vim /etc/profile

# 修改/etc/profile,在最后添加如下内容:

#set mysql environment
export PATH=$PATH:/usr/local/mysql/bin

# 使文件生效
[root@ren mysql]# vim /etc/profile
[root@ren mysql]# source /etc/profile

设置密码

1
2
3
# 获取初始密码
cat /root/.mysql_secret
ugcNJt;ZAx7+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 登录
mysql -uroot -p
Enter password: #此处填写上边获取到的初始密码
# 修改
set password=password('password');
UPDATE user SET Password = password('password') WHERE User = 'mysql';
flush privileges
exit

# 验证新密码
mysql -uroot -p
Enter password: #此处输入新密码

show tables;
show databases;

常见报错

(1)如果报错:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2),

解决方案,创建软链接:

1
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

也可以使用下面的方式连接:

1
mysql -uroot -h 127.0.0.1 -p

(2)ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.

使用忽略授权表的方法进入mysql:

1
2
3
vim my.cnf
[mysqld]
skip-grant-tables=1

使用命令重启mysql:

1
2
3
service mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL. [ OK ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 进入mysql
mysql -uroot -p

use mysql;

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER USER() IDENTIFIED BY 'test1';
Query OK, 0 rows affected (0.05 sec)

select * from mysql.user where user='root' \G
update user set authentication_string=password('test') where user='root' and Host='localhost';

update user set password_expired='N' where user='root';

# 刷新
flush privileges;

# 退出
quit;

之后把 my.cnf 的 skip-grant-tables=1 这行注释掉

添加远程访问权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+---------------+
3 rows in set (0.00 sec)

重启mysql生效

1
2
3
/etc/init.d/mysqld restart
# 或
service mysqld restart

配置防火墙

注意:针对各种云,因为有专门策略,所以不需要操作防火墙;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

## 重新查询端口是否开放
firewall-cmd --query-port=3306/tcp

## 查看监听的端口
netstat -lnpt

#关闭端口
firewall-cmd --zone=public --remove-port=3306/tcp --permanent

## 查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports

查看监听的端口

1
netstat -lnpt | grep 3306

执行脚本

1
2
3
4
5
6
7
8
CREATE DATABASE data1

use data1

进入mysql:

-- 执行脚本
source /sql/data1.sql

参考:

centos7下使用mysql离线安装包安装mysql5.7

对mysql的高并发优化配置的一些思考

监听的 IP 可以选择本地回环地址,特定的 IP 以及任意 IP,分别是:

1
2
3
127.0.0.1 127.0.0.2 127.0.0.3…… 本地回环地址
192.168.120.102 特定的 IP
0.0.0.0 任意 IP
  • 监听本地回环地址时,则访问仅限于本机应用程序,不需要管理员权限来添加防火墙配置。

  • 本地计算机配置了反向代理服务器,推荐使用本地回环地址。

  • 如果让服务对外公开提供,则需要设置为 0.0.0.0 任意 IP。

UseUrls

1
2
3
4
5
6
7
8
9
10
11
12
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:8080")
.UseStartup<Startup>();
}

appsettings.json

1
2
3
4
5
6
7
8
9
10
11
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"urls": "http://*:5000",
"AllowedHosts": "*"
}

参考:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/host/web-host?view=aspnetcore-3.1#override-configuration

命令行

使用命令行参数 --urls

http协议,监听IP 地址,监听端口

1
dotnet WebApplication1.dll --urls http://0.0.0.0:5000

设置环境变量

ASPNETCORE_URLS

1
environment=ASPNETCORE_URLS='http://0.0.0.0:5000'

参考:

dotnet 命令

ASP.NET Core Web 主机

你需要知道的这几种 asp.net core 修改默认端口的方式

如何设置 ASP.NET Core 程序监听的 IP 和端口

下载

官网下载

下载地址:redis-5.0.8.tar.gz

安装

安装gcc依赖

1
yum install gcc

解压安装

1
2
3
4
5
tar -zxvf redis-5.0.8.tar.gz
cd redis-5.0.8
cd src
make distclean # make distclean清除之前生成的文件(可选)
make && make install

修改配置文件

编辑 redis.conf:

1
vim /ldjc/rj/redis-5.0.8/redis.conf

进入vim 输入 / 再按 回车用来搜索关键字

比如如下命令会定位到文件中出现 bind 的位置并会将关键词用颜色区分。

/bind

  • 1,后台启动

搜索 daemonize no 改为 daemonize yes

  • 2,设置密码

搜索 requirepass password 添加 requirepass 设置的密码

requirepass password

  • 3,外部访问

搜索 bind 127.0.0.1 然后使用 #注释掉

1
# bind 127.0.0.1

启动

命令:

1
2
3
4
5
6
7
cd /ldjc/rj/redis-5.0.8

# 启动
/usr/local/bin/redis-server /ldjc/rj/redis-5.0.8/redis.conf

# 连接
/usr/local/bin/redis-cli

示例:

1
2
3
4
5
6
7
8
9
10
11
12
[root@host-192-125-30-11 redis-5.0.8]# /usr/local/bin/redis-server /ldjc/rj/redis-5.0.8/redis.conf
15531:C 12 May 2020 16:07:35.523 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
15531:C 12 May 2020 16:07:35.523 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=15531, just started
15531:C 12 May 2020 16:07:35.523 # Configuration loaded
[root@host-192-125-30-11 redis-5.0.8]# /usr/local/bin/redis-cli
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth root
OK
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>

开放端口

注意:针对各种云,因为有专门策略,所以不需要操作防火墙;

  • 开放6379端口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
firewall-cmd --zone=public --add-port=6379/tcp --permanent

#重启防火墙
firewall-cmd --reload

## 重新查询端口是否开放
firewall-cmd --query-port=6379/tcp

## 查看监听的端口
netstat -lnpt

#关闭6379端口
firewall-cmd --zone=public --remove-port=6379/tcp --permanent

## 查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports
  • 查找redis
    ps aux | grep redis

关闭Redis服务

1
2
3
4
5
6
7
[root@localhost bin]# pkill redis-server
[root@localhost bin]# netstat -tunpl | grep 6379
[root@localhost bin]# pstree -p | grep redis
[root@localhost bin]# /usr/local/bin/redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>

安装 setuptools

下载setuptools 46.2.0离线包

参考:installing

1
2
3
4
5
6
7
8
9
## 解压
unzip -o -d setuptools-46.2.0 setuptools-46.2.0.zip
# 把 setuptools-46.2.0.zip 文件解压到 setuptools-46.2.0
# -o :不提示的情况下覆盖文件
# -d:将文件解压缩到指定目录下
cd setuptools-46.2.0

## 安装
python setup.py install

需要安装 uzip 命令:

1
2
yum install zip
yum install unzip

从pip下载supervisor

下载supervisor 4.2.0离线包

参考:installing

进入文件所在目录:

1
2
3
4
5
6
## 解压
tar -zxvf supervisor-4.2.0.tar.gz
cd supervisor-4.2.0

## 安装
python setup.py install

验证安装是否成功

1
supervisorctl --help

配置supervisor

1
2
3
4
5
6
7
8
##创建supervisor所需目录
mkdir /etc/supervisord.d/

##创建supervisor配置文件
echo_supervisord_conf > /etc/supervisord.conf

##编辑supervisord.conf文件
vim /etc/supervisord.conf

[include] 标签中添加 /etc/supervisord.d/*.conf

1
2
[include]
files = relative/directory/*.ini /etc/supervisord.d/*.conf

长时间运行会报错 unix:///tmp/supervisor.sock no such file,参考

解决unix-tmp-supervisor-sock-no-such-file

测试supervisor

常用命令

1
2
3
4
5
6
7
supervisord -c /etc/supervisord.conf ## 启动
supervisorctl shutdown ## 关闭
supervisord -c /etc/supervisord.conf ## 通过配置文件启动supervisor
supervisorctl -c /etc/supervisord.conf status ## 查看状态
supervisorctl -c /etc/supervisord.conf reload ## 重新载入配置文件
supervisorctl -c /etc/supervisord.conf start [all]|[x] ## 启动所有/指定的程序进程
supervisorctl -c /etc/supervisord.conf stop [all]|[x] ## 关闭所有/指定的程序进程

部署测试站点

新建 WebApplication1.conf:

1
2
touch /etc/supervisord.d/WebApplication1.conf
vim /etc/supervisord.d/WebApplication1.conf

内容:

注意:supervisor配置文件中的注释使用英文分号 ;

配置文件名需要与program标签内名称一致!!!

asp net core 站点:

1
2
3
4
5
6
7
[program:WebApplication1]
command=/root/dotnet/dotnet WebApplication1.dll
directory=/test/webapi
environment=ASPNETCORE_ENVIRONMENT=Production
stopsignal=INT
stderr_logfile=/var/log/WebApplication1/WebApplication1.err.log
stdout_logfile=/var/log/WebApplication1/WebApplication1.out.log

注意:如果配置Linux开机启动服务报错,则需要配置 dotnet 命令全路径:/root/dotnet/dotnet

supervisor FATAL can't find command 'dotnet'

webapp 站点,使用 npm http-server:

1
2
3
4
5
6
[program:webapp]
command=http-server /test/webapp -p 8013
directory=/test/webapp
stopsignal=INT
stderr_logfile=/var/log/webapp/webapp.err.log
stdout_logfile=/var/log/webapp/webapp.out.log

详细命令参考:Configuration File

查看站点日志:

1
2
vim /var/log/WebApplication1.err.log
vim /var/log/WebApplication1.out.log

配置防火墙

注意:针对各种云,因为有专门策略,所以不需要操作防火墙;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
firewall-cmd --zone=public --add-port=5000/tcp --permanent
firewall-cmd --zone=public --add-port=5001/tcp --permanent
firewall-cmd --reload

## 重新查询端口是否开放
firewall-cmd --query-port=5000/tcp

## 查看监听的端口
netstat -lnpt

#关闭端口
firewall-cmd --zone=public --remove-port=5000/tcp --permanent

## 查看防火墙所有开放的端口
firewall-cmd --zone=public --list-ports

测试站点

1
2
3
4
5
6
7
curl -X GET "http://localhost:5000/weatherforecast" -H "accept: application/json"
curl -X GET "https://127.0.0.1:5001/weatherforecast" -H "accept: application/json"
curl -X GET "http://192.125.30.82:5000/weatherforecast" -H "accept: application/json"

# 查看状态
curl -o /dev/null -s -w %{http_code} -X GET "192.125.30.82:5100/weatherforecast" -H "accept: application/json"
curl -o /dev/null -s -w %{http_code} -X GET "192.125.30.82:8013/pages/tsjb/djsl.html" -H "accept: text/html"

开机启动

脚本:centos-systemd-etcs

1
2
3
4
5
6
7
8
9
[root@host supervisor-4.2.0]# touch /usr/lib/systemd/system/supervisord.service
[root@host supervisor-4.2.0]# vim /usr/lib/systemd/system/supervisord.service
[root@host supervisor-4.2.0]# systemctl enable supervisord
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
[root@host supervisor-4.2.0]# systemctl is-enabled supervisord
enabled
[root@host supervisor-4.2.0]# systemctl daemon-reload
[root@host supervisor-4.2.0]# systemctl restart supervisord
[root@host supervisor-4.2.0]# systemctl status supervisord

supervisord.service:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# supervisord service 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/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

设置成功后,可以使用下列命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 重启指定应用
supervisorctl restart <application name>

# 停止指定应用
supervisorctl stop <application name>

# 启动指定应用
supervisorctl start <application name>

# 查看状态
supervisorctl status

# 重启所有应用
supervisorctl restart all

# 停止所有应用
supervisorctl stop all

# 启动所有应用
supervisorctl start all

参考:

Installing

Supervisor离线安装、管理

挂载iso文件到挂载点

1
2
3
4
5
6
7
8
9
10
11
## 创建文件夹
mkdir -p /media/cdrom

## 挂载iso文件到挂载点
mount -o loop /media/CentOS-7-x86_64-DVD-1804.iso /media/cdrom

##查看挂载状态
df -h

## 重新挂载系统分区
mount -a

修改yum的配置文件,使用本地ISO做yum源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
cd /etc/yum.repos.d/

# (可选) 一个一个文件备份
mv CentOS-Base.repo CentOS-Base.repo.bak
cp CentOS-Media.repo CentOS-Media.repo.bak

mkdir bak
# 拷贝目录下所有.repo和.bak文件到 bak文件夹下
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.bak /etc/yum.repos.d/bak

# 新建 local.repo
touch local.repo
vi local.repo

# local.repo 内容
[local]
name=local_yum
baseurl=file:///media/cdrom
enable=1
gpgcheck=0

介绍:

1
2
3
4
5
6
[local]               #库名称
name=local   #名称描述
baseurl=file:///media/cdrom #yum源目录,源地址为rpm的目录
gpgcheck=1           #检查GPG-KEY,0为不检查,1为检查
enabled=1            #是否用该yum源,0为禁用,1为使用
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6  #gpgcheck=0时无需配置

清除缓存

1
2
yum clean all
yum list

测试

1
yum install libicu

参考:

centos–软件源–本地软件源—离线安装

CentOS 本地ISO 挂载并配置本地软件源

源代码形式

1.绝大多数开源软件都是直接以原码形式发布的

2.源代码一般会被打成.tar.gz的归档压缩文件

3.源代码需要编译成为二进制形式之后才能够运行使用

4.源代码基本编译流程:

1).configure 检查编译环境;

2)make对源代码进行编译;

3)make insall 将生成的可执行文件安装到当前计算机中

RPM

1.源代码形式的特点:操作复杂、编译时间长、极易出现问题、依赖关系复杂

2.为了方便,RPM(redhat package manager)

3.RPM通过将代码基于特定平台系统编译为可执行文件,并保存依赖关系,来简化开源软件的安装管理。针对不同的系统设定不同的包

4.常用命令规范:linuxcast-1.2.0-30.el6.1686.rpm 包名-版本号-适用平台-32/64-rpm

5.使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## 安装
rpm –i software.rpm

## 卸载
rpm -e software.rpm

## 升级形式安装
rpm –U software.rpm

## 例子
rpm –ivh http://www.linuxcast.net/software.rpm ## 支持通过http\ftp协议形式安装

-v 显示详细信息;-h显示进度条
查询功能:rpm –qa
列出全部已经安装的.rpm软件  rpm –qa |grep ***

YUM

1.rpm软件包形式的管理虽然方便,但是需要手工解决软件包的依赖关系。很多时候安装一个软件安装一个软件需要安装1个或者多个其他软件,手动解决时,很复杂,yum解决这些问题。Yum是rpm的前端程序,主要目的是设计用来自动解决rpm的依赖关系,其特点:

1)自动解决依赖关系;
2)可以对rpm进行分组,基于组进行安装操作;
3)引入仓库概念,支持多个仓库;
4)配置简单

2.yum仓库用来存放所有的现有的.rpm包,当使用yum安装一个rpm包时,需要依赖关系,会自动在仓库中查找依赖软件并安装。仓库可以是本地的,也可以是HTTP、FTP、nfs形式使用的集中地、统一的网络仓库。

3.仓库的配置文件/etc/yum.repos.d目录下

4.使用:

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
## 1 安装
yum install 全部安装
yum install package1 安装指定的安装包package1
yum groupinsall group1 安装程序组group1

## 2 更新和升级
yum update 全部更新
yum update package1 更新指定程序包package1
yum check-update 检查可更新的程序
yum upgrade package1 升级指定程序包package1
yum groupupdate group1 升级程序组group1

## 3 查找和显示
yum info package1 显示安装包信息package1
yum list 显示所有已经安装和可以安装的程序包
yum list package1 显示指定程序包安装情况package1
yum groupinfo group1 显示程序组group1信息yum search string 根据关键字string查找安装包

## 4 删除程序
yum remove &#124; erase package1 删除程序包package1
yum groupremove group1 删除程序组group1
yum deplist package1 查看程序package1依赖情况

## 5 清除缓存
yum clean packages 清除缓存目录下的软件包
yum clean headers 清除缓存目录下的 headers
yum clean oldheaders 清除缓存目录下旧的 headers
yum clean, yum clean all (= yum clean packages; yum clean oldheaders) 清除缓存目录下的软件包及旧的headers

5.查询软件:

可以使用 yumsearch **

参考:

linux中yum与rpm区别

linux yum命令详解

1
2
3
4
5
6
7
wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar -zxvf make-4.3.tar.gz
cd make-4.3
./configure
make
make install
ln -s -f /usr/local/bin/make /usr/bin/make

参考:

Centos7make编译安装

简介

CentOS,是基于 Red Hat Linux 提供的可自由使用源代码的企业级 Linux 发行版本;是一个稳定,可预测,可管理和可复制的免费企业级计算平台。

配置方法

  1. 备份
1
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  1. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

CentOS 8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
  1. 运行 yum makecache 生成缓存

  2. 其他
    非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用。用户也可自行修改相关配置: eg:

1
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

参考

CentOS 镜像

  1. rpm包安装的,可以用rpm -qa看到,如果要查找某软件包是否安装,用 rpm -qa | grep “软件或者包的名字”。

  2. deb包安装的,可以用dpkg -l能看到。如果是查找指定软件包,用dpkg -l | grep “软件或者包的名字”;

  3. yum方法安装的,可以用yum list installed查找,如果是查找指定包,命令后加 | grep “软件名或者包名”;

  4. 如果是以源码包自己编译安装的,例如.tar.gz或者tar.bz2形式的,这个只能看可执行文件是否存在了,
    上面两种方法都看不到这种源码形式安装的包。如果是以root用户安装的,可执行程序通常都在/sbin:/usr/bin目录下

  5. pip安装的所有包:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pip list

rpm -qa | grep libcurl
rpm -qa | grep openssl-libs
rpm -qa | grep krb5-libs
rpm -qa | grep zlib

rpm -qa | grep lttng-ust
rpm -qa | grep libicu

yum list installed | grep lttng-ust

yum list installed | libicu

rpm -qa | grep bzip2

lttng-ust
https://lttng.org/docs/v2.11/#doc-fedora

bzip2 –安装
https://www.cnblogs.com/thrillerz/p/3935789.html

PuTTYgen生成密钥

生成,并保存私钥(.ppk)格式。

QQ截图20200302165208.png

配置ssh密钥

在github设置页面配置:

QQ截图20200302113117.png

配置仓库

QQ截图20200302165822.png

Pageant 添加.ppk密钥

QQ截图20200302170027.png

简介

WSL1 和 WSL2
相比于 WSL1,WSL2 通过虚拟机的方式带来了更完整的 Linux 内核,但这种方式也引入了一些问题,微软给出了下面的图表来展示这些不同:

v2-bb7b8a23b362ba5329d66517f81fbca8_720w.jpg

安装

1
2
3
4
5
6
7
8
9
10
# 完全未安装 WSL 时才有效
wsl --install

# 以查看可用发行版列表并运行
wsl --list --online
# 或
wsl -l -o

# 安装发行版
wsl --install -d <DistroName>

--install 命令执行以下操作:

  • 启用可选的 WSL 和虚拟机平台组件
  • 下载并安装最新 Linux 内核
  • 将 WSL 2 设置为默认值
  • 下载并安装 Ubuntu Linux 发行版(可能需要重新启动)
阅读全文 »

后台任务

摘自:Background tasks with hosted services in ASP.NET Core

BackgroundService is a base class for implementing a long running IHostedService.

ExecuteAsync(CancellationToken) is called to run the background service. The implementation returns a Task that represents the entire lifetime of the background service. No further services are started until ExecuteAsync becomes asynchronous, such as by calling . Avoid performing long, blocking initialization work in . The host blocks in StopAsync(CancellationToken) waiting for to complete.awaitExecuteAsyncExecuteAsync

The cancellation token is triggered when IHostedService.StopAsync is called. Your implementation of should finish promptly when the cancellation token is fired in order to gracefully shut down the service. Otherwise, the service ungracefully shuts down at the shutdown timeout. For more information, see the IHostedService interface section.ExecuteAsync

总结

当继承 IHostedService 接口实现 BackgroundService 或者 BackgroundTasks ,其实现类在注入时,不受注入的先后顺序影响。

下面的例子,ConsumerManager 依赖 IKafkaEventBusContainer 的实现:

1
2
serviceCollection.AddHostedService<ConsumerManager>();
serviceCollection.AddSingleton<IKafkaEventBusContainer, EventBusContainer>();

参考:

Background tasks with hosted services in ASP.NET Core