看见别人写过一次,不尽人意,看起来乱七八糟而且部分步骤我觉得非常麻烦,干脆自己写一个吧,在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,欢迎做客(^__^)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.