看见别人写过一次,不尽人意,看起来乱七八糟而且部分步骤我觉得非常麻烦,干脆自己写一个吧,在V2EX,算是第一个发布的稿子吧
因为怕一些人不会拿到新的VPS不会部署,在这里也一并说了算是造福社会吧2333
接下来按照步骤走就对啦
原文: http://imoe.moe/install-ghost/
本文包括基于Centos7 64位系统搭建Ghost博客系统,附带指导安装Nginx,mariadb,nodejs,ghost~~嗯,就是这样,那么让我们开始吧
没有抄袭官方的文档,不信你可以去对比,全部经验走起
PS:为了方便大家,在本文结尾处附带了2个安装版本,请慢慢读下去吧,文末有惊喜哦~
TOC
一、Centos 7 安装Nginx
1、安装依赖
2、通过源安装Nginx
二、Centos 7安装mariadb
1、安装Mariadb Mariadb-server
2、配置Mariadb
3、配置mariadb以防止乱码
三、安装nodejs
四、安装Ghost博客
1、配置一下nginx
五、配置systemd
六、完成
<h4 id=“anamecentoscentos7nginxa”><a name='centos'>一、Centos 7 安装Nginx[有的人请跳过]</a></h4>
<h6 id=“anameyilai1a”><a name='yilai'>1、安装依赖</a></h6>
<pre><code class=“python”> # yum install gcc-c++
# yum install pcre pcre-devel
# yum install zlib zlib-devel
# yum install openssl openssl–devel
</code></pre>
<h5 id=“anameyuan2nginxa”><a name='yuan'>2、通过源安装Nginx</a></h5>
<p><strong>Centos7 默认是没有Nginx源的,需要自己添加。当然你也可以手动编译最新版的包,但是貌似不能用systemd管理。这里通过源来安装</strong></p>
<pre><code class=“python”> # wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx- release-centos-7-0.el7.ngx.noarch.rpm
# rpm -ivh noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# yum install nginx
//让nginx随机子启动而启动并启动nginx
# systemctl enable nginx
# systemctl start nginx
//查看下状态
# systemctl status nginx
</code></pre>
<p><strong>Centos7默认是安装在/etc/nginx 配置文件在/etc/nginx/conf.d/default.conf</strong></p>
<hr />
<h4 id=“anamemariadbcentos7mariadba”><a name='mariadb'>二、Centos 7安装mariadb</a></h4>
<p><strong>Centos7源中没有了mysql而是改用了mariadb,他们关系自行google</strong></p>
<h6 id=“anamemariadbserver1mariadbmariadbservera”><a name='mariadb-server'>1、安装Mariadb Mariadb-server</a></h6>
<pre><code class=“python”> # yum install mariadb mariadb-server
# systemctl enable mariadb
# systemctl start mariadb
# systemctl status mariadb
</code></pre>
<h6 id=“anameconfigmariadb2mariadba”><a name='config-mariadb'>2、配置Mariadb</a></h6>
<pre><code class=“python”> # mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
//这里直接按回车
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
//提示输入root账户密码,是mysql账户的密码,不是系统的
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
//是否删除匿名账户
Remove anonymous users? [Y/n] yes
… Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
//是否禁止远程登陆
Disallow root login remotely? [Y/n] y
… Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
//删除test测试数据库
Remove test database and access to it? [Y/n] y
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
//重载权限表
Reload privilege tables now? [Y/n] y
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
</code></pre>
<h6 id=“anamecharset3mariadba”><a name='charset'>3、配置mariadb以防止乱码</a></h6>
<pre><code class=“python”># vi /etc/my.cnf
在[mysqld]字段下面添加类似于这样
[mysqld]
//添加下面这三行到[mysqld]字段
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
//重启mariadb
//登陆查看下是否改变为utf-8
</code></pre>
<p><img src=“http://ghostblog.qiniudn.com/mariadb_chara1.png” alt=“” title=“” /> <br />
<img src=“http://ghostblog.qiniudn.com/mariadb_char2.png” alt=“” title=“” /></p>
<h4 id=“anamenodejsnodejsa”><a name='nodejs'>三、安装nodejs</a></h4>
<p><strong>nodejs编译的很慢,我是直接下载的二进制包</strong></p>
<pre><code class=“python”>#wget http://nodejs.org/dist/v0.10.33/node-v0.10.33-linux-x64.tar.gz
v0.10.32
1.4.28 //出现同样的效果
</code></pre>
还有一种非常简易的方法,两个命令解决node部署与npm依赖
<pre><code class=“python”># curl -sL https://rpm.nodesource.com/setup | bash -
v0.10.32
1.4.28 //同样的效果
</code></pre>
<h4 id=“anameghostghosta”><a name='ghost'>四、安装Ghost博客系统</a></h4>
<p><strong>Ghost是一个轻量级的Blog系统,基于nodejs构建。相较于wp我觉得Ghost更适合写作,本Blog就是搭建于Ghost博客。你可以访问<a href=“http://ghost.org”>官方网站</a>了解她。</strong></p>
<pre><code class=“python”>$ wget https://ghost.org/zip/ghost-latest.zip
$ unzip ghost-latest.zip -d ghost //如没有unzip请执行$ sudo yum install unzip 来安装
$ npm install –production
$ mysql -uroot -p -e 'create database ghost;' //ghost默认的是sqlite数据库,但是在各大云平台上都不是太好,这里更换为mariadb数据库。这里新建一个ghost数据库。
$ cp config.example.js config.js
$ vim config.js
//修改config.js类似于这样,主要是mysql配置
production: {
url: 'http://your_blog_url',
mail: {},
database: {
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'root', //暂且直接用root账户
password : 'password', //你的root账户密码
database : 'ghost',
charset : 'utf8'
},
debug: false
},
server: {
// Host to be passed to node's `net.Server#listen()`
host: '127.0.0.1',//改为0.0.0.0,否则他人无法访问
// Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
port: '2368'
}
},
</code></pre>
<h6 id=“anameconfignginx1nginxa”><a name='config-nginx'>1、配置一下nginx</a></h6>
<pre><code class=“python”># vim /etc/nginx/conf.d/default.conf
//删除里面内容添加
server {
listen 80;
server_name xxx.com www.xxxx.com; //替换为你自己的域名!
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
</code></pre>
<p><strong>如果你已经启用了Nginx的反向代理那么可以执行<code>npm start –production</code>来看看效果,前提你已经把域名解析到IP,如果没有解析那么可以用IP访问,切记,–production不可省</strong></p>
<h4 id=“anamesystemdsystemda”><a name='systemd'>五、配置systemd</a></h4>
<p><strong>当我们断开ssh的时候,nodejs的进程也会死掉,所以我们要让ghost自动重启,官方推荐用forever如果你想用可以去看看。在这里我们用Centos新的配置工具systemd来守护Ghost,让她死掉后能自动重启。关于systemd请自行google</strong></p>
<pre><code class=“python”># vim /etc/systemd/system/ghost.service
//添加以下内容
[Service]
WorkingDirectory=你的ghost博客目录
ExecStart=/opt/node-v0.10.32/bin/node index.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=ghostblog
User=你想运行ghost的用户
Group=组
Environment=PATH=/opt/node-v0.10.32/bin:$PATH
Environment='NODE_ENV=production'
[Install]
WantedBy=multi-user.target
让Ghost自启动
</code></pre>
<h4 id=“anameoka”><a name='ok'>六、安装完成</a></h4>
<p>说好的福利呢!</p>
PS:福利在此,很多人说在国内无法使用npm依赖,原因是长城拦住了,于是在此附带最新的0.5.6的中文汉化版本,内附node_modules依赖,你只需使用npm start命令运行即可,其余的均已经帮你配置好了。
下载地址: http://pan.baidu.com/s/1bnhcjmR
最后希望这个博客能帮助到你,欢迎来到ghost的世界╮( ̄▽ ̄")╭
转载标明出处"imoe.moe",这是基本的素质和修养问题,个人博客imoe.moe,欢迎做客(^__^)
1
Moefun OP 好无语。。。竟然没办法去修改文章
|
3
Moefun OP 排版有点乱,貌似不支持语法.......我也是第一次发
|
4
jinshi 2014-12-13 21:20:45 +08:00
博客好漂亮!~~
|
6
mjever 2014-12-13 21:29:35 +08:00
技术贴,支持起!!
|
7
kiritoalex 2014-12-13 21:31:50 +08:00
。。。。排版好乱。。不过感谢楼主啦
PS:V2不支持论坛那种复杂代码的:P |
8
echopan 2014-12-13 21:45:46 +08:00
@kiritoalex 去楼主网站看看下就可以,因为没写好
|
9
MinonHeart 2014-12-13 21:57:16 +08:00
我来看看域名
|
10
moliliang 2014-12-13 22:46:12 +08:00
githis 部署jekyll 也很简单
|
11
MeowCold 2014-12-13 22:51:40 +08:00
支持 前排
|
12
Imivan 2014-12-13 22:55:51 +08:00
这些用得着发吗?
|
13
disonlee 2014-12-13 23:17:32 +08:00
很好的文章,排版有点乱。。。还差一个用pm2使ghost一直运行。
|
14
jimmy66 2014-12-13 23:30:31 +08:00
支持~
|
16
Jays 2014-12-13 23:31:49 +08:00 via iPad
哪位来个debian 7的吧 , 我的ghost+mysql总是失败
|
18
TrustyWolf 2014-12-13 23:51:49 +08:00 via iPhone
Hexo大法好。纯静态大法好。
博客神马的才不要数据库呢,逃) |
20
Showfom 2014-12-14 02:32:24 +08:00 via iPhone
@TrustyWolf 等文章多的时候就要捂脸了
|
21
echopan 2014-12-14 08:51:17 +08:00
@TrustyWolf hexo怎么做?没有中文官方站点
|
22
TrustyWolf 2014-12-14 14:18:29 +08:00 1
@echopan http://hexo.io/ 文档非常全,安装相当简单,在CentOS 7下只需要几个命令:
yum -y install epel-release yum -y install nodejs yum -y install npm npm install -g hexo 安装完毕0rz... |
23
echopan 2014-12-14 14:42:15 +08:00
@TrustyWolf [error] { name: 'HexoError',
reason: 'can not read a block mapping entry; a multiline key may not be an implicit key', mark: { name: null, buffer: '# Hexo Configuration\n## Docs: http://hexo.io/docs/configuration.html\n## Source: https://github.com/hexojs/hexo/\n\n# Site\ntitle: hexo\nsubtitle:angel beats!\ndescription:\nauthor: echopan\nemail:[email protected]\nlanguage:zh-CN\n# URL\n## If your site is put in a subdirectory, set url as \'http://hexo.freedom.moe/\' and root as \'home/hexo.freedom.moe/\n\'\nurl: http://hexo.freedom.moe\nroot: /home/hexo.freedom.moe/\npermalink: :year/:month/:day/:title/\ntag_dir: tags\narchive_dir: archives\ncategory_dir: categories\ncode_dir: downloads/code\npermalink_defaults:\n\n# Directory\nsource_dir: source\npublic_dir: public\n\n# Writing\nnew_post_name: :title.md # File name of new posts\ndefault_layout: post\ntitlecase: false # Transform title into titlecase\nexternal_link: true # Open external links in new tab\nfilename_case: 0\nrender_drafts: false\npost_asset_folder: false\nrelative_link: false\nhighlight:\n enable: true\n line_number: true\n tab_replace:\n\n# Category & Tag\ndefault_category: uncategorized\ncategory_map:\ntag_map:\n\n# Archives\n## 2: Enable pagination\n## 1: Disable pagination\n## 0: Fully Disable\narchive: 2\ncategory: 2\ntag: 2\n\n# Server\n## Hexo uses Connect as a server\n## You can customize the logger format as defined in\n## http://www.senchalabs.org/connect/logger.html\nport: 4000\nserver_ip: localhost\nlogger: false\nlogger_format: dev\n\n# Date / Time format\n## Hexo uses Moment.js to parse and display date\n## You can customize the date format as defined in\n## http://momentjs.com/docs/#/displaying/format/\ndate_format: MMM D YYYY\ntime_format: H:mm:ss\n\n# Pagination\n## Set per_page to 0 to disable pagination\nper_page: 10\npagination_dir: page\n\n# Disqus\ndisqus_shortname:\n\n# Extensions\n## Plugins: https://github.com/hexojs/hexo/wiki/Plugins\n## Themes: https://github.com/hexojs/hexo/wiki/Themes\ntheme: landscape\nexclude_generator:\n\n# Deployment\n## Docs: http://hexo.io/docs/deployment.html\ndeploy:\n type:\n\u0000', position: 165, line: 7, column: 11 }, message: 'Config file load failed', domain: { domain: null, _events: { error: [Function] }, _maxListeners: 10, members: [ [Object] ] }, domainThrown: true, stack: undefined } |
24
echopan 2014-12-14 14:42:31 +08:00
@TrustyWolf 这错误怎么解决
|
25
TrustyWolf 2014-12-14 15:03:02 +08:00
@echopan 配置文件有错误,就是博客目录下的那个 _config.yml
|
26
adspe 2014-12-14 16:20:29 +08:00
上次我用Debian上面搞了半天的nginx反代80我也是醉了。
|
28
echopan 2014-12-14 16:59:03 +08:00
@TrustyWolf 我不会弄呢,=。= 加我扣扣咨询 三五2914三90
|