百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

VPS主机搭建Ghost环境:Nginx Node.js MariaDB

nanshan 2025-03-30 19:21 12 浏览 0 评论

Ghost是一款个人博客系统,它是使用Node.js语言和MySQL数据库开发的,同时支持MySQL、MariaDB、SQLite和PostgreSQL。用户可以在支持Node.js的服务器上使用自己的博客。它是由两位WordPress前工程师开发,特点就是轻 快 高效,并原生支持Markdown语法。

在WordPress变得越来越强大,同时又越来越臃肿的今天,Ghost的出现,无疑为博客系统界带来一股清风。 虽然如此,Ghost目前的使用者还局限于有一定代码基础的Geek,工程师们,它并不完善。如果您想尝试一下Ghost博客的轻便快速,不妨跟随本文来进行一番尝试。

本文使用的环境如下: CentOS 6.6 x86_64纯净系统 。搭建目标如下:

1.nginx 1.9.2 编译SPDY模块 ;

2.node.js v0.12.4 ;

3.MariaDB 10.1.5(YUM快速安装) ;

4.安装并配置Ghost 0.6.3程序 。

更多的有关于博客系统搭建的信息可查看:静态博客程序使用入门

一、编译安装Nginx 1.9.2

1.首先我们去官方网站下载最新的nginx源码:

 cd /usr/local/src wget http://nginx.org/download/nginx-1.9.2.tar.gz

2.解压nginx源码:

tar xzvf nginx-1.9.2.tar.gz cd nginx-1.9.2

3.编译openssl(为https准备,不需要请跳过该步骤)

yum update -y && yum install -y ncurses-devel make gcc bc cd /usr/local/src wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz tar zxvf openssl-1.0.1h.tar.gz cd openssl-1.0.1h ./config make

4.建立makefile(此处加入了https(--with-httpsslmodule)与spdy(--with-httpspdymodule)模块,若不需要请去掉)

#安装依赖环境 yum update -y && yum install pcre-devel zlib-devel #编译nginx ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_spdy_module --with-openssl=/usr/local/src/openssl-1.0.1h useradd www -g www make make install 

5.添加nginx管理脚本,设置开机启动

#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs { # make required directories user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fi options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart { configtest || return $? stop sleep 1 start } reload { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload { restart } configtest { $nginx -t -c $NGINX_CONF_FILE } rh_status { status $prog } rh_status_q { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac 

6、使用以上代码时,请注意代码的中英文字符在复制过程中是不是有变化。执行:vim /etc/init.d/nginx 。按I编辑,贴入上方脚本。按Esc,然后按:键,输入wq,回车保存。接着执行以下代码:

chkconfig --add /etc/init.d/nginx service nginx start chkconfig --level 2345 nginx on 

6.nginx有关路径:nginx:/usr/local/nginx ,
nginx.conf:/usr/local/nginx/conf/nginx.conf

二、yum快速安装MariaDB 10.1.5

1.添加MariaDB源:

cd /etc/yum.repos.d vim MariaDB.repo #输入如下内容 [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1.5/centos6-amd64/ gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 #保存退出

2.安装启动MariaDB

yum install MariaDB-server MariaDB-client MariaDB-devel service mysql start 

3.更改MariaDB root密码:/usr/bin/mysqladmin -u root password '你的密码'

4.设置MariaDB字符集:

cd /etc/my.cnf.d vim server.cnf #在[mysqld]段下加入 character-set-server=utf8 #在[server]段上方输入 [client] default-character-set=utf8 #保存退出 service mysql restart 

5.编辑完后如下图:

5.建立ghost数据库

mysql -uroot -p你的密码 #MariaDB>表示在mysql客户端中输入 MariaDB>CREATE DATABASE ghost; MariaDB>quit 

6.MariaDB配置文件路径:my.cnf:/etc/my.cnf ,my.cnf引用:/etc/my.cnf.d

三、安装node.js v0.12.4

1.下载node.js二进制源码包(这个是编译好的程序,可直接使用,只要设置环境变量即可)

cd /usr/local wget http://nodejs.org/dist/v0.12.4/node-v0.12.4-linux-x64.tar.gz tar xzvf node-v0.12.4-linux-x64.tar.gz cd node-v0.12.4-linux-x64 

2.设置环境变量:

vim /etc/profile #在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL上方加入 export NODE_HOME=/usr/local/node-v0.12.4-linux-x64 export PATH=$NODE_HOME/bin:$PATH #保存退出 source /etc/profile node -v #查看node.js版本 

3.附图:编辑后的/etc/profile

注:相关网站建设技巧阅读请移步到建站教程频道。

四、安装运行Ghost中文

1.Ghost中文网:

官网首页:
http://www.ghostchina.com/

2.执行以下命令开始下载Ghost中文并解压

mkdir -p /home/wwwroot/ghost chown -R www:www /home/wwwroot/ghost cd /home/wwwroot/ghost wget http://dl.ghostchina.com/Ghost-0.6.3-zh-full.zip yum install -y unzip unzip Ghost-0.6.3-zh-full.zip 

2.修改Ghost配置:执行cp config.example.js config.js 和 vim config.js 。需修改部位如下:

production: { url: 'http://my-ghost-blog.com', mail: {}, database: { client: 'sqlite3', connection: { filename: path.join(__dirname, '/content/data/ghost.db') }, debug: false }, // 配置MySQL 数据库 /*database: { client: 'mysql', connection: { host : 'host', user : 'user', password : 'password', database : 'database', charset : 'utf8' }, debug: false },*/

(1).将url: 'http://my-ghost-blog.com' 改为url: 'http://你自己的域名'

(2)删去

database: { client: 'sqlite3', connection: { filename: path.join(__dirname, '/content/data/ghost.db') }, debug: false },

(3)取消:(注:前后的/* */注释符号,并分别改为你自己的信息(用户root即可) )

database: { client: 'mysql', connection: { host : 'host', user : 'user', password : 'password', database : 'database', charset : 'utf8' }, debug: false },

(4)修改如下内容:(将127.0.0.1改为0.0.0.0)

server: { // Host to be passed to node's `net.Server#listen` host: '127.0.0.1', // Port to be passed to node's `net.Server#listen`, for iisnode set this to `process.env.PORT` port: '2368' },

(5)保存退出。附图:修改后的config.js文件

3.运行Ghost。执行以下命令,运行Ghost:

cd /home/wwwroot/ghost #切换至Ghost根目录,以后所有跟Ghost进程有关操作皆应在根目录下进行 npm start --production 

4、若config.js无误,输出类似如下:

5、若config.js设置失误,则会输出栈跟踪: 红色输出标示错误原因

6、forever守护ghost进程 。我们如果按下Ctrl+C,或者关闭SSH连接,Ghost博客就会被关闭,那么,如何让它长期运行?我们使用forever来实现。

7、输出如下

npm install forever -g #切换至Ghost根目录并运行 NODE_ENV=production forever start index.js 

8、停止Ghost可以:切换至Ghost根目录并运行forever stop index.js

9、输出如下:

10、查看Ghost进程:切换至Ghost根目录并运行forever list

五、为Ghost设置虚拟主机

1.编辑nginx.conf文件:

vim /usr/local/nginx/conf/nginx.conf #按G移动到文件末尾,在最后一个}前键入 include vhost/*.conf; 

2.编辑完后像这样:

3.建立虚拟主机配置文件:mkdir vhost && cd vhost 和 vim 你的域名.conf ,并写入如下配置:

server { listen 80; server_name 你的域名(不用带http://); root /home/wwwroot/ghost; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:2368; } }

4.重启nginx:service nginx restart

至此,在VPS上,我们已经成功搭建出了Nginx+Node.js+MariaDB环境,并运行了自己的ghost博客,您可以在做好DNS记录后,访问您的域名,就可以开始您的ghost之旅了。

文章出自sxbk.pw博主, Ghost建站过程中有任何问题可咨询博主。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。

相关推荐

ssh终端xshell日志查看命令(xshell怎么看日志)

现在我们云服务器运维较多用的是SSH工具,其中常用的包括PUTTY、XSHELL等,其实大同小异界面UI稍微不同,但是都可以进入远程连接。这里有朋友提到如何查看服务器的日志文件,这个其实和是否使用XS...

使用 Fail Ban 日志分析 SSH 攻击行为

通过分析`fail2ban`日志可以识别和应对SSH暴力破解等攻击行为。以下是详细的操作流程和关键分析方法:---###**一、Fail2ban日志位置**Fail2ban的日志路径因系统配置...

如何高效读取Linux日志文件?这些命令要熟记于心!

在Linux系统中,日志文件通常存储在/var/log目录下。比如,/var/log/syslog(或/var/log/messages,视发行版而定)记录系统整体事件,/var/log/a...

Windows服务器远程登录日志查询方法,linux查看登录日志方法

概述本文介绍Windows、Linux服务器查询系统的远程登录日志方法。根据服务器所使用的操作系统不同,有以下两种查询方法。Linux操作系统的登录日志查询通过远程连接登录Linux服务器,使用roo...

iptables防火墙如何记录日志(防火墙日志查看)

例如:记录所有ssh服务的登录的日志首先,我们需要了解如何将所有的iptables的INPUT链数据包记录到/var/log/messages中。如果你已经有一些iptables规则了,那么将记录日志...

如何安全管理SSH密钥以防止服务器被入侵

SSH密钥安全管理实施指南(2025年更新版)一、密钥生成与存储规范高强度密钥生成bashCopyCodessh-keygen-ted25519-a100#生成ED25519算法密钥(比...

在CentOS上安装nginx服务器(centos搭建代理服务器)

一、环境描述1.虚拟机配置CPU:单核内存:2GB硬盘:120GBIP:10.24.17.1082.操作系统版本:CentOS6.6x86_64安装方式:Minimal3.虚拟化环境VM...

CentOS7安全加固的一份整理规划建议

◆更新系统:及时更新CentOS7操作系统版本和安全补丁,确保系统以最新状态运行。◆关闭不必要的服务:在运行系统时,应关闭不需要的服务和端口,以减少系统暴露的攻击面。◆安装防火墙:使用iptables...

第四十七天-二叉树,centOS安装tomcat,Maven,vsftpd

学习笔记:1.Maven是Apache下的一个纯Java开发的开源项目。基于项目对象模型(缩写:POM)概念,Maven利用一个中央信息片断能管理一个项目的构建、报告和文档等步骤。Maven...

Linux远程桌面连接使用教程 Widows终端远程连接Linux服务器

一、前言为什么不是远程连接Linux服务器?因为我不会,远程连接window我就用电脑自带的“远程桌面连接”。以下所述都是在CentOS操作系统下的。服务器刚换成Linux的时候很迷茫,感觉无从下手...

CentOS 安全加固操作,保护你的操作系统

系统加固是保障系统安全的重要手段,对于维护企业数据安全、用户隐私以及系统稳定运行具有重要意义。加固后的系统更加健壮和稳定,能够有效减少因安全问题导致的系统故障和停机时间,提高系统的可用性和可靠性。通过...

Dockerfile部署Java项目(docker如何部署java项目)

1、概述本文主要会简单介绍什么是Docker,什么是Dockerfile,如何安装Docker,Dockerfile如何编写,如何通过Dockerfile安装jar包并外置yaml文件以及如何通过do...

CentOS7云主机部署Fail2ban阻断SSH暴力破解

关于Fail2banFail2ban可以监视你的系统日志,然后匹配日志的错误信息(正则式匹配)执行相应的屏蔽动作(一般情况下是调用防火墙屏蔽)例如:当有人在试探你的HTTP、SSH、SMTP、FTP密...

在CentOS7上用源码编译安装PostgreSQL

1、新建postgres用户#useraddpostgres&&passwdpostgres2、安装依赖包#yum-yinstallmakegccgcc-c++readline...

pure-ftpd 使用(ftp prompt命令)

pure-ftpd是一个免费的ftp软件,其他介绍就不多说了。我们直接开始主题安装centosyuminstallepel-releaseyuminstallpure-ftpd配置备份原配置...

取消回复欢迎 发表评论: