Követelmények
Mielőtt elkezded
Telepítse a Certbotot
Telepítse a Node.js-t és az NPM-et
Telepítse a MySQL-t
Telepítse az NGINX-et
Telepítse a Ghost-ot
A Ghost futtatása rendszerszolgáltatásként
Következtetés
A Ghost egy nyílt forráskódú blogplatform, amely 2013-as megjelenése óta egyre népszerűbb a fejlesztők és a hétköznapi felhasználók körében. A tartalomra és a blogírásra helyezi a hangsúlyt. A Ghost legvonzóbb tulajdonsága az egyszerű, letisztult és érzékeny kialakítás. Blogbejegyzéseit mobiltelefonról is írhatja. A Ghost tartalma a Markdown nyelven íródott. A Ghost tökéletesen illeszkedik egyénekhez vagy kisebb írócsoportokhoz.
Ebben az útmutatóban egy biztonságos Ghost v0.11.x LTS blogot állítunk be és telepítünk CentOS 7.3 VPS-en a Let's Encrypt , Certbot , Node.js , NPM , NGINX és MySQL használatával .
Követelmények
- Regisztráljon (vásároljon) egy domain nevet.
- CentOS 7.3 szerverpéldány legalább 1 GB RAM-mal .
- Sudo felhasználó.
Mielőtt elkezded
Ellenőrizze a CentOS verzióját:
cat /etc/centos-release
# CentOS Linux release 7.3.1611 (Core)
Hozzon létre egy új, nem root felhasználót:
useradd -c "John Doe" johndoe && passwd johndoe
Tedd szuperfelhasználóvá, ha hozzáadod a wheelcsoporthoz:
usermod -aG wheel johndoe
Váltás új felhasználóra:
su - johndoe
Frissítse operációs rendszere szoftverét:
sudo yum check-update || sudo yum update -y
Állítsa be az időzónát:
timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'
Fejlesztőeszközök telepítése:
sudo yum groupinstall -y 'Development Tools'
Telepítse a Vim szövegszerkesztőt:
sudo yum install -y vim
Szükség esetén indítsa újra a rendszert:
sudo shutdown -r now
Telepítse a Certbotot
NOTE: Before starting this step, ensure that you have set DNS records for your domain.
A Let's Encrypt CA és az EFF Certbot kliensét fogjuk használni , hogy SSL/TLS tanúsítványt szerezzünk Ghost blogunkhoz . Ne felejtse el a(z) összes példányát lecserélni blog.domain.tlda domain nevére.
Engedélyezze az Extra Packages for Enterprise Linux (EPEL) adattárat:
# Certbot is packaged in Extra Packages for Enterprise Linux (EPEL) repository. To use Certbot, you must first enable the EPEL repository.
sudo yum install -y epel-release
Telepítse a Certbot (korábban Let's Encrypt kliens ) tanúsítványkezelő szoftverét, amely Pythonnal készült:
sudo yum install -y certbot
Ellenőrizze a Certbot verzióját:
certbot --version
# certbot 0.14.1
Szerezzen be RSA- tanúsítványt önálló hitelesítési módszerrel (bővítmény):
sudo certbot certonly --standalone --domains blog.domain.tld --rsa-key-size 2048 --must-staple --email admin@domain.tld --no-eff-email --agree-tos
# IMPORTANT NOTES:
# - Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/blog.domain.tld/fullchain.pem.
# Your cert will expire on YYYY-MM-DD. . . .
# . . .
Az előző lépések elvégzése után a tanúsítvány és a privát kulcs a /etc/letsencrypt/live/blog.domain.tldkönyvtárban lesz.
Telepítse a Node.js-t és az NPM-et
NOTE: Ghost currently supports Node.js versions 4.5+ and 6.9+ only.
A Ghost a Node.js-re épül. Telepíteni fogjuk a Ghost ajánlott verzióját, amely v6 Boron LTSaz írás idején van.
Töltse le és telepítse a Node.js v6 LTS-t:
sudo curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
sudo yum install -y nodejs
Ellenőrizze a Node.js és az NPM verzióját:
node -v && npm -v
# v6.11.2
# 3.10.10
Telepítse a MySQL-t
Alapértelmezés szerint a Ghost SQLite adatbázis használatára van beállítva, amely nem igényel konfigurációt.
Alternatív megoldásként a Ghost MySQL adatbázissal is használható az adatbázis konfigurációjának megváltoztatásával. Először létre kell hoznia egy adatbázist és egy felhasználót, majd módosíthatja a meglévő sqlite3 konfigurációt.
Töltse le és telepítse a MySQL legújabb verzióját (jelenleg 5.7 ) a hivatalos MySQL Yum tárolóból:
cd /tmp
# Adding the MySQL Yum Repository
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
sudo yum localinstall -y mysql57-community-release-el7-11.noarch.rpm
# Installing MySQL
sudo yum install -y mysql-community-server
Ellenőrizze a MySQL verzióját:
mysql --version
# mysql Ver 14.14 Distrib 5.7.19, for Linux (x86_64) using EditLine wrapper
Indítsa el a MySQL Servert, és ellenőrizze az állapotát:
sudo systemctl start mysqld.service
sudo systemctl status mysqld.service
A MySQL 5.7-es vagy újabb verziója ideiglenes véletlenszerű jelszót generál a MySQL- rootfelhasználó számára a telepítés után, és a jelszót a rendszer a MySQL hibanaplófájlban tárolja, amely a címen található /var/log/mysqld.log. Felfedéséhez használja a következő parancsot:
sudo grep 'temporary password' /var/log/mysqld.log
Futtassa a mysql_secure_installationszkriptet, hogy egy kicsit biztonságossá tegye az adatbázist:
NOTE: Password Validation Plugin is installed and enabled, so your new password for root user needs to be strong (one upper case letter, one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters). If you want to relax that or disable plugin completely (not recommended) consult the official MySQL documentation for how to do that.
sudo mysql_secure_installation
Jelentkezzen be a MySQL-be root felhasználóként:
mysql -u root -p
# Enter password:
Hozzon létre egy új MySQL adatbázist és felhasználót:
create database dbname;
grant all on dbname.* to 'user' identified by 'password';
Kilépés a MySQL-ből:
exit
Telepítse az NGINX-et
Download and install the latest mainline version of NGINX from the official NGINX repository:
# Add the NGINX Yum Repository
sudo vim /etc/yum.repos.d/nginx_mainline.repo
# Copy/paste the following into /etc/yum.repos.d/nginx_mainline.repo
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=1
enabled=1
wget https://nginx.org/keys/nginx_signing.key
sudo rpm --import nginx_signing.key
rm nginx_signing.key
sudo yum install -y nginx nginx-module-geoip nginx-module-image-filter nginx-module-njs nginx-module-perl nginx-module-xslt nginx-nr-agent
Verify that it is installed by checking the NGINX version:
sudo nginx -v
# nginx version: nginx/1.13.3
Check status, enable and start NGINX service (daemon):
sudo systemctl status nginx.service # inactive (dead)
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
Create /etc/nginx/ssl directory and generate a new Diffie-Hellman (DH) parameters:
sudo mkdir -p /etc/nginx/ssl
sudo openssl dhparam -out /etc/nginx/ssl/dhparams-2048.pem 2048
Create log directory for blog.domain.tld virtual host:
sudo mkdir -p /var/log/nginx/blog.domain.tld
Configure NGINX as a HTTP(S) reverse proxy server:
sudo vim /etc/nginx/conf.d/ghost.conf
Paste the following in /etc/nginx/conf.d/ghost.conf:
# domain: blog.domain.tld
# public: /var/www/ghost
upstream ghost_app {
server 127.0.0.1:2368;
keepalive 32;
}
server {
listen [::]:80 default_server;
listen 80 default_server;
listen [::]:443 ssl http2 default_server;
listen 443 ssl http2 default_server;
server_name blog.domain.tld;
root /var/www/ghost;
error_log /var/log/nginx/blog.domain.tld/error.log;
access_log /var/log/nginx/blog.domain.tld/access.log;
client_max_body_size 100M;
ssl_certificate /etc/letsencrypt/live/blog.domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.domain.tld/privkey.pem;
ssl_dhparam ssl/dhparams-2048.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
ssl_prefer_server_ciphers on;
ssl_buffer_size 4K;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50M;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/blog.domain.tld/chain.pem;
resolver 8.8.8.8 8.8.4.4 valid=300s;
location / {
proxy_pass http://ghost_app;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_hide_header X-Powered-By;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
Save and test NGINX configuration for syntax errors:
sudo nginx -t
Reload NGINX configuration:
sudo systemctl reload nginx.service
Install Ghost
NOTE: If you want to host multiple Ghost blogs on same VPS, each Ghost instance must be running on a separate port.
Create document root directory:
sudo mkdir -p /var/www/
Create a new ghost user:
sudo useradd -c 'Ghost application' ghost
Download Ghost:
curl -L https://github.com/TryGhost/Ghost/releases/download/0.11.11/Ghost-0.11.11.zip -o ghost.zip
Unzip Ghost into the /var/www/ghost directory (recommended install location):
sudo unzip -uo ghost.zip -d /var/www/ghost
rm ghost.zip
Move to the new ghost directory:
cd /var/www/ghost
A /var/www/ghostcímtár tulajdonjogának módosítása :
sudo chown -R ghost:ghost .
Váltás új ghostfelhasználóra:
sudo su - ghost
Navigáljon a dokumentum gyökeréhez /var/www/ghost:
cd /var/www/ghost
Telepítse a Ghost-ot csak termelési függőségekkel. Amikor ez befejeződött, a Ghost telepítve lesz:
npm install --production
Konfigurálása Ghost megváltoztatásával url, mailés databasetulajdon gyártási objektum belsejében config.jsfile:
cp config.example.js config.js
vim /var/www/ghost/config.js
var path = require('path'),
config;
config = {
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'https://blog.domain.tld',
mail: {
transport: 'SMTP',
options: {
service: 'Mailgun',
auth: {
user: '',
pass: ''
}
}
},
database: {
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'your_database_user',
password: 'your_database_password',
database: 'your_database_name',
charset: 'utf8'
},
debug: false
},
// . . .
// . . .
NOTE: You should configure mail settings also. Consult the official Ghost documentation on how to do that.
Indítsa el a Ghost-ot éles környezetben:
npm start --production
A Ghost most futni fog. Mind a blog front-end, mind az adminisztrációs felület HTTPS-sel védett, és a HTTP/2 is működik. Megnyithatja böngészőjét, és felkeresheti a webhelyet a címen https://blog.domain.tld. Ne felejtse el lecserélni blog.domain.tlda domain nevét.
Zárja le a Ghost folyamatot a CTRL+ megnyomásával, Cés lépjen vissza a ghost felhasználóról a nem root felhasználóra, amelyet az elején létrehozott:
exit
A Ghost futtatása rendszerszolgáltatásként
Ha bezárja a terminál-munkamenetet a VPS-szel, a blogod is megszűnik. Ez nem jó. Ennek elkerülése érdekében a systemd-t fogjuk használni. Ez a nap 24 órájában fenn fogja tartani a blogunkat.
Hozzon létre ghost.servicesystemd unit fájlt. Futtassa a sudo-t, sudo vim /etc/systemd/system/ghost.serviceés másolja/illessze be az alábbi tartalmat:
[Unit]
Description=Ghost - the professional publishing platform
Documentation=https://docs.ghost.org/v0.11.11/docs
After=network.target
[Service]
Type=simple
# Edit WorkingDirectory, User and Group as needed
WorkingDirectory=/var/www/ghost
User=ghost
Group=ghost
ExecStart=/bin/npm start --production
ExecStop=/bin/npm stop --production
Restart=always
SyslogIdentifier=Ghost
[Install]
WantedBy=multi-user.target
Engedélyezze és indítsa el ghost.service:
sudo systemctl enable ghost.service && sudo systemctl start ghost.service
Állapot ellenőrzése ghost.service:
sudo systemctl status ghost.service && sudo systemctl is-enabled ghost.service
Keresse meg https://blog.domain.tld/ghost/és hozzon létre egy Ghost adminisztrátori felhasználót. Tedd meg ezt mielőbb!
Következtetés
Ez az. Most már van egy teljesen működőképes Ghost blogunk. A szerver HTTP/2-n keresztül szállít tartalmat, ha az ügyfél támogatja. Ha meg szeretné változtatni az alapértelmezett Casper nevű Ghost témát egy egyénire , egyszerűen töltse le és csomagolja ki a témát a /var/www/ghost/content/themesmappába, és válassza ki a Ghost adminisztrációs felületén, amely a címen található https://blog.domain.tld/ghost.