VPS主机搭建Ghost环境:Nginx Node.js MariaDB
wptr33 2025-04-29 05:38 21 浏览
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建站过程中有任何问题可咨询博主。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。
相关推荐
- Python 中 必须掌握的 20 个核心:str()
-
str()是Python中用于将对象转换为字符串表示的核心函数,它在字符串处理、输出格式化和对象序列化中扮演着关键角色。本文将全面解析str()函数的用法和特性。1.str()函数的基本用法...
- python中的函数报错后继续运行而不是停止整个程序
-
要让main...
- 如何在身份证号码中提取出生年月日的函数公式
-
在不同软件中,从身份证号码提取出生年月日的函数公式不同,以下是常见软件的方法:Excelo假设身份证号码在A列,在B列提取出生年月日,在B2单元格输入公式=TEXT(MID(A2,7,8),"...
- sql中的一些CTE和开窗函数相关用法
-
CTE的优势提高可读性:将复杂查询分解为更简单的部分避免重复子查询:同一CTE可以在查询中多次引用递归查询:处理层次结构数据模块化SQL:将复杂查询拆分成逻辑模块...
- 【SQL】SQL 语法差异大全(PgSQL/MySQL/Oracle/TiDB/OceanBase)
-
以下是针对不同数据库系统的SQL语法差异总结,按功能分类展示:一、基础查询1.分页查询...
- MySQL索引:从原理到实战的终极指南
-
MySQL索引原理揭秘MySQL索引是数据库高效查询的核心机制,其原理基于特定的数据结构(主要是B+Tree)和数据库引擎(如InnoDB)的实现策略。索引本质上是一种空间换时间的策略,虽然会占...
- 如何在本地安装开源人工智能Agent——AutoGen Studio的安装
-
AutoGen是微软出品的一个用于创建可自主行动,或与人类协同工作的多智能体AI应用程序的框架。下面来介绍如何在本地安装AutoGenStudio,AutoGenStudio是一个低代码界...
- 小巧WinForm库存系统,竟能实现这些功能?
-
第一次体验真正“握在手里的”库存控制,是在一个微型工厂的仓库运输带旁。顶着仓库里金属味和三十几平米的闷热,老王蹲在地上,一边用笔在账本上划格,一边嘴里嘟囔:“每次都说要数字化管理,数字在哪儿呢?”透过...
- 有关SQLite数据库的介绍
-
SQLite,是一种轻型的数据库,它的设计目标是嵌入式的,而且已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/U...
- SQLite 数据库Web管理工具
-
概述SQLite数据库以其轻量级和易于配置的特点,成为了许多项目中的首选数据库。尽管它的便捷性受到了广泛的认可,但对于数据库的管理和维护,尤其是在没有图形界面工具的情况下,开发者往往需要通过复杂的命...
- SqlLite数据库注意要点分析
-
1.验证sqlite是否安装配置好了。执行sqlite3命令。当执行该命令的时候没有传递任何参数表示默认连接到了一个内存数据库,当退出该程序的时候,数据库自动销毁。退出命令:.quit.ex...
- python 连接sqlite
-
在Python中,你可以使用标准库sqlite3来连接SQLite数据库。在Python中,sqlite3模块是内置的,无需使用pip进行安装。sqlite3模块提供了与SQ...
- 提升数据库搜索效率:探索SQLite的向量搜索扩展
-
大家好!今天我们要聊一个特别酷炫的东西——sqlite-vec,一个能让SQLite飞起来的向量搜索扩展。如果你对数据库的搜索速度不满意,那你可得好好看看这篇文章了。...
- Qt编程进阶(21):Qt操作SQLite数据库及实例
-
QtSql模块Qt提供的QtSql模块实现了对数据库的访问,同时提供了一套与平台和具体所用数据库均无关的调用接口。此模块为不同层次的用户提供了不同的丰富的数据库操作类。例如,对于习惯使用SQL语法的用...
- 5分钟快速掌握在Python使用SQLite数据库,
-
小巧、稳定、快速!我为什么喜欢用SQLite...
- 一周热门
-
-
因果推断Matching方式实现代码 因果推断模型
-
C# 13 和 .NET 9 全知道 :13 使用 ASP.NET Core 构建网站 (1)
-
git pull命令使用实例 git pull--rebase
-
git 执行pull错误如何撤销 git pull fail
-
面试官:git pull是哪两个指令的组合?
-
git pull 和git fetch 命令分别有什么作用?二者有什么区别?
-
git fetch 和git pull 的异同 git中fetch和pull的区别
-
git pull 之后本地代码被覆盖 解决方案
-
还可以这样玩?Git基本原理及各种骚操作,涨知识了
-
git命令之pull git.pull
-
- 最近发表
- 标签列表
-
- git pull (33)
- git fetch (35)
- mysql insert (35)
- mysql distinct (37)
- concat_ws (36)
- java continue (36)
- jenkins官网 (37)
- mysql 子查询 (37)
- python元组 (33)
- mybatis 分页 (35)
- vba split (37)
- redis watch (34)
- python list sort (37)
- nvarchar2 (34)
- mysql not null (36)
- hmset (35)
- python telnet (35)
- python readlines() 方法 (36)
- munmap (35)
- docker network create (35)
- redis 集合 (37)
- python sftp (37)
- setpriority (34)
- c语言 switch (34)
- git commit (34)