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

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

liebian365 2024-10-26 13:06 14 浏览 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建站过程中有任何问题可咨询博主。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。

相关推荐

4万多吨豪华游轮遇险 竟是因为这个原因……

(观察者网讯)4.7万吨豪华游轮搁浅,竟是因为油量太低?据观察者网此前报道,挪威游轮“维京天空”号上周六(23日)在挪威近海发生引擎故障搁浅。船上载有1300多人,其中28人受伤住院。经过数天的调...

“菜鸟黑客”必用兵器之“渗透测试篇二”

"菜鸟黑客"必用兵器之"渗透测试篇二"上篇文章主要针对伙伴们对"渗透测试"应该如何学习?"渗透测试"的基本流程?本篇文章继续上次的分享,接着介绍一下黑客们常用的渗透测试工具有哪些?以及用实验环境让大家...

科幻春晚丨《震动羽翼说“Hello”》两万年星间飞行,探测器对地球的最终告白

作者|藤井太洋译者|祝力新【编者按】2021年科幻春晚的最后一篇小说,来自大家喜爱的日本科幻作家藤井太洋。小说将视角放在一颗太空探测器上,延续了他一贯的浪漫风格。...

麦子陪你做作业(二):KEGG通路数据库的正确打开姿势

作者:麦子KEGG是通路数据库中最庞大的,涵盖基因组网络信息,主要注释基因的功能和调控关系。当我们选到了合适的候选分子,单变量研究也已做完,接着研究机制的时便可使用到它。你需要了解你的分子目前已有哪些...

知存科技王绍迪:突破存储墙瓶颈,详解存算一体架构优势

智东西(公众号:zhidxcom)编辑|韦世玮智东西6月5日消息,近日,在落幕不久的GTIC2021嵌入式AI创新峰会上,知存科技CEO王绍迪博士以《存算一体AI芯片:AIoT设备的算力新选择》...

每日新闻播报(September 14)_每日新闻播报英文

AnOscarstatuestandscoveredwithplasticduringpreparationsleadinguptothe87thAcademyAward...

香港新巴城巴开放实时到站数据 供科技界研发使用

中新网3月22日电据香港《明报》报道,香港特区政府致力推动智慧城市,鼓励公私营机构开放数据,以便科技界研发使用。香港运输署21日与新巴及城巴(两巴)公司签署谅解备忘录,两巴将于2019年第3季度,开...

5款不容错过的APP: Red Bull Alert,Flipagram,WifiMapper

本周有不少非常出色的app推出,鸵鸟电台做了一个小合集。亮相本周榜单的有WifiMapper's安卓版的app,其中包含了RedBull的一款新型闹钟,还有一款可爱的怪物主题益智游戏。一起来看看我...

Qt动画效果展示_qt显示图片

今天在这篇博文中,主要实践Qt动画,做一个实例来讲解Qt动画使用,其界面如下图所示(由于没有录制为gif动画图片,所以请各位下载查看效果):该程序使用应用程序单窗口,主窗口继承于QMainWindow...

如何从0到1设计实现一门自己的脚本语言

作者:dong...

三年级语文上册 仿写句子 需要的直接下载打印吧

描写秋天的好句好段1.秋天来了,山野变成了美丽的图画。苹果露出红红的脸庞,梨树挂起金黄的灯笼,高粱举起了燃烧的火把。大雁在天空一会儿写“人”字,一会儿写“一”字。2.花园里,菊花争奇斗艳,红的似火,粉...

C++|那些一看就很简洁、优雅、经典的小代码段

目录0等概率随机洗牌:1大小写转换2字符串复制...

二年级上册语文必考句子仿写,家长打印,孩子照着练

二年级上册语文必考句子仿写,家长打印,孩子照着练。具体如下:...

一年级语文上 句子专项练习(可打印)

...

亲自上阵!C++ 大佬深度“剧透”:C++26 将如何在代码生成上对抗 Rust?

...

取消回复欢迎 发表评论: