惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
V
V2EX
爱范儿
爱范儿
Last Week in AI
Last Week in AI
美团技术团队
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
Security Latest
Security Latest
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
I
Intezer
K
Kaspersky official blog
阮一峰的网络日志
阮一峰的网络日志
大猫的无限游戏
大猫的无限游戏
T
Tenable Blog
AWS News Blog
AWS News Blog
小众软件
小众软件
博客园 - 司徒正美
Cyberwarzone
Cyberwarzone
NISL@THU
NISL@THU
博客园 - 三生石上(FineUI控件)
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
量子位
有赞技术团队
有赞技术团队
S
Schneier on Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Secure Thoughts
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
L
Lohrmann on Cybersecurity
P
Palo Alto Networks Blog
P
Privacy International News Feed
L
LINUX DO - 最新话题
博客园 - Franky
雷峰网
雷峰网
月光博客
月光博客
Hacker News: Ask HN
Hacker News: Ask HN
Forbes - Security
Forbes - Security
博客园 - 【当耐特】
C
Cyber Attacks, Cyber Crime and Cyber Security

Feed of liolok

Fix Broken URLs of My Site Containerize Steam with systemd-nspawn Containerize Android Studio with systemd-nspawn Run Desktop App with systemd-nspawn Container Oculus Quest 2 Usage Note Set Environment Variables with pam_env Install Arch Linux on Acer Swift 3 SF313-52 V2Ray Subscription Parse Manage Dotfiles with Git and Stow Run SS and MTProxy Server on AWS How to Add Image to Hexo Blog Post Build Blog with Hexo and GitHub Pages
Run Mastodon Server on Arch Linux VPS
2019-12-08 · via Feed of liolok

cd ~{,/zhs/}

I’m using Docker to run Mastodon now, this article is reserved only for reference.

Mastodon?

Short story: open-source self-hosted Twitter. So why not Twitter? Well Mastodon should be more private and under my own control.

VPS Requirement

I’m using one-year free trial of AWS, there are Arch Linux AMIs according to ArchWiki, which people can directly launch EC2 instances.

Basically a VPS that one can install Arch Linux on it is enough; Hardware resource requirement depends on user amount, in my case, a free trial VPS should be enough.

Add DNS Record

Go to my DNS service website then add an A record with public IP of VPS to my domain.

Add Swap Space

Swap - ArchWiki

My VPS has only 1G memory, so a swapfile is considered necessery.

# pacman --sync systemd-swap
# sed --in-place 's/swapfc_enabled=0/swapfc_enabled=1/' /etc/systemd/swap.conf
# systemctl enable systemd-swap
# reboot

Install Packages Needed

# pacman --sync nano sudo tmux yay nginx certbot-nginx

I don’t know how to use vi so nano is needed.

For package yay, one can install it after adding Arch Linux CN repository.

Create a Privileged User

An AUR package is not allowed to install with root user, so I have to run useradd -m -G wheel liolok && passwd liolok to create a user of administration group, then run nano /etc/sudoers and uncomment the line %wheel ALL=(ALL) ALL.

Install AUR Package

# su - liolok
$ tmux
$ yay --sync mastodon

Nodejs stuff will take quite a long time even without output. After installation, press Ctrl + D twice to return to root user.

PostgreSQL and Redis

# systemctl enable --now postgresql redis

I ran into a trouble that the service of PostgreSQL failed to start, so look into it:

 root   systemctl status postgresql                                                                                                                                                    1 
 postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Sun 2019-12-08 16:37:37 UTC; 20s ago
    Process: 150840 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=1/FAILURE)

Dec 08 16:37:37 ip-172-31-21-37 systemd[1]: Starting PostgreSQL database server...
Dec 08 16:37:37 ip-172-31-21-37 postgres[150840]: "/var/lib/postgres/data" is missing or empty. Use a command like
Dec 08 16:37:37 ip-172-31-21-37 postgres[150840]:   su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"
Dec 08 16:37:37 ip-172-31-21-37 postgres[150840]: with relevant options, to initialize the database cluster.
Dec 08 16:37:37 ip-172-31-21-37 systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
Dec 08 16:37:37 ip-172-31-21-37 systemd[1]: postgresql.service: Failed with result 'exit-code'.
Dec 08 16:37:37 ip-172-31-21-37 systemd[1]: Failed to start PostgreSQL database server.

It seems not a big deal, just follow the instruction to initialize the database cluster and then start service.

# su - postgres --command "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"
# systemctl start postgres

Then create the Mastodon PostgreSQL user and grant it the ability to create databases:

# su - postgres --shell /bin/sh --command "createuser -d mastodon"

Nginx

Copy Mastodon’s default nginx configuration:

# cd /etc/nginx/
# mkdir sites-available sites-enabled
# cp --verbose /var/lib/mastodon/dist/nginx.conf sites-available/mastodon
# ln --symbolic --verbose sites-available/mastodon sites-enabled/mastodon

Replace example.com with my own domain, fix mastodon path:

# sed --in-place=".default" /etc/nginx/sites-available/mastodon \
--expression 's/example\.com/zone\.liolok\.com/' \
--expression 's/home\/mastodon\/live/var\/lib\/mastodon/'

Generate certificate:

# certbot --nginx --domains zone.liolok.com

This command reports that certificate and chain are saved, but haven’t been installed to nginx configuration.

It’s ok, do the next steps:

  • edit /etc/nginx/nginx.conf and add line include /etc/nginx/sites-enabled/*; to the end of http block;
  • edit /etc/nginx/sites-enabled/mastodon and uncomment the ssl_certificate and ssl_certificate_key lines.

Then run systemctl enable --now nginx.

Final Setup

# tmux
# su - mastodon --shell /bin/sh --command "cd '/var/lib/mastodon'; RAILS_ENV=production bundle exec rails mastodon:setup"

In this step, there will be a command line interface that seems kind of user friendly.

First content to input is my own domain zone.liolok.com; then comes stuff about postgresql and redis, leave them default; then comes E-mail part: this confused me for a lot of time, at last I used my previous configured Yandex domain mail:

Then the database and pre-compile work, latter would take longer. Finally I config the admin account information, and get the default password generated.

Up to now, everything is ready. Start the mastodon services, and the website becomes available.

# systemctl enable --now mastodon.target