Jiliuke

激流客

自动设置token

为了简化操作,有时候需要postman在请求接口后自动设置token,方法如下
打开postman,在一个请求下面点击Tests,输入以下代码

1
2
var responseData = responseBody;
pm.environment.set("token", responseData.replace(/\"/g,''));

在debian查看SSD寿命

  1. 查看Wear_Leveling_CountSSD_Life_Left
    1
    sudo smartctl -a /dev/sdb
    不同的SSD使用smartctl展示不同

wear leveling count是 磨损均衡计数(WLC)的意思,当前值代表的剩余耐力,以百分比表示,意味着它从100开始减少。

SSD_Life_Left代表着SSD的生命周期还剩下多少

  1. 查看 Percentage Used Endurance Indicator
    1
    sudo smartctl -l devstat /dev/sdb
    最重要和直观Percentage Used Endurance Indicator,单位是百分比,新的是0%

实际应用中会出现需要减少导出的备份体积,然后在本地导入再开发,可以大幅缩短导入等待时间,方法如下

1
sed '/INSERT INTO `tablelog1`/d' xxxx.sql | sed '/INSERT INTO `tablelog2`/d' | sed '/INSERT INTO `tablelog3`/d' | sed '/INSERT INTO `tablelog4`/d' | sed '/INSERT INTO `tablelog5`/d' > reduced.sql

一些有用mysql tips

1
2
3
4
5
6
7
8
#统计所有数据库从大到小排列
select TABLE_SCHEMA,round(SUM(DATA_LENGTH + INDEX_LENGTH)/1024/1024,2) as data from information_schema.tables GROUP BY TABLE_SCHEMA order by data desc;
#统计数据库大小
select round(SUM(DATA_LENGTH + INDEX_LENGTH)/1024/1024,2) as data from information_schema.tables where TABLE_SCHEMA="xxxxxx";
#统计数据表大小
select table_name,round(SUM(DATA_LENGTH + INDEX_LENGTH)/1024/1024,2) as data from information_schema.tables where TABLE_SCHEMA="xxxxxx" GROUP BY table_name order by data desc;
#批量修改域名
UPDATE core_config_data SET value = replace (value,'xxx.xxx.com','xxx.xxx.local') WHERE value LIKE '%xxx.xxx.com%';

需求

magento2 在运行的时候会不断在项目中var/log中记录日志,时间久后就会产生巨大的log日志,所以有必要每天切割日志保存,利于日志分析和减少磁盘开销。

方法 (仅对于linux)

1.首先确定当前的项目名称(magento2)和项目路径(/var/www/magento2),项目执行用户www

2.sudo vim /etc/logrotate.d/magento2
3.拷贝以下内容到/etc/logrotate.d/magento2

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
 {
daily
missingok
rotate 365
maxage 365
compress
copytruncate
prerotate
# logrotate fails if the .1 file already exists, which only
# ever happens if the last copytruncate failed, or during the
# first run after delaycompress is disabled. When this script
# runs, older logs have already been rotated, so it's safe to
# rotate an unexpected log.1 file into log.2.gz. Sometimes the
# argument already has a .1 suffix, so strip it.
[ -e "${1%.1}.1" ] && sudo -u -g bash -c "gzip --best < \"${1%.1}.1\" > \"${1%.1}.2.gz\"" && rm "${1%.1}.1"
true
endscript
notifempty
create 0640 www www
su www www
lastaction
chown www:www -R /var/www/magento2/var/log/*.log
# fix files with broken permissions
chown www:www -R /var/www/magento2/var/log/*.log.[0-9]*.gz 2>/dev/null || true
endscript
}

4.测试

1
2
3
4
#强制执行
sudo logrotate -f /etc/logrotate.d/magento2
#调试模式
sudo logrotate -d /etc/logrotate.d/magento2

当服务器中curl访问https站点出现以下问题时

1
2
3
4
5
6
7
curl: (60) SSL certificate problem: certificate has expired

More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.

问题原因

由于服务器curl证书问题导致无法正确访问https站点

解决办法

1
2
3
4
5
6
#红帽系系统
yum install ca-certificates openssl
curl -k https://curl.se/ca/cacert.pem > cacert.pem
openssl x509 -outform der -in cacert.pem -out cacert.crt
update-ca-trust
ls -l /etc/pki/tls/certs/

参考连接

https://curl.se/docs/sslcerts.html

https://curl.se/docs/caextract.html

在deepin linux中安装nvidia官方驱动的方法

首先,到nvdia官网下载对应显卡的linux驱动
https://www.nvidia.com/Download/index.aspx?lang=en-us
一般对应的下载文件会在~/Downloads下,将它重新命令nvidia.sh便于后面引用。

接下来请按照以下步骤执行。

  1. 卸载nvidia开源驱动和闭源驱动

    1
    sudo apt autoremove nvidia-*
  2. 禁止nouveau驱动

    1
    sudo dedit /etc/modprobe.d/blacklist.conf

    执行以上代码打开blacklist.conf文件后复制以下内容并保存关闭

    1
    2
    3
    4
    5
    blacklist nouveau
    blacklist lbm-nouveau
    options nouveau modeset=0
    alias nouveau off
    alias lbm-nouveau off
  3. blacklist.conf添加执行权限

    1
    sudo chmod +x /etc/modprobe.d/blacklist.conf

    blacklist nouveau是禁用nouveau第三方驱动,之后不需要改回来,由于nouveau是构建在内核中的,所以要执行下面代码集成到内核中

    1
    sudo update-initramfs -u

    好了,到现在为止,前期工作已经完成。

  4. 重启
    可以运行以下命令

    1
    reboot
  5. 重启后查看nouveau有没有运行,没有输出则代表禁用生效

    1
    lsmod | grep nouveau
  6. 同时按住ctrl+alt+F2键,进入tty2。输入当前用户名点击enter然后再输入密码点击enter进入。

  7. 导航到Downloads目录,为nvidia.sh添加执行权限。

    1
    cd ~/Downloads && chmod +x nvidia.sh
  8. 关闭图形界面

    1
    sudo systemctl stop lightdm
  9. 安装显卡驱动

    1
    sudo sh nvidia.sh

    请注意接下来的步骤,一定要完成相同,否则将造成无法登陆图形界面

    注意英文字母中出现大写的“DKMS”选择Yes

    注意英文中出现“32-bit”选择Yes

    注意英文中出现“nvidia-xconfig”一定要选择No

  10. 输入reboot重启电脑,安装完成

参考视频

https://www.ixigua.com/7024358143215960590

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash 
id="user"
pwd="password"
$db="db"
backuppath="/app/"$user"/var/dbbackup"
day=15
[ ! -d $backuppath ] && mkdir -p $backuppath
cd $backuppath

dbname=$db'_'
backupname=$dbname`date +%Y%m%d%H%M%S`
mysqldump -h127.0.0.1 -u$id -p$pwd $db --single-transaction --triggers --skip-tz-utc --ignore-table-data=$db.quote_id_mask | gzip -> $backupname.sql.gz
find $backuppath -name $dbname"*.sql.gz" -type f -mtime +$day -exec rm -rf {} \;

开发中,如果遇到某种特殊情况下,无法访问外网,则可以设置代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//file vendor/magento/framework/HTTP/Adapter/Curl.php after line 26
/**
* Parameters array
*
* @var array
*/
protected $_config = [
'protocols' => (CURLPROTO_HTTP
| CURLPROTO_HTTPS
| CURLPROTO_FTP
| CURLPROTO_FTPS
),
'verifypeer' => true,
'verifyhost' => 2,
'proxy' => "http://127.0.0.1:8888"//add http proxy here
];
1
2
3
4
5
6
//file vendor/magento/zendframework1/library/Zend/Http/Client.php after line 1089
$response = $this->adapter->read();
//remove extra response afteradd proxy
if (false !== stripos($response, "HTTP/1.1 200 Connection established\r\n\r\n")) {
$response = str_ireplace("HTTP/1.1 200 Connection established\r\n\r\n", '', $response);
}

问题

打包后安装出现双图标

解决办法

desktop中添加StartupWMClass=xxx
xxx通过终端中执行xprop WM_CLASS点击应用程序获取。

0%