(转)博客第一篇:记录这个网站的诞生过程

转发自:http://kittenyang.com/myfirstblog/

1. 购买域名

域名就是网址。比如我这个网站的域名就是kittenyang.com。Godaddy是全球最大的域名供应商,所以我在Godaddy(网友亲切称其为“狗爹”)购买了域名。

2287217-06da6427b24d4fbf.png

首页中大大的输入框(Enter a domain name)里面就可以输入你想要注册的域名,然后godaddy会告诉你这个有没有被注册。如果被注册了,godaddy会建议你使用其他后缀名比如.net.org.me...

*tips:

Godaddy可以使用支付宝支付,只要把顶部货币栏切换到CNY即可。

购买完成之后,进入你的My Account,点击Domains,点击Launch.

2287217-59ed45da2bd17ae5.png

然后你会进入到域名的配置页面。在这里我们需要把域名和我们的服务器绑定起来。其实很简单,就一句话,把域名绑定到服务器的IP地址即可。这个过程,就是传说中的解析

怎么解析呢? 请看下图:

2287217-766b30249bca66d0.png
2287217-dbcc7d4853b04a79.png

点击编辑,在Points to一栏中填入服务器的IP地址即可。这里的Host其实就是前缀。这里普及两个名词:顶级域名二级域名。我们平常所知道的所谓的so-called正确网址是www.XXX.xxx。其实不然, 我们只要输入XXX.xxx就可以了,不需要输入前面的www。www只是一个前缀。www.XXX.xxx就是一个二级域名,类似的还有mail.qq.com、open.weibo.com等。而顶级域名就是XXX.xxx,比如baidu.com、qq.com。所以我们在解析的时候第一栏的Host Name就只是个前缀。顶级域名一般用@表示。

域名配置好了,接下来我们就要去配置服务器(本文以阿里云服务器为例)了。

由于笔者用的是Mac,所以我只能用Mac上的方法来写这篇博文。但Windows用户也不用害怕,流程是对的,只是有些环节的手段不太一样。如果遇到不懂的,请善用搜索引擎,俗称黄金法则

2. 配置服务器

首先启动终端terminal(Mac上开启一个文件或者一个应用的最快方法:control + 空格,呼出spotlight,输入想要的文件或应用的名称,如terminal,回车)。

输入命令行:ssh root@你的IP地址,回车。输入服务器密码。

2287217-9a84a324b520b395.png

这段命令的作用是请求连接服务器。出现如下界面表示连接成功。

2287217-ee5ba123c566cd08.png

2.1 安装Node.js

依次执行以下指令:

sudo apt-getupdatesudo apt-getinstall-y python-software-properties python g++ make  sudoadd-apt-repository ppa:chris-lea/node.js  sudo apt-getupdatesudo apt-getinstallnodejs

确认是否安装成功:

node-v

v0.10.30

npm-v

1.4.21

2.2 安装Nginx

执行以下指令:

sudo apt-getinstall nginx

2.3 安装MySQL

Ghost 默认采用 Sqlite3 数据库,但是我还是建议用 MySQL,避免将来由于数据多、访问量多而导致性能下降。

执行如下指令开始安装 MySQL 吧:

sudo apt-getinstallmysql-servermysql-client

安装过程中,系统会提示你给root用户(这里的 root 是 MySQL 数据库的管理账号) 设置个密码,建议设置的复杂些,更加安全些。如下图:

2287217-659f9225adc5d80a.png

MySQL 安装成功后,我们执行以下指令进一步加强 MySQL 的安全设置:

sudomysql_secure_installation

此工具所做的增强安全设置包括:移除所有匿名账户、限制远程 root 账户登录、删除 test 数据库等。下面列出详细设置:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL        SERVERS IN PRODUCTIONUSE!  PLEASEREADEACHSTEP CAREFULLY!InordertologintoMySQLtosecure it, we'll need the current

password for the root user.  If you've just installed MySQL,andyou haven't set the root password yet, the password will be blank,

so you should just press enter here.

//输入安装 MySQL 时为 root 账户设置的密码

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 MySQL

root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

//是否修改 root 账户的密码?前面设置过 root 账户的密码了,如果不打算修改密码的话,输入 'n'

Change the root password? [Y/n] n

... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL 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] y

... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

//是否禁止 root 账户远程登录?

Disallow root login remotely? [Y/n] y

... Success!

By default, MySQL 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.

//是否删除 MySQL 默认创建的 test 数据库,并删除所有对 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 completedallofthe above steps, your MySQL  installation shouldnowbe secure.ThanksforusingMySQL!

OK!MySQL 到此就安装好了!

下面,我们为为 MySQL 设置默认字符集。将数据库、htnl页面、源码文件都设置为统一的字符集会减少很多麻烦,当然,utf8 是最好的选择。

执行如下命令:

cd/etc/mysql

这条命令的作用是进入/etc/mysql文件夹。

然后输入:

vimy.cnf

这条命令的作用是用Vim编辑器打开/etc/mysql目录下的 my.cnf 文件,然后就可以在终端对文件进行修改了。就像下面这样的界面:

2287217-f99d974df0c42c08.png

将光标定位到[mysqld]位置,按"i",这时可以修改了,添加如下设置:

[mysqld]collation-server =utf8_unicode_ciinit-connect='SET NAMES utf8'character-set-server =utf8

修改完成之后,先按esc,然后输入:wq,退出MySQL。

为了确保设置成功,我们检查一下:

进入 MySQL 命令行界面:mysql -uroot -p,输入之前你自己设置的MySQL密码。

输入指令:show variables like 'char%';输出是否如下所示:

2287217-8474860efb2a875a.png

再输入指令:show variables like 'collation%';检查一下结果:

2287217-162457146508ea22.png

如果是上面的结果,恭喜你,搞定 MySQL 了!!!

3. 安装Ghost

3.1 创建数据库

我们希望 Ghost 搭配 MySQL 数据库运行,因此需要为 Ghost 创建一个 MySQL 数据库。前面已经安装好 MySQL 了,现在我们就来创建数据库吧:

mysql -uroot -p -e 'createdatabaseghost;'

系统会提示你输入 MySQL 数据库的root账户密码(还记得前一章节安装 MySQL 时设置的密码吗?)。指令执行之后就创建了一个叫做ghost的数据库,将来,你的文章就是存在这里喽!

3.2 配置Nginx

我们希望利用 Nginx 做 Ghost 的前端代理服务。OK, 输入下面命令进入/etc/nginx/sites-available/目录:

cd /etc/nginx/sites-available/

然后输入下面指令:

sudotouch ghost.conf  sudo vi ghost.conf

还记得vi指令的作用吗?最后一条指令的作用是 vim 编辑器打开 ghost.conf 文件进行编辑。我们输入如下内容:

server {      listen80;    server_name kittenyang.com *.kittenyang.com115.28.223.69; //替换为你自己的域名!    location / {        proxy_set_header  X-Real-IP$remote_addr;        proxy_set_header  Host$http_host;        proxy_pass        http://127.0.0.1:2368;    }}

完成之后按etc:wq退出编辑。

然后我们为 ghost.conf 文件做一个软链接到/etc/nginx/sites-enabled/目录下:

sudo ln-s/etc/nginx/sites-available/ghost.conf /etc/nginx/sites-enabled/ghost.conf

3.3 安装forever

如果是通过npm start启动 Ghost 的话,只要你关闭了远程连接,Ghost 也就停了,这个我们当然不希望喽。幸好,有forever工具帮我们解决这个问题。接下来执行以下指令来安装forever:

sudonpminstall forever -g

3.4 Ghost,走你!

3.4.1 下载Ghost

Ghost 安装包是经过压缩的,在 Linux 上我们需要用unzip工具对其解压,因此,首先要安装unzip工具:

sudo apt-getinstall unzip

接下来我们下载 Ghost 安装包:

cd/srv/  sudo curl -Lhttp://dl.ghostchina.com/Ghost-0.5.0.zip-o ghost.zip

上面命令中网址的版本号可以根据ghostchina.com上的最新版本修改,我写这篇文章的最新版本是0.5.0,所以我输入的是0.5.0

将其解压缩:

sudo unzip ghost.zip-dghost

现在,/srv/ghost/目录下面就是我们的 Ghost 系统了!

3.4.2 修改Ghost配置文件

我们进入 Ghost 系统目录,为 Ghost 增加配置文件并配置数据库:

cd/srv/ghost/  sudo cp config.example.js config.js  sudo vi config.js

最后一条指令是用 vim 打开 config.js 文件进行编辑。我们只修改production一节的配置信息,修改为如下形式(注意按照你自己的实际情况替换!):

// ### Production    // When running Ghost in the wild,usethe production environment    // Configure your URLandmail settings here    production: {        url:'http://ghostchina.com', //替换为你自己的域名。        mail: {},database: {            updateCheck:false,            client:'mysql',connection: {                host    :'127.0.0.1',user:'root', //我们暂且用 MySQL 的 root 账户password:'123456', //输入你的 MySQL 密码database:'ghost', //我们前面为 Ghost 创建的数据库名称charset:'utf8'}        },server: {            // Hosttobe passedtonode's `net.Server#listen()`

host: '127.0.0.1',

// Port to be passed to node's`net.Server#listen()`,foriisnodesetthisto`process.env.PORT`port:'2368'}    },

完成之后按etc:wq退出编辑。

3.4.3 安装 Ghost 依赖库

打开 Ghost 系统的目录下面的package.json 文件,将"sqlite3": "2.2.0", 这一行删除掉(注意,你看到的 sqlite 版本可能会不一样,但是,只要是sqlite3字样,删除即可)。

接下来,进入存放 Ghost 系统的目录并安装 Ghost 所依赖的npm包:

cd/srv/ghost/sudonpminstall --production

很快,所有依赖包就安装好了,当前目录下会多出一个node_modules目录。

3.4.3 启动 Ghost

执行如下指令重启 Nginx、启动 Ghost:

sudo service nginx restart  cd /srv/ghost  sudo NODE_ENV=production foreverstartindex.js

OK,至此,所有的操作都做完了。现在打开浏览器并输入你的域名看看吧!

Q&A:

Q1. 主页显示很慢,界面很久才展示出来.

A:还是因为google被墙了,需要删除三处引用了谷歌字体的地方。/core/server/views下的两个default.hbs和user-error.hbs以及主题目录content/themes/你的主题/default.hbs中的:

Q2. service nginx restart 重启Nginx失败.

A:原因在于你已经把端口映射的配置写进default这个默认的配置文件了,但是你又写了一份同样的配置到ghost.conf,结果这两个配置同时生效,重启时冲突了。所以你应该:

输入以下命令:/etc/nginx/sites-available# rm -rf ghost.conf.

检查:/etc/nginx/sites-available# ls

应该就只会显示:default

然后service nginx restart重启Nginx 就行了 重启成功了。

Q3. npm start ghost 正常运行以后,访问ghost, 无法进入后台,web端显示的状态码为302.

A:进入ghost 后台系统会自动检测更新,是否有新版本,但是国内无法访问这个地址update.ghost.org.

所以你应该在config.js中加入updateCheck: false, 看起来像这样:

development: {        updateCheck:false,        database: {            client:'mysql',            connection: {                host    :'127.0.0.1',                ......

Q4. 如何备份现有的文件?

A:cp /srv/ghost /srv/ghost_bak

这样就可以把原来的文件备份到ghost_bak文件夹.

Q5. 如何备份数据库?

A:先按cd /srv进入/srv目录,再mysqldump -uroot -p你的密码 ghost > ghost.sql

这样就会把你的数据库内容备份到srv目录的ghost.sql这个文件里.

转载请注明出处,不胜感激!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值