Linux挂载qcow2格式文件

挂载命令

1
sudo guestmount -a /path/***.qcow2 -m /dev/sda1 /挂载点/

-m 要挂载的qcow2镜像文件中的分区名

  • 例如

1
sudo guestmount -a /home/a.qcow2 -m /dev/sda1 /home/a/

卸载命令

1
sudo guestunmount /挂载点/
  • 例如

1
sudo guestunmount /home/a/

Linux WebDav Mount
1
2
3
4
5
6
7
8
apt-get -y install davfs2
mkdir /davdir
mount -t davfs https://****/dav/ /davdir
sed -i 's/# use_locks 1/use_locks 0/g' /etc/davfs2/davfs2.conf

echo "你的WebDAV地址 用户名 密码" >> /etc/davfs2/secrets #保存用户名密码,以后可以直接免密码挂载

mount.davfs 你的WebDAV地址 你想要挂载到的目录

NextCloud Cron jobs

cron

1
2
3
4
5
crontab -u www-data -e

*/5 * * * * php -f /var/www/html/nextcloud/cron.php

systemctl restart cron.service

Systemd

    1. Create files in /etc/systemd/system/nextcloudcron.service
      1
      2
      3
      4
      5
      6
      [Unit]
      Description=Nextcloud cron.php job
      [Service]
      User=www-data
      ExecStart=/usr/local/bin/php -f /var/www/html/nextcloud/cron.php
      KillMode=process
    1. Create files in /etc/systemd/system/nextcloudcron.timer
      1
      2
      3
      4
      5
      6
      7
      8
      9
      [Unit]
      Description=Run Nextcloud cron.php every 5 minutes
      [Timer]
      OnBootSec=5min
      OnUnitActiveSec=5min
      Unit=nextcloudcron.service
      [Install]
      WantedBy=timers.target
      systemctl enable --now nextcloudcron.timer

Run

1
docker exec -it --user www-data nextcloud /usr/local/bin/php -f /var/www/html/nextcloud/cron.php

Docker occ scan

php occ files:scan –help

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
Description:
rescan filesystem

Usage:
files:scan [options] [--] [<user_id>...]

Arguments:
user_id will rescan all files of the given user(s)

Options:
--output[=OUTPUT] Output format (plain, json or json_pretty, default is plain) [default: "plain"]
-p, --path=PATH limit rescan to this path, eg. --path="/alice/files/Music", the user_id is determined by the path and the user_id parameter and --all are ignored
--all will rescan all files of all known users
--unscanned only scan files which are marked as not fully scanned
--shallow do not scan folders recursively
--home-only only scan the home storage, ignoring any mounted external storage or share
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--no-warnings Skip global warnings, show command output only
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

阅读更多
Linux Network Setup

IP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.0.147
netmask 255.255.255.0
gateway 192.168.0.1

DNS

1
2
3
4
/etc/resolv.conf
nameserver 1.1.1.1
nameserver 8.8.8.8


cloudflare ddns auto update

原文链接:https://github.com/yulewang/cloudflare-api-v4-ddns

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#/bin/bash
set -o errexit
set -o nounset
set -o pipefail

date "+%n%F %T"

# Automatically update your CloudFlare DNS record to the IP, Dynamic DNS
# Can retrieve cloudflare Domain id and list zone's, because, lazy

# Place at:
# From https://github.com/yulewang/cloudflare-api-v4-ddns
# curl https://raw.githubusercontent.com/yulewang/cloudflare-api-v4-ddns/master/cf-v4-ddns.sh > /usr/local/bin/cf-ddns.sh && chmod +x /usr/local/bin/cf-ddns.sh
# run `crontab -e` and add next line:
# */1 * * * * /usr/local/bin/cf-ddns.sh >/dev/null 2>&1
# or you need log:
# */1 * * * * /usr/local/bin/cf-ddns.sh >> /var/log/cf-ddns.log 2>&1


# Usage:
# cf-ddns.sh -k cloudflare-api-key \
# -u user@example.com \
# -h host.example.com \ # fqdn of the record you want to update
# -z example.com \ # will show you all zones if forgot, but you need this
# -t A|AAAA # specify ipv4/ipv6, default: ipv4

# Optional flags:
# -f false|true \ # force dns update, disregard local stored ip

# default config

# API key, see https://www.cloudflare.com/a/account/my-account,
# incorrect api-key results in E_UNAUTH error
CFKEY=

# Username, eg: user@example.com
CFUSER=

# Zone name, eg: example.com
CFZONE_NAME=

# Hostname to update, eg: homeserver.example.com
CFRECORD_NAME=next.litao.cloud

# Record type, A(IPv4)|AAAA(IPv6), default IPv4
CFRECORD_TYPE=AAAA

# Cloudflare TTL for record, between 120 and 86400 seconds
CFTTL=120

# Ignore local file, update ip anyway
FORCE=false

#WANIPSITE="http://ipv6.icanhazip.com"
WANIPSITE=`ifconfig | grep global | awk {'print $2'}`


# Site to retrieve WAN ip, other examples are: bot.whatismyipaddress.com, https://api.ipify.org/ ...
if [ "$CFRECORD_TYPE" = "AAAA" ]; then
:
elif [ "$CFRECORD_TYPE" = "A" ]; then
WANIPSITE="http://ipv4.icanhazip.com"
else
echo "$CFRECORD_TYPE specified is invalid, CFRECORD_TYPE can only be A(for IPv4)|AAAA(for IPv6)"
exit 2
fi

# get parameter
while getopts k:u:h:z:t:f: opts; do
case ${opts} in
k) CFKEY=${OPTARG} ;;
u) CFUSER=${OPTARG} ;;
h) CFRECORD_NAME=${OPTARG} ;;
z) CFZONE_NAME=${OPTARG} ;;
t) CFRECORD_TYPE=${OPTARG} ;;
f) FORCE=${OPTARG} ;;
esac
done

# If required settings are missing just exit
if [ "$CFKEY" = "" ]; then
echo "Missing api-key, get at: https://www.cloudflare.com/a/account/my-account"
echo "and save in ${0} or using the -k flag"
exit 2
fi
if [ "$CFUSER" = "" ]; then
echo "Missing username, probably your email-address"
echo "and save in ${0} or using the -u flag"
exit 2
fi
if [ "$CFRECORD_NAME" = "" ]; then
echo "Missing hostname, what host do you want to update?"
echo "save in ${0} or using the -h flag"
exit 2
fi

# If the hostname is not a FQDN
if [ "$CFRECORD_NAME" != "$CFZONE_NAME" ] && ! [ -z "${CFRECORD_NAME##*$CFZONE_NAME}" ]; then
CFRECORD_NAME="$CFRECORD_NAME.$CFZONE_NAME"
echo " => Hostname is not a FQDN, assuming $CFRECORD_NAME"
fi

# Get current and old WAN ip
WAN_IP=`curl -s ${WANIPSITE}`
WAN_IP_FILE=$HOME/.cf-wan_ip_$CFRECORD_NAME.txt
if [ -f $WAN_IP_FILE ]; then
OLD_WAN_IP=`cat $WAN_IP_FILE`
else
echo "No file, need IP"
OLD_WAN_IP=""
fi

# If WAN IP is unchanged an not -f flag, exit here
if [ "$WAN_IP" = "$OLD_WAN_IP" ] && [ "$FORCE" = false ]; then
echo "WAN IP Unchanged, to update anyway use flag -f true"
exit 0
fi

# Get zone_identifier & record_identifier
ID_FILE=$HOME/.cf-id_$CFRECORD_NAME.txt
if [ -f $ID_FILE ] && [ $(wc -l $ID_FILE | cut -d " " -f 1) == 4 ] \
&& [ "$(sed -n '3,1p' "$ID_FILE")" == "$CFZONE_NAME" ] \
&& [ "$(sed -n '4,1p' "$ID_FILE")" == "$CFRECORD_NAME" ]; then
CFZONE_ID=$(sed -n '1,1p' "$ID_FILE")
CFRECORD_ID=$(sed -n '2,1p' "$ID_FILE")
else
echo "Updating zone_identifier & record_identifier"
CFZONE_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$CFZONE_NAME" -H "X-Auth-Email: $CFUSER" -H "X-Auth-Key: $CFKEY" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 )
CFRECORD_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$CFZONE_ID/dns_records?name=$CFRECORD_NAME" -H "X-Auth-Email: $CFUSER" -H "X-Auth-Key: $CFKEY" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 )
echo "$CFZONE_ID" > $ID_FILE
echo "$CFRECORD_ID" >> $ID_FILE
echo "$CFZONE_NAME" >> $ID_FILE
echo "$CFRECORD_NAME" >> $ID_FILE
fi

# If WAN is changed, update cloudflare
echo "Updating DNS to $WAN_IP"

RESPONSE=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$CFZONE_ID/dns_records/$CFRECORD_ID" \
-H "X-Auth-Email: $CFUSER" \
-H "X-Auth-Key: $CFKEY" \
-H "Content-Type: application/json" \
--data "{\"id\":\"$CFZONE_ID\",\"type\":\"$CFRECORD_TYPE\",\"name\":\"$CFRECORD_NAME\",\"content\":\"$WAN_IP\", \"ttl\":$CFTTL}")

if [ "$RESPONSE" != "${RESPONSE%success*}" ] && [ "$(echo $RESPONSE | grep "\"success\":true")" != "" ]; then
echo "Updated succesfuly!"
echo $WAN_IP > $WAN_IP_FILE
exit
else
echo 'Something went wrong :('
echo "Response: $RESPONSE"
exit 1
fi


Docker Server

MariaDB

1
2
3
4
5
6
7
8
9
10
docker run -d \
-p 3306:3306 \
-v /my/own/datadir:/var/lib/mysql \
--name mariadb \
-e MYSQL_ROOT_PASSWORD=PASSWORD \
-e MYSQL_DATABASE=DATABASE \
-e MYSQL_USER=USER \
-e MYSQL_PASSWORD=PASSWORD \
mariadb:latest

阅读更多
SmartDNS

参考原文链接:https://pymumu.github.io/smartdns/

Step 1 下载SmartDNS

1
wget https://github.com/pymumu/smartdns/releases/download/Release33/smartdns.1.2020.09.08-2235.x86_64-linux-all.tar.gz

Step 2 解压并安装

1
2
3
4
tar zxf smartdns.1.2020.09.08-2235.x86_64-linux-all.tar.gz
cd smartdns
chmod +x ./install
./install -i
阅读更多