Posts in category “Linux”

Seafile server configuration on CentOS 8

I am using the docker-compose version. The first problem I met was none of Seafile's concerns, it is actually a bug of docker. All of the containers cannot reach the internet (cannot resolve any DNS). The solution is at here.

After fixed the issue above, the Seafile server runs well on centos. However, there are still two issues that need to be addressed.

The first one is about the head icon of a user. It simply cannot display. You can easily found that the host part of the head icon is wrong. You need to edit "shared/seafile/conf/ccnet.conf" and change the SERVICE_URL to your real hostname in the [General] section.

The second one is similar, if you don't fix it, you cannot download any of the file you uploaded. This time, you need to edit "shared/seafile/conf/seahub_settings.py" and change the last line to "https://your.domain.name/seafhttp".

tmux super simple guide

echo 'set -g mouse on' >> ~/.tmux.conf
tmux new -s tmux3
^b %
^b "
^b d
tmux attach -t tmux3

How to setup pm2 to automatically start after reboot?

$ pm2 start
$ pm2 save
$ pm2 startup

You will see something like the following after you run the last command:

[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/local/lib/nodejs/node-v12.18.0-linux-x64/bin /usr/local/lib/nodejs/node-v12.18.0-linux-x64/lib/node_modules/pm2/bin/pm2 startup systemd -u shukebeta --hp /home/shukebeta

copy the sudo line & paste it on your command line then press Enter! You have done.

Using crontab to backup your mysql data

  1. on a server with huge disk space, run crontab -e and put the following code in it (you may need to change the directory names to fit your situation)

    30 3 * * * mysqldump --databases DB1 DB2 DB3 DB4 | gzip > /data/backups/mysql/db_`date '+\%Y\%m\%d-\%H\%M\%S'`.sql.gz
    30 4 * * * find /data/backups/mysql/db_* -mtime -1 -exec scp {} anotherserver:/data/backups/mysql \;
    30 5 * * * find /data/backups/mysql/db_* -mtime +30 -exec rm {} \;
    
  2. on another server, run crontab -e and put the following line into it:

    30 5 * * * find /data/backups/mysql/db_* -mtime +7 -exec rm {} \;
    

summary & explanation:

  1. at 3:30 backup MySQL data in a local directory and keep latest 30 days backup in that directory
  2. at 4:30 transfer the latest backup to another server in case the first backup may be destroyed by an accident.
  3. at 5:30 remove the oldest backup on the local backup server (the code shows that the latest 30 days backups are kept on the server).
  4. at 5:30 remove the oldest backup on the remote server (the code shows that only the latest 7 days backups are kept on that server).

Using sed to insert a line after several lines after the match line

最近一直在写 .net core,它有诸多优点我且不提,我实在头痛于手写注入服务时的模式化代码,因此动了心思要写个小脚本帮我自动化一些事情。我的想法是告诉我要加入的 ServiceName, 指定一个 Controller然后脚本自动在这个 Controller 里声明一个 private readonly 属性,自动修改类的construction 函数,自动注入这个服务,并在construction 函数体写上 _serviceName = serviceName;

在第一步,注入 private readonly 属性那里,我就绊了个跟头。用 sed 匹配到某行,在它之前,或者之后插入数据是简单的。但我匹配到 public class xxxController 这行之后是单独一行 {,而我要加的变量要放到 {这行之后。网上一通搜索,试图找到定位到某行之后N行的命令,然而并没有这样的命令。然而功夫不负有心人,我最后还是找到了一个解决方案,那就是

sed '/pattern/!b;n;n;i\something'

具体解释见 Reference