岁月随笔

给时间添上漂亮的一笔

0%

环境:

Centos 7

已安装.Net core 3.1. 410

  1. Supervisor安装

    • yum 安装

      1
      yum install supervisor

    (阿里云验证通过)

    • easy_install 安装

      如果yum安装无法找到资源,可以通过easy_install

      1
      wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | sudo python

    安装supervisor

    1
    easy_install supervisor
  2. 配置supervisor

    • 在etc下创建目录,并赋权限

      1
      mkdir -m 700 -p /etc/supervisor
    • 在目录“ /etc/supervisor”下创建配置文件

      1
      echo_supervisord_conf > /etc/supervisor/supervisord.conf
    • 修改配置文件

      1
      vim /etc/supervisor/supervisord.conf

      在文件末尾添加,注意首尾需无空格,需顶格

      1
      2
      [include]
      files=/etc/supervisor/conf.d/*.conf
    • 在目录“/etc/supervisor”下创建dotnet core 进程配置文件存放目录“conf.d”

      1
      mkdir -m 700 /etc/supervisor/conf.d
  3. 创建进程配置文件

    1
    vim /etc/supervisor/conf.d/MyDotNetName.conf

    “MyDotNetName”可以为dotnet core 入口dll文件名字 ,插入内容,注意首尾需无空格,需顶格:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [program:MyDotNetName] ;显示名称
    command=/bin/bash -c "dotnet MyDotNetName.dll" ;运行命令,启动dotnet进程
    directory=/usr/PublishOutput/ ;MyDotNetName目录
    stderr_logfile=/var/log/MyDotNetName.error.log ;错误日志文件
    stdout_logfile=/var/log/MyDotNetName.stdout.log ;日志文件
    environment=ASPNETCORE_ENVIRONMENT=Production ;进程环境变量
    user=root ;进程执行用户
    autostart=true ;自动启动
    autorestart=true ;是否自动重启
    startsecs=3 ;自动重启间隔时间
  4. 创建supervisor 自启动服务

    1
    vim /etc/systemd/system/supervisor.service

    编辑内容:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [Unit]
    Description=supervisor

    [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

    使配置生效

    1
    systemctl daemon-reload

    设置服务开机启动,即设置enable

    1
    systemctl enable supervisor.service

    启动服务

    1
    systemctl start supervisor.service
  5. 验证dotnet进程是否启动

    使用命令“ps -ef | grep dotnet”查看dotnet 是否运行

    1
    ps -ef | grep dotnet
  6. supervisor远程管理

    使用命令“vim /etc/supervisor/supervisord.conf”修改配置文件,如下设置

    1
    vim /etc/supervisor/supervisord.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ;[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))
    ;以下内容开启http服务
    [inet_http_server]
    port=192.168.1.71:9001 ;ip 加端口
    username=admin ;登陆账号,可以不设
    password=123456 ;登陆账户,可以不设
  7. 重启服务,就可以访问了

    注意防火墙是否对端口9001例外

查看服务器.net core环境信息

1
dotnet --info
安装.net core环境

如果服务器只是用来运行.net core程序,则只需安装.net core runtime即可;如果要做开发和编译工作,则需要安装.net core sdk

.net core sdk包含了.net core runtime,所以这里就直接安装.net core skd了

官方安装文档:https://docs.microsoft.com/zh-cn/dotnet/core/install/linux-centos

  1. 执行命令,将Microsoft包签名密钥添加到受信任密钥列表,并添加Microsoft包存储库

    1
    sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
  2. 执行命令,安装.net core 3.1 sdk

    1
    sudo yum install dotnet-sdk-3.1
  3. 安装结束后,再次输入 dotnet –info 查看环境信息

将.net core 项目发布到文件系统
  1. 上传到服务器
启动.net core 项目
1
dotnet xxxx.dll

解决办法

1.修改#include部分

1
2
3
4
//当编译器非gcc时,不包含cxxabi.h头文件
#ifdef __GNUC__
#include <cxxabi.h>
#endif

2.修改demangle函数,当编译器为MSVC时直接将输入参数返回

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
static inline std::string demangle(const std::string &name)
{
#ifdef _MSC_VER
return name; // 为MSVC编译器时直接返回name
#elif defined(__GNUC__)
// 为gcc编译器时还调用原来的代码
int status=0;
char *p=abi::__cxa_demangle(name.c_str(), 0, 0, &status);
std::string ret(p);
free(p);
return ret;
#else
// 其他不支持的编译器需要自己实现这个方法
#error unexpected c complier (msc/gcc), Need to implement this method for demangle
#endif
}

输出目录:

1
$(SolutionDir)/bin/$(Platform)/$(Configuration)/

中间目录:

1
$(SolutionDir)/temp/$(Platform)/$(Configuration)/$(ProjectName)/

Next 8.x 自动添加可切换的暗黑模式

安装 Hexo 插件

安装 hexo-next-darkmode 插件

1
npm install hexo-next-darkmode --save

配置 Hexo 插件

在 Next 主题的 _config.yml 配置文件里添加以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Darkmode JS
# For more information: https://github.com/rqh656418510/hexo-next-darkmode, https://github.com/sandoche/Darkmode.js
darkmode_js:
enable: true
bottom: '64px' # default: '32px'
right: 'unset' # default: '32px'
left: '32px' # default: 'unset'
time: '0.5s' # default: '0.3s'
mixColor: 'transparent' # default: '#fff'
backgroundColor: 'transparent' # default: '#fff'
buttonColorDark: '#100f2c' # default: '#100f2c'
buttonColorLight: '#fff' # default: '#fff'
saveInCookies: true # default: true
label: '🌓' # default: ''
autoMatchOsTheme: true # default: true
libUrl: # Set custom library cdn url for Darkmode.js

关闭原生的暗黑模式

确保 Next 原生的 darkmode 选项设置为 false,在 Next 的 _config.yml 配置文件中更改以下内容:

1
darkmode: false

暗黑模式 CSS 样式自定义

暗黑模式激活后,hexo-next-darkmode 插件会将 darkmode–activated CSS 类添加到 body 标签,可以利用它覆盖插件默认自带的 CSS 样式(如下所示);这样就可以实现暗黑模式 CSS 样式的高度自定义,包括代码块颜色自定义切换等。更多配置内容介绍可以参考官方文档

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
.darkmode--activated {
--body-bg-color: #282828;
--content-bg-color: #333;
--card-bg-color: #555;
--text-color: #ccc;
--blockquote-color: #bbb;
--link-color: #ccc;
--link-hover-color: #eee;
--brand-color: #ddd;
--brand-hover-color: #ddd;
--table-row-odd-bg-color: #282828;
--table-row-hover-bg-color: #363636;
--menu-item-bg-color: #555;
--btn-default-bg: #222;
--btn-default-color: #ccc;
--btn-default-border-color: #555;
--btn-default-hover-bg: #666;
--btn-default-hover-color: #ccc;
--btn-default-hover-border-color: #666;
--highlight-background: #282b2e;
--highlight-foreground: #a9b7c6;
--highlight-gutter-background: #34393d;
--highlight-gutter-foreground: #9ca9b6;
}

.darkmode--activated img {
opacity: 0.75;
}

.darkmode--activated img:hover {
opacity: 0.9;
}

.darkmode--activated code {
color: #69dbdc;
background: transparent;
}

设置访问时默认为深色

在./node_modules/hexo-next-darkmode 目录下找到 darkmode.njk 文件
修改内容如下

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
<script src="{%if config.darkmode_js.libUrl %}{{ config.darkmode_js.libUrl }}{%else%}https://fastly.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js{%endif%}"></script>

<script>
var options = {
bottom: '{{ config.darkmode_js.bottom }}',
right: '{{ config.darkmode_js.right }}',
left: '{{ config.darkmode_js.left }}',
time: '{{ config.darkmode_js.time }}',
mixColor: '{{ config.darkmode_js.mixColor }}',
backgroundColor: '{{ config.darkmode_js.backgroundColor }}',
buttonColorDark: '{{ config.darkmode_js.buttonColorDark }}',
buttonColorLight: '{{ config.darkmode_js.buttonColorLight }}',
saveInCookies: {{ config.darkmode_js.saveInCookies }},
label: '{{ config.darkmode_js.label }}',
autoMatchOsTheme: {{ config.darkmode_js.autoMatchOsTheme }}
}
const darkmode = new Darkmode(options);
darkmode.showWidget();
//新增的内容,如果不是深色模式,则激活深色模式
if(!darkmode.isActivated())
{
darkmode.toggle();
}
</script>

重新构建生成静态文件

Hexo 重新构建生成静态文件后,点击页面上的按钮即可切换暗黑模式

1
hexo c & hexo g & hexo d

群晖的套件中心可以安装MariaDB5和MariaDB10,但是远程访问功能是默认关闭的,可以通过以下命令开启。

1
2
3
4
5
6
7
8
# ssh到Synology
sudo -i # 提权
cd /volume1/@appstore/MariaDB10/usr/local/mariadb10/bin #访问目录
./mysql -u root -p # 这里有个坑,root密码和MariaDB密码是不同的,需要在套件中心各自设置
use mysql # 选择数据库
update user set host = '192.168.1.%' where user = 'root'; #可以直接使用%,也可以用192.168.1.%来缩小范围
select host, user from user; # 确认,也可以使用select User,host from mysql.user;
FLUSH PRIVILEGES; # 刷新权限

之后就可以用HeidiSQL等远程访问了。

群晖Docker安装chevereto图床

Docker chevereto准备的环境

mysql数据库(我目前是使用的是MariaDB 10,套件中心直接安装)

我用的是Navicat,新建数据库填写chevereto下面:

chevereto6.th.png

Docker chevereto的下载

在群晖docker里面的注册表里面搜索

chevereto1.th.png

Docker chevereto的存储卷

chevereto2.th.png

Docker chevereto的配置

容器整体下载完成后,点击下载的附加文件名的小箭头,查看该容器该如何进行配置,docker其实大部分都有配置介绍,多看看自己也会配置

chevereto3.th.png

chevereto4.th.png

双击该变量进行安装,容器名称随意填充,内存限制根据实际需要填充,单击高级设置,启用自动重新启动打钩,卷设置里面点击添加文件夹,选择你刚刚在docker目录下创建的chevereto目录,后面加载路径填充【/ var / www / html / images】,不能有空间,请注意,然后在到端口设置,本地端口设置为10000,容器端口不需要修改,后面进行docker的环境配置,

chevereto5.th.png

点击启用后,可以使用http:群晖地址:10000进行访问,设置相关的信息

有时会提示群晖没有对图像文件夹的写入权限,后面对/ volume1 / docker / chevereto赋予权限即可!

也可以从ssh里面直接授予所有权限

1
chmod +r 777 chevereto

Docker chevereto修改上传大小

http://域名:10000 / dashboard / settings / image-upload

获取root权限

1
2
admin@DSM3617:~$ sudo -i
root@DSM3617:~#

查看运行的docker容器

1
2
3
4
5
6
7
root@DSM3617:/volume1/docker# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc9701c6850c nmtan/chevereto:latest "docker-php-entrypoi…" 6 hours ago Up 29 minutes 0.0.0.0:10000->80/tcp nmtan-chevereto1
a906997c2ff6 synology/gitlab:11.11.8 "/sbin/entrypoint.sh…" 3 weeks ago Up 5 hours 443/tcp, 0.0.0.0:30001->22/tcp, 0.0.0.0:30000->80/tcp synology_gitlab
f6e478504c02 sameersbn/postgresql:10 "/sbin/entrypoint.sh" 3 weeks ago Up 5 hours 5432/tcp synology_gitlab_postgresql
1c6ced1ca7ad sameersbn/redis:4.0.9-1 "/sbin/entrypoint.sh" 3 weeks ago Up 5 hours 6379/tcp synology_gitlab_redis

复制到群晖本地目录

1
2
root@DSM3617:~# docker cp  bc9701c6850c:/var/www/html/.htaccess /volume1/docker/
root@DSM3617:~#

修改配置文件

1
vi /volume1/docker/.htaccess
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
# Disable server signature
ServerSignature Off



# Disable directory listing (-indexes), Multiviews (-MultiViews) and enable Follow system links (+FollowSymLinks)
Options -Indexes
Options -MultiViews

<IfModule mod_rewrite.c>

RewriteEngine On

# If you have problems with the rewrite rules remove the "#" from the following RewriteBase line
# You will also have to change the path to reflect the path to your Chevereto installation
# If you are using alias is most likely that you will need this.
#RewriteBase /

# 404 images
# If you want to have your own fancy "image not found" image remove the "#" from RewriteCond and RewriteRule lines
# Make sure to apply the correct paths to reflect your current installation
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule images/.+\.(gif|jpe?g|png|bmp) - [NC,L,R=404]
#RewriteRule images/.+\.(gif|jpe?g|png|bmp) content/images/system/default/404.gif [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpe?g|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ [NC]
RewriteRule . index.php [L]
#修改上传文件大小增加以下 配置 最大支持 32M 根据自己情况配置
php_value post_max_size 64M
php_value upload_max_filesize 32M

</IfModule>

复制到容器目录里面

1
docker cp /volume1/docker/.htaccess bc9701c6850c:/var/www/html/

然后进入到docker容器管理里面重新启动即可解除2m上传限制

chevereto7.png

VSCode 使用CMake构建

CMakeLists.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cmake_minimum_required(VERSION 3.0.0)
project(test VERSION 0.1.0)

include(CTest)
enable_testing()

aux_source_directory(src SRC_SUB)
aux_source_directory(. SRC_CUR)
add_executable(demo ${SRC_SUB} ${SRC_CUR} )
include_directories(include)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

task.json

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
{
"options": {
"cwd": "${workspaceFolder}/build/"
},
"tasks": [
{
"label": "cmake",
"type": "shell",
"command":"cmake",
"args": [".."]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true,
},
"command":"mingw32-make.exe",
"args": []
},
{
"label": "Build My Project",
"dependsOn":[
"cmake",
"make"
]
}
],
"version": "2.0.0"
}

launch.json

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
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\demo.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build My Project"
}
]
}

常用操作

合并

把master合到分支

1
2
3
4
5
6
git checkout master 
git pull
git checkout 分支名
git pull
git merge master
git push -u origin 分支名

把分支合到master

1
2
3
4
5
6
git checkout 分支名
git pull
git checkout master
git pull
git merge 分支名
git push -u origin master

打 TAG

1
2
git tag "tags/tag名称"
git push origin "tags/tag名称"

对比

1
2
3
git diff --name-status 'tags/tag名称' HEAD 项目/path

git diff HEAD 'tags/tag名称'

拉取最新代码及解决冲突(避免产生 merge 记录)

1
2
3
4
5
6
1. git log #查看本地版本最新时间
2. 尝试 git pull 能否直接更新,如可以,更新结束。如报错,进行第三步
3. git add . #本地修改保存
4. git stash #本地修改暂存到栈里
5. git pull #不报错
6. git stash pop #取出栈,会提示冲突。手动解决冲突后,正常commit 提交

本地配置

检查自动修改换行符配置

1
2
git config --global  --list
git config --global core.autocrlf false

删除相关(慎用)

回滚本地

1
2
git log 找到恢复的hash
git reset --hard 恢复的hash

丢弃修改

1
git checkout -- *

删除分支

1
git push origin --delete branch/分支名称