美文网首页
我是如何搭建个人技术博客的

我是如何搭建个人技术博客的

作者: 澜色飞扬 | 来源:发表于2016-04-18 16:36 被阅读390次

做开发有些时间了,一直希望从高标准严格自己,也希望有个特色风格的技术博客,看了喵神的博客,我很喜欢,于是就仿照做了一个~

1.购买域名

域名也就是网址,可以到万网Godaddy等域名供应商购买,我的域名lansefund.com是在万网购买,如下:

Snip20160418_1.png

当然域名的后缀有很多种.com 、.cn 、.me 、.net等,根据自己的偏好购买就可以了,如果想购买的域名被注册了可以选择其他的后缀!

2.域名解析

所谓解析就是域名绑定服务器IP地址即可,像这种轻量级的网站服务器可以选择云虚拟主机或阿里云服务器ECS,我的是在在阿里云服务器ECS_Ubun系统上安装Ghost,然后根据阿里云的教程一步步解析就好了。如果选择云服务器ECS创建实例后会给一个弹性公用IP地址和私有IP地址,解析域名在IP地址里写弹性公用IP地址。由于我用的是Mac,所以教程也是基于Mac OS的系统,Windows的步骤也差不多,遇到问题多利用搜索引擎就好了!

域名解析好后,可以打开终端 输入ping lansefund.com (ping空格+域名),如果出现下图样式,解析就成功了,(括号里面123.56.16.58是我的服务器IP地址)

Snip20160418_2.png

3.配置服务器

打开终端,输入命令行

ssh root@你的IP地址
回车,输入你的服务器密码

这段命令行用来连接服务器,出现下面的结果表示连接成功

Snip20160418_4.png

3.1安装node.js

  • 1.安装程序
    Node.js是一个可以快速构建网络服务及应用的 平台,基于Chrome's JavaScript runtime,即Google V8引擎,是一款高性能的服务架构平台,Ubuntu系统上执行以下代码即可安装Node.js
sudo apt-get update  
sudo apt-get install -y python-software-properties python g++ make  
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js  
sudo apt-get update  
sudo apt-get install nodejs  
  • 2.查看是否安装成功
node -v
v0.10.37
npm -v
1.4.28

3.2 安装Nginx

输入安装命令
sudo apt-get install nginx

3.3安装MySQL

Ghost 默认采用 Sqlite3 数据库, 安装MySQL执行如下命令:

sudo apt-get install mysql-server mysql-client 

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


Snip20160418_5.png

安装成功后,为确保安全性执行以下指令加强 MySQL 的安全设置:

sudo mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current  
password for the root user.  If you've just installed MySQL, and  
you 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 账户的密码?
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 completed all of the above steps, your MySQL  
installation should now be secure.

Thanks for using MySQL!  

OK!MySQL 到此就安装好了!

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

执行如下命令:

cd /etc/mysql 

然后输入

vi my.cnf 

这条命令的作用是用 Vim编辑器打开 /etc/mysql 目录下的 my.cnf 文件,在终端对文件进行修改,将光标定位到 [mysqld] 位置,按 "i" ,添加如下红线框内设置,如下:

Snip20160418_6.png
[mysqld]
collation-server = utf8_unicode_ci  
init-connect='SET NAMES utf8'  
character-set-server = utf8 

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

4.安装Ghost

4.1创建数据库

输入指令

mysql -uroot -p -e 'create database ghost;' 

根据系统提示,输入MySQL数据库的root 的密码(上一步骤刚设置过的).指令执行之后就创建了一个叫做 ghost 的数据库。

4.2 配置Nginx

我们利用 Nginx 做 Ghost 的前端代理服务 输入:

cd /etc/nginx/sites-available/
sudo touch ghost.conf 
sudo vi ghost.conf 

就可以用vim 编辑器打开 ghost.conf 文件进行编辑,如下

Snip20160418_7.png

然后按esc :wq 退出编辑

4.3 建立软连接

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

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

4.4 安装forever

如果是通过npm start 启动 Ghost 的话,只要关闭了远程连接,Ghost 也就停了,为了使ghost永远运行,使用 forever 工具解决这个问题。接下来执行以下指令来安装 forever,执行如下命令:

sudo npm install forever -g 

4.5 开始安装Ghost

  • 4.5.1.下载Ghost
    先安装curl,输入
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

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

sudo apt-get install unzip  

然后下载Ghost 安装包:

cd /srv/
sudo curl -L http://dl.ghostchina.com/Ghost-0.7.4.zip -o ghost.zip  

网址的版本号可以根据ghostchina.com 上的最新版本修改,我写这篇文章的最新版本是0.7.4,所以我输入的是0.7.4
解压缩:

sudo unzip ghost.zip -d ghost
  • 4.5.2 修改Ghost配置文件
    进入 Ghost 系统目录,为 Ghost 增加配置文件并配置数据库
cd /srv/ghost/  
sudo cp config.example.js config.js  
sudo vi config.js  

修改production 的配置信息,修改为如下

Snip20160419_2.png

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

  • 4.5.3 安装 Ghost 依赖库
    打开 Ghost 系统的目录下面的 package.json 文件,将 "sqlite3": "x.x.0", 这一行删除掉。
    接下来,进入存放 Ghost 系统的目录并安装 Ghost 所依赖的npm包:
cd /srv/ghost/ 
sudo npm install --production

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

  • 4.5.4 启动 Ghost
    执行如下指令重启 Nginx、启动 Ghost:
sudo service nginx restart
cd /srv/ghost 
sudo NODE_ENV=production forever start index.js

所有的操作都做完了,待DNS生效后,打开域名,就可以看到Ghost博客已经成功运行了。

相关文章

  • 我是如何搭建个人技术博客的

    做开发有些时间了,一直希望从高标准严格自己,也希望有个特色风格的技术博客,看了喵神的博客,我很喜欢,于是就仿照做了...

  • Hexo+github博客搭建记录

    为何搭建个人博客 一直想搭建自己的个人博客,写博客可以记录我的学习笔记、总结经验、分享技术等等。本来csdn、博客...

  • 将 Hexo 个人博客同时部署到 GitHub 和 Coding

    一、将个人博客托管到 GitHub 上 关于如何快速搭建自己的个人博客,如何完善自己的个人博客,什么是 GitHu...

  • 网络编程系列 Hexo + Github搭建个人博客

    1.0 说明 其实,搭建个人博客的技术方案有很多。 其实,你能找到的使用Hexo + Github搭建个人博客的教...

  • 最近的感受

    最近几天都在学习如何在github上面搭建个人博客,免费而且不限流量,非常好。 搭建博客对于一个技术小白来说,其实...

  • 利用wordpress搭建自己的博客——自己搭建博客的经验

    如何利用wordpress搭建属于自己的个人博客 域名的选择要搭建个人博客,首先是域名的选择。我呢,当然是在最有名...

  • 使用hexo 搭建github博客

    使用hexo 搭建github博客 目的: 通过hexo 在github上 搭建一个个人技术博客的网站 我之前已...

  • 说明

    由于某些原因,我决定自己搭建一个博客,我的新博客主要用来做一些技术性的教程,用hexo搭建的(在搭建个人博客方面比...

  • 如何搭建个人博客网站

    如何搭建个人博客网站 Hong 如何搭建个人博客网站 1.服务器的购买 2.域名的购买 3.安装Putty连接服务...

  • vuepress搭建个人技术博客

    vuepress是一个静态网站生成器,由vue驱动的主题系统和api,支持markdown语法,可以利用开发属于自...

网友评论

      本文标题: 我是如何搭建个人技术博客的

      本文链接:https://www.haomeiwen.com/subject/lwdalttx.html