[不花钱站长]:从免费域名开始[0元] Oracle永久免费VPS[0元] VPS环境搭建免费脚本[0元] 秒变大盘挂载免费网盘[0元] 小白免费采集器1天500W[0元] CF免费DNS+CDN服务[0元]
[零基础网赚]:撸本站免费源码[0元] 网站强引免费蜘蛛法[0元] 图片视频文件免费存储[0元] 外链轻松发布免费友链[0元] 入坑免费教程学习源代码[0元] 网上百种+赚钱联盟推荐[?元]

↑↑VPS推荐网 WWW.VPS.COM.IN 稳定 便宜 免备案↑↑


您现在的位置是:首页 > 全球[VPS测评] >  建站教程,建站教程,国外永久免费VPS

#建站教程#centos系统搭建Mastodon

全球[VPS测评]来源:VPS推荐网点击:560
【性价之王】【线路之王】【价格之王】【配置之王】
【免费之王】【香港首推】【梯子之王】【独服之王】
#建站教程#centos系统搭建Mastodon

在开始之前,你应该先了解一下什么是Mastodon,它是做什么的?有什么功能?下面这篇文章写的很详细了,有兴趣的可以先看看:

https://www.douban.com/group/topic/113168501/

这里我们简而言之,你现在可以把Mastodon当作是一个“去中心化”的新浪微博或是Twitter。

现在我们来做部署前的准备工作,你应该准备好下面两样东西:

1.一台内存大于1GB的KVM架构VPS
2.一个顶级域名,并且已经解析到你的VPSIP。

首先我们使用Xshell登录到VPS内,更新系统:

yum -y update
1 yum -y update

安装EPEL源:

yum -y install epel-release
1 yum -y install epel-release

安装开发工具包:

yum -y groupinstall "Development Tools"
1 yum -y groupinstall "Development Tools"

安装项目所需依赖:

yum -y install wget curl git openssl-devel readline-devel libicu-devel libidn-devel postgresql-devel protobuf-devel libxml2-devel libxslt-devel ncurses-devel sqlite-devel gdbm-devel zlib-devel libffi-devel libyaml-devel
1 yum -y install wget curl git openssl-devel readline-devel libicu-devel libidn-devel postgresql-devel protobuf-devel libxml2-devel libxslt-devel ncurses-devel sqlite-devel gdbm-devel zlib-devel libffi-devel libyaml-devel

安装NodeJS:

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -yum -y install nodejs
12 curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -yum -y install nodejs

安装Yarn包管理器:

curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repoyum -y install yarn
12 curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repoyum -y install yarn

安装imagemagick:

yum -y install https://imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-libs-7.0.8-12.x86_64.rpmyum -y install https://imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-7.0.8-12.x86_64.rpm
12 yum -y install https://imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-libs-7.0.8-12.x86_64.rpmyum -y install https://imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-7.0.8-12.x86_64.rpm

安装Redis:

yum -y install redis
1 yum -y install redis

启动Redis并设置开机启动:

systemctl start redissystemctl enable redis
12 systemctl start redissystemctl enable redis

安装PostgreSQL数据库:

yum -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpmyum -y install postgresql10 postgresql10-server postgresql10-contrib postgresql10-devel
12 yum -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpmyum -y install postgresql10 postgresql10-server postgresql10-contrib postgresql10-devel

初始化数据:

/usr/pgsql-10/bin/postgresql-10-setup initdb
1 /usr/pgsql-10/bin/postgresql-10-setup initdb

启动PostgreSQL以及设置开机启动:

systemctl enable postgresql-10systemctl start postgresql-10
12 systemctl enable postgresql-10systemctl start postgresql-10

现在登录到数据库内:

sudo -u postgres psql
1 sudo -u postgres psql

创建数据库:

CREATE USER mastodon CREATEDB;
1 CREATE USER mastodon CREATEDB;

完成之后退出:

\q
1 \q

安装FFMPEG(可选):

cdwget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xztar -xJf ffmpeg-release-64bit-static.tar.xzcd ffmpeg-4.0.2-64bit-staticcp ffmpeg /usr/bin/ffmpegcp ffprobe /usr/bin/ffprobe
123456 cdwget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xztar -xJf ffmpeg-release-64bit-static.tar.xzcd ffmpeg-4.0.2-64bit-staticcp ffmpeg /usr/bin/ffmpegcp ffprobe /usr/bin/ffprobe

安装Nginx,先新建一个源:

vi /etc/yum.repos.d/nginx.repo
1 vi /etc/yum.repos.d/nginx.repo

写入:

[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1
12345 [nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1

然后yum安装即可:

yum -y install nginx
1 yum -y install nginx

这里先停止运行nginx:

systemctl stop nginx
1 systemctl stop nginx

设置nginx开机启动:

systemctl enable nginx
1 systemctl enable nginx

现在我们添加一个用户,命名为mastodon:

adduser mastodon
1 adduser mastodon

切换到这个用户的shell内:

su mastodon
1 su mastodon

如果需要修改这个用户的密码,你应该执行下面的命令:

passwd mastodon
1 passwd mastodon

安装rbenv:

wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O- | bash
1 wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O- | bash

上面的脚本执行完成之后,设置环境变量:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profileecho 'eval "$(rbenv init -)"' >> ~/.bash_profilesource ~/.bash_profile
123 echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profileecho 'eval "$(rbenv init -)"' >> ~/.bash_profilesource ~/.bash_profile

接着执行如下命令检查是否正常:

wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor -O- | bash
1 wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor -O- | bash

如果一切正常,那么我们现在就可以使用rbenv安装ruby了:

rbenv install 2.5.1
1 rbenv install 2.5.1

安装完成之后,设置全局使用ruby2.5.1:

rbenv global 2.5.1
1 rbenv global 2.5.1

现在拉取Mastodon项目文件并进入到项目目录:

cd ~git clone https://github.com/tootsuite/mastodon.git livecd ~/live
123 cd ~git clone https://github.com/tootsuite/mastodon.git livecd ~/live

检测最新版本:

git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
1 git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)

安装bundler和ruby依赖:

gem install bundlerbundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test
12 gem install bundlerbundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without development test

安装node.js依赖:

yarn install --pure-lockfile
1 yarn install --pure-lockfile

全部完成之后,现在我们可以开始配置mastodon了:

RAILS_ENV=production bundle exec rake mastodon:setup
在这个向导中,你应该按照如下配置来填写:

Q:Domain name:
A:填写你的域名地址,不要带wwwQ:Do you want to enable single user mode?
A:NQ:Are you using Docker to run Mastodon?
A:nQ:PostgreSQL host: /var/run/postgresql
A:回车Q:PostgreSQL port: 5432
A:回车Q:Name of PostgreSQL database: mastodon_production
A:回车Q:Name of PostgreSQL user: mastodon
A:回车Q:Password of PostgreSQL user:
A:回车Q:Redis host: localhost
A:回车Q:Redis port: 6379
A:回车Q:Redis password:
A:回车Q:Do you want to send e-mails from localhost?
A:yQ:Send a test e-mail with this configuration right now?
A:nQ:Save configuration?
A:yQ:Prepare the database now?
A:yQ:Compile the assets now?
A:yQ:Do you want to create an admin user straight away?
A:y

走完这个向导之后,你应该切换回root用户:

su root
1 su root

现在我们需要创建三个服务文件,第一个是web服务:

vi /etc/systemd/system/mastodon-web.service
1 vi /etc/systemd/system/mastodon-web.service

写入:

[Unit]Description=mastodon-webAfter=network.target[Service]Type=simpleUser=mastodonWorkingDirectory=/home/mastodon/liveEnvironment="RAILS_ENV=production"Environment="PORT=3000"ExecStart=/home/mastodon/.rbenv/shims/bundle exec puma -C config/puma.rbExecReload=/bin/kill -SIGUSR1 $MAINPIDTimeoutSec=15Restart=always[Install]WantedBy=multi-user.target
12345678910111213141516 [Unit]Description=mastodon-webAfter=network.target[Service]Type=simpleUser=mastodonWorkingDirectory=/home/mastodon/liveEnvironment="RAILS_ENV=production"Environment="PORT=3000"ExecStart=/home/mastodon/.rbenv/shims/bundle exec puma -C config/puma.rbExecReload=/bin/kill -SIGUSR1 $MAINPIDTimeoutSec=15Restart=always [Install]WantedBy=multi-user.target

第二个是后台服务:

vi /etc/systemd/system/mastodon-sidekiq.service
1 vi /etc/systemd/system/mastodon-sidekiq.service

写入:

[Unit]Description=mastodon-sidekiqAfter=network.target[Service]Type=simpleUser=mastodonWorkingDirectory=/home/mastodon/liveEnvironment="RAILS_ENV=production"Environment="DB_POOL=5"ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q push -q mailers -q pullTimeoutSec=15Restart=always[Install]WantedBy=multi-user.target
123456789101112131415 [Unit]Description=mastodon-sidekiqAfter=network.target[Service]Type=simpleUser=mastodonWorkingDirectory=/home/mastodon/liveEnvironment="RAILS_ENV=production"Environment="DB_POOL=5"ExecStart=/home/mastodon/.rbenv/shims/bundle exec sidekiq -c 5 -q default -q push -q mailers -q pullTimeoutSec=15Restart=always [Install]WantedBy=multi-user.target

第三个是流媒体API服务:

vi /etc/systemd/system/mastodon-streaming.service
1 vi /etc/systemd/system/mastodon-streaming.service

写入:

[Unit]Description=mastodon-streamingAfter=network.target[Service]Type=simpleUser=mastodonWorkingDirectory=/home/mastodon/liveEnvironment="NODE_ENV=production"Environment="PORT=4000"ExecStart=/usr/bin/npm run startTimeoutSec=15Restart=always[Install]WantedBy=multi-user.target
123456789101112131415 [Unit]Description=mastodon-streamingAfter=network.target[Service]Type=simpleUser=mastodonWorkingDirectory=/home/mastodon/liveEnvironment="NODE_ENV=production"Environment="PORT=4000"ExecStart=/usr/bin/npm run startTimeoutSec=15Restart=always [Install]WantedBy=multi-user.target

完成之后立即启动这三个服务:

systemctl start mastodon-web.servicesystemctl start mastodon-sidekiq.servicesystemctl start mastodon-streaming.service
123 systemctl start mastodon-web.servicesystemctl start mastodon-sidekiq.servicesystemctl start mastodon-streaming.service

接着设置开机启动:

systemctl enable mastodon-web.servicesystemctl enable mastodon-sidekiq.servicesystemctl enable mastodon-streaming.service
123 systemctl enable mastodon-web.servicesystemctl enable mastodon-sidekiq.servicesystemctl enable mastodon-streaming.service

现在你应该关闭系统防火墙:

systemctl stop firewalld.servicesystemctl disable firewalld.service
12 systemctl stop firewalld.servicesystemctl disable firewalld.service

接着关闭SELinux:

vi /etc/selinux/configSELINUX=disabledsetenforce 0
123 vi /etc/selinux/configSELINUX=disabledsetenforce 0

安装certbot用于自动签发Let’s Encrypt证书:

yum -y install certbot
1 yum -y install certbot

执行如下命令,给你的域名签发证书(example.com替换成你的域名):

certbot certonly --standalone -d example.com
1 certbot certonly --standalone -d example.com

证书如果签发成功,那么证书的存储路径应该是:

/etc/letsencrypt/live/example.com/fullchain.pem/etc/letsencrypt/live/example.com/privkey.pem
12 /etc/letsencrypt/live/example.com/fullchain.pem/etc/letsencrypt/live/example.com/privkey.pem

现在你应该配置certbot自动续约证书:

crontab -e
1 crontab -e

写入:

0 0 * * * /usr/bin/certbot renew --quiet
1 0 0 * * * /usr/bin/certbot renew --quiet

这样配置好了后,certbot会在每天的0点检查证书是否过期,如果过期就自动续约证书。

现在我们编辑Nginx的主配置文件:

vi /etc/nginx/nginx.conf
1 vi /etc/nginx/nginx.conf

在这个配置文件的第一行,将nginx的运行用户修改成mastodon:

user mastodon;
1 user  mastodon;

接着我们新建一个Nginx站点配置文件:

vi /etc/nginx/conf.d/example.com.conf

写入:

map $http_upgrade $connection_upgrade { default upgrade; '' close;}server { listen 80; listen [::]:80; server_name example.com; root /home/mastodon/live/public; return 301 https://$host$request_uri;}server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name example.com; ssl_protocols TLSv1.2; ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA; ssl_per_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; keepalive_timeout 70; sendfile on; client_max_body_size 80m; root /home/mastodon/live/public; gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; add_header Strict-Transport-Security "max-age=31536000"; location / { try_files $uri @proxy; } location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) { add_header Cache-Control "public, max-age=31536000, immutable"; try_files $uri @proxy; } location /sw.js { add_header Cache-Control "public, max-age=0"; try_files $uri @proxy; } location @proxy { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Proxy ""; proxy_pass_header Server; proxy_pass http://127.0.0.1:3000; proxy_buffering off; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; tcp_nodelay on; } location /api/v1/streaming { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Proxy ""; proxy_pass http://127.0.0.1:4000; proxy_buffering off; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; tcp_nodelay on; } error_page 500 501 502 503 504 /500.html;}
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 map $http_upgrade $connection_upgrade {  default upgrade;  ''      close;} server {  listen 80;  listen [::]:80;  server_name example.com;  root /home/mastodon/live/public;  return 301 https://$host$request_uri;} server {  listen 443 ssl http2;  listen [::]:443 ssl http2;  server_name example.com;   ssl_protocols TLSv1.2;  ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;  ssl_per_server_ciphers on;  ssl_session_cache shared:SSL:10m;   ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;   keepalive_timeout    70;  sendfile             on;  client_max_body_size 80m;   root /home/mastodon/live/public;   gzip on;  gzip_disable "msie6";  gzip_vary on;  gzip_proxied any;  gzip_comp_level 6;  gzip_buffers 16 8k;  gzip_http_version 1.1;  gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;   add_header Strict-Transport-Security "max-age=31536000";   location / {    try_files $uri @proxy;  }   location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) {    add_header Cache-Control "public, max-age=31536000, immutable";    try_files $uri @proxy;  }    location /sw.js {    add_header Cache-Control "public, max-age=0";    try_files $uri @proxy;  }   location @proxy {    proxy_set_header Host $host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    proxy_set_header X-Forwarded-Proto https;    proxy_set_header Proxy "";    proxy_pass_header Server;     proxy_pass http://127.0.0.1:3000;    proxy_buffering off;    proxy_redirect off;    proxy_http_version 1.1;    proxy_set_header Upgrade $http_upgrade;    proxy_set_header Connection $connection_upgrade;     tcp_nodelay on;  }   location /api/v1/streaming {    proxy_set_header Host $host;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    proxy_set_header X-Forwarded-Proto https;    proxy_set_header Proxy "";     proxy_pass http://127.0.0.1:4000;    proxy_buffering off;    proxy_redirect off;    proxy_http_version 1.1;    proxy_set_header Upgrade $http_upgrade;    proxy_set_header Connection $connection_upgrade;     tcp_nodelay on;  }   error_page 500 501 502 503 504 /500.html;}

最后启动Nginx:

systemctl start nginx
1 systemctl start nginx

大功告成,不出意外的话,现在打开你的站点域名,你应该可以看到一个Mastodon实例了,随便试用了下,很不错:


申明:原文来至荒岛(https://lala.im/4286.html)


[建站教程]历史优惠活动内容
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • 香港虚拟主机建站教程 云服务器建站教程
  • SiteGround建站教程→使用Site Tools一键安装WordPress博客
  • SiteGround建站教程→使用Site Tools一键安装WordPress博客
  • SiteGround建站教程→使用Site Tools一键安装WordPress博客
  • SiteGround建站教程→使用Site Tools一键安装WordPress博客
  • SiteGround建站教程→使用Site Tools一键安装WordPress博客
  • SiteGround建站教程→使用Site Tools一键安装WordPress博客
  • 新手站建之-wordpress建站教程
  • 新手站建之-飞飞影视建站教程
  • 建站教程 centos系统搭建Mastodon
  • Windows VPS/服务器安装宝塔面板建站教程 – 宝塔面板安装
  • UCloud优刻得云服务器建站教程1 – 云服务器购买和优惠券领取使用
  • UCloud云服务器建站教程2 – UCloud服务器后台管理及安全组设置
  • UCloud云服务器建站教程3 – UCloud安装宝塔面板/LNMP一键包WEB环境
  • LEMP(Linux/Nginx/MySQL/PHP)一键包安装及SFTP快速建站教程
  • 腾讯云服务器建站教程 – 重装系统/更换IP地址/重置密码
  • 腾讯云服务器建站教程 – 安全组规则创建和授权云服务器实例
  • 腾讯云服务器建站教程 – 定时快照备份和镜像备份的功能策略
  • Windows VPS/服务器建站教程进阶系列 – Windows2012安装IIS7图文
  • Windows VPS/服务器建站教程进阶系列 – BT宝塔软件部署Web环境体验
  • Windows VPS/服务器建站教程进阶系列 – 一键phpStudy软件环境安装
  • Windows VPS/服务器建站教程进阶系列 – 绑定域名安装WordPress
  • Windows VPS/服务器建站教程进阶系列 – Windows2012安装IIS7图文
  • Windows VPS/服务器建站教程进阶系列 – BT宝塔软件部署Web环境体验
  • Windows VPS/服务器建站教程进阶系列 – 一键phpStudy软件环境安装
  • Windows VPS/服务器建站教程进阶系列 – 绑定域名安装WordPress
  • #建站教程#centos系统搭建Mastodon
  • 新手站建之-wordpress建站教程
  • 新手站建之-Discuz论坛建站教程
  • 新手站建之-PHPwind论坛建站教程
  • 新手站建之-织梦DedeCMS建站教程
  • 新手站建之-飞飞影视建站教程
  • 新手站建之-Freekan电影站建站教程
  • #建站教程#centos系统搭建Mastodon
  • 新手站建之-wordpress建站教程
  • 新手站建之-Discuz论坛建站教程
  • 新手站建之-PHPwind论坛建站教程
  • 新手站建之-织梦DedeCMS建站教程
  • 新手站建之-飞飞影视建站教程
  • 新手站建之-Freekan电影站建站教程
  • #建站教程#centos系统搭建Mastodon
  • 新手站建之-wordpress建站教程
  • 新手站建之-Discuz论坛建站教程
  • 新手站建之-PHPwind论坛建站教程
  • 新手站建之-织梦DedeCMS建站教程
  • 新手站建之-飞飞影视建站教程
  • 新手站建之-Freekan电影站建站教程
  • #建站教程#centos系统搭建Mastodon

  • 猜你可能想看的VPS


    转载请注明原文地址:http://140.238.13.167:12355/read-28446.html

    下一篇       上一篇