运行code-server命令报错,node not found

运行code-server命令报错,node not found

/usr/lib/code-server/lib/vscode/bin/remote-cli/code-server: 12: /usr/lib/code-server/lib/vscode/node: not found

/usr/lib/code-server/lib/vscode目录下没有node这个程序,看了下在/usr/lib/code-server/lib 目录下有node,用ln做个链接就好了

ln -s /usr/lib/code-server/lib/node /usr/lib/code-server/lib/vscode

Ubuntu Server 从20.04升级到22.04

先更新一下包再重启一下

apt update
apt upgrade
reboot

然后升级系统

do-release-upgrade -d

升级过程中有要确认的选项直接默认回车就行了,大概十分钟就升级完成了

Ubuntu 22.04 升级到PHP8了,所以要改一下nginx的配置文件,把原来的7.4改成8.1,这样网站才能正常运行

fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;

打开网站后,WordPress会显示很多已弃用的警告,关闭debug就不会显示了,这些警告不会影响到网站

Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in .../wp-content/plugins/wordpress-seo/src/integrations/admin/helpscout-beacon.php on line 108
Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in .../wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 22
Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in .../wp-content/plugins/wordpress-seo/src/conditionals/third-party/elementor-edit-conditional.php on line 28
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../wp-includes/functions.php on line 7035
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in .../wp-includes/functions.php on line 2164
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../wp-includes/functions.php on line 7035
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in .../wp-includes/functions.php on line 2164
null to parameter #1 ($string) of type string is deprecated in .../wp-includes/formatting.php on line 2772

wp-config.php文件里关掉debug就不会显示了

define( 'WP_DEBUG', false ); 

我在Piwigo里,也会显示出相同的警告,编辑local/config/config.inc.php文件,加入下面的代码也可以关掉已弃用警告

$conf['show_php_errors'] = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_WARNING;

zsh: corrupt history file /root/.zsh_history

cd ~
mv .zsh_history .zsh_history_bad
strings -eS .zsh_history_bad > .zsh_history
fc -R .zsh_history

linux 查找指定大小文件和大目录

查找>4G文件

find . -type f -size +4G

查找<4G文件

find . -type f -size -4G

查找大于40M小于30M的文件

find -size +30M -size -40M

配合 -exec 输出更多信息

find . -type f -size +4G -exec ls -lh {} +

查找大目录

du -Sh | sort -rh | head -5

不包括子目录

du -hs * | sort -rh | head -5

Ubuntu正确卸载nginx

apt-get remove --purge nginx nginx-full nginx-common

Ubuntu WordPress 开启redis 缓存

安装redis

apt-get update
apt-get install redis redis-server php-redis

编辑 /etc/redis/redis.conf 文件,添加

maxmemory 256mb
maxmemory-policy allkeys-lfu

重启服务

systemctl restart redis-server
systemctl restart php7.4-fpm
systemctl restart apache2

编辑wp-config.php文件添加

define( 'WP_CACHE_KEY_SALT', 'zuoridangnian.com' );
define( 'WP_CACHE', true );

安装Redis Object Cache 插件,点击开启缓存即可

下面查看一下效果

WP有个 Query Monitor 插件,可以查看一个页面的查询次数

未开启Redis Object Cache时,我的后台页面和首页查询次数是这样的

分别是68个查询和56个查询

开启后减少为32和25,大约节约一半的查询次数

腾讯云轻量服务器定时创建快照

把下面的实例ID和secretId、secretKey替换就行了,这里是查询快照然后删除快照并新建一个快照。

由于腾讯云一个轻量只能有两个快照,我这里直接删除第二个快照,所以设置定时任务时,设置多久创建一次新快照都行。

// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");

const LighthouseClient = tencentcloud.lighthouse.v20200324.Client;

const clientConfig = {
  credential: {
    secretId: "更改为账号secretId",
    secretKey: "更改为账号secretKey",
  },
  region: "ap-guangzhou",
  profile: {
    httpProfile: {
      endpoint: "lighthouse.tencentcloudapi.com",
    },
  },
};

const client = new LighthouseClient(clientConfig);

const chakan = {
  "Filters": [
    {
      "Name": "instance-id",
      "Values": [
        "更改为实例id"
      ]
    }
  ]
};

client.DescribeSnapshots(chakan).then(

  (data) => {

    shanchu_id = data.SnapshotSet[1].SnapshotId //数组的第二个

    const shanchu = {
      "SnapshotIds": [
        shanchu_id
      ]
    };

    client.DeleteSnapshots(shanchu).then(
      (data) => {

        console.log('删除一个旧快照成功');
        console.log(data);

        // 创建快照

        const chuangjian = {
          "InstanceId": "更改为实例id"
        };
        client.CreateInstanceSnapshot(chuangjian).then(
          (data) => {
            console.log('创建一个新快照成功');
            console.log(data);
          },
          (err) => {
            console.error("error", err);
          }
        );

      },
      (err) => {

        console.log('删除一个旧快照失败~~~~必须已有两个快照,才能删除第二个快照并创建新快照');
        console.error("error", err);
      }
    );

  },
  (err) => {

    console.log('查询旧快照失败');
    console.error("error", err);
  }
);

这里是查询一个轻量的流量使用情况,然后发邮件通知我。这里除了实例id和密钥要替换外,还要设置smtp信息。

// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");

const LighthouseClient = tencentcloud.lighthouse.v20200324.Client;

const nodemailer = require('nodemailer'); //发送邮件的


function bytesToSize(bytes) {
  var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  if (bytes == 0) return '0 Byte';
  var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}

function sendEmail(data) {
  let transporter = nodemailer.createTransport({
    service: 'QQex', // 发送者的邮箱厂商,支持列表:https://nodemailer.com/smtp/well-known/ 如果是qq邮箱,就填QQ, QQex是腾讯企业邮
    port: 465, // SMTP 端口
    secureConnection: true, // SSL安全链接
    auth: {   //发送者的账户密码
      user: '账户', //账户
      pass: 'smtp授权码,到邮箱设置下获取', //smtp授权码,到邮箱设置下获取
    }
  });
  let mailOptions = {
    from: '"腾讯云轻量流量通知" <i@zuoridangnian.com>', // 发送者昵称和地址
    to: data.email, // 接收者的邮箱地址
    subject: data.subject, // 邮件主题
    html: data.content
  };
  //发送邮件
  transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
      return console.log(error);
    }
    console.log('邮件发送成功 ID:', info.messageId);
  });
}

const clientConfig = {
  credential: {
    secretId: "更改为账号secretId",
    secretKey: "更改为账号secretKey",
  },
  region: "ap-guangzhou",
  profile: {
    httpProfile: {
      endpoint: "lighthouse.tencentcloudapi.com",
    },
  },
};

const client = new LighthouseClient(clientConfig);
const params = {
  "InstanceIds": [
    "更改为实例id"
  ]
};

let Traffic

client.DescribeInstancesTrafficPackages(params).then(
  (data) => {
    Traffic = `使用了${bytesToSize(data.InstanceTrafficPackageSet[0].TrafficPackageSet[0].TrafficUsed)},总共有1000GB。`

    let mail = {
      email: '收件邮箱@qq.com', //收件邮箱
      content: `腾讯云轻量应用服务器 流量使用情况:${Traffic}`,
      subject: Traffic
    }

    sendEmail(mail)

  },
  (err) => {
    console.error("error", err);
  }
)

Crontab 定时脚本中出现 command not found

原因是cron中仅传递少部分环境变量,如下

LANGUAGE=en_US.utf8:
HOME=/root
LOGNAME=root
PATH=/usr/bin:/bin
LANG=en_US.utf8
SHELL=/bin/sh
PWD=/root

而我想使用的命令文件在 /usr/local/bin/ 目录中,不在默认的环境变量中

解决办法是在定时脚本中加入PATH变量

#!/bin/bash
PATH="/usr/local/bin:/usr/bin:/bin"
# 脚本内容

如果定时任务不是脚本文件,而是命令的话,可以用绝对路径的去执行命令,例如 /snap/bin/certbot ... 这样子。

Apache 域名跳转到目录

RewriteEngine On
RewriteCond %{SERVER_NAME} =photo.zuoridangnian.com
RewriteRule ^ https://zuoridangnian.com/photo-gallery%{REQUEST_URI} [END,NE,R=permanent]

Ubuntu 20.04 apache开启http2

apt update && apt upgrade
apt install apache2 php7.4-fpm 
a2enmod proxy_fcgi setenvif
a2enconf php7.4-fpm 
a2dismod php7.4 
systemctl restart apache2
a2dismod mpm_prefork 
a2enmod mpm_event 
systemctl restart apache2
systemctl restart php7.4-fpm
a2enmod http2
systemctl restart apache2

没有更多文章了