Ali cloud cloud ECS CentOS server deployment personal website

ping a bit coding pages and Ali cloud server speed, unexpected feeling coding speed but faster. But to toss, or to migrate to the blog Ali cloud, stumbled encounter many pits, mostly because of the instruction and tutorial are not familiar with some of the steps are omitted, the last ever Google finally succeeded!

Purchase student computers

Beginning tangle for a long time the question is: Ali cloud student machine to buy a lightweight application server or cloud server ECS ? Finally, looking at the tutorial bought six months 云服务器ECS& Centos, because this tutorial is a reference configuration.But I regret it, peak bandwidth, the former is the latter five times ah ah ah ah! ! ! Sure enough, a poor person would think to pursue cost-effective, shed tears of the poor ooo, ooo

Ali cloud configuration:

Find cloud host instance (this example is that you buy the ECS server)

Find the host server instance

Find the host server instance

  1. Select the instance in ECS cloud server list.
  2. Then select the server region of your choice when buying a server.
  3. Is your own instance of the server.

Add the security group rules

If you want to use this security system is a set of rules CentOS mirrors must be added.
Simple and clear, with the following four maps to demonstrate the added security set of rules.

Enter the instance management

Enter the instance managementEnter the instance management

Enter the security group configuration rules

Enter the security group configuration rulesEnter the security group configuration rules

Open the rules add the security group

Open the rules add the security groupOpen the rules add the security group

Add the security group rules

Add the security group rules

Add the security group rules

Yes, the configuration is complete, very simple right, but this is just the warm-up, oh, the next step is to build into the theme of the beginning of our trip blog.


Server environment to build

Selecting a remote connection instance

Selecting a Remote Connection

Selecting a Remote Connection

Enter the remote password

Enter the remote password

Enter the remote password

Note: This remote password only the first time it will prompt connected, only the first time it will prompt connected, only the first time it will prompt connected, important things to say three times. Be sure to keep in mind.

Login server

输入密码后就会进到服务器页面,是一个黑色的shell小窗口,之后根据提示登录就可以。
shell窗口中的登录操作就不截图演示了,直接使用文本方式根据步骤来就可以了。
  1.login后面输入用户名。
  2.password后面输入密码。(注意:这里在输入密码的时候为了安全是不会在界面上显示出来的,所以如果你在输入密码的时候没有看到你输入的结果是正常现象,直接输入就可以)

安装git和nodejs

yum install git

#安装Nodejs
curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
adduser git
chmod 740 /etc/sudoers
vim /etc/sudoers

到这里之后会打开一个文本文件,然后找到以下内容

Allow root to run any commands anywhere
root    ALL=(ALL)    ALL

按一下 I 键 进入插入模式然后使用方向键在以上内容的下面添加一行

git ALL=(ALL) ALL

添加完成后按下ESC键退出插入模式,然后输入

:wq

这个命令的意思是保存并退出vim
保存退出后改回权限

chmod 400 /etc/sudoers

随后设置Git用户的密码,

sudo passwd git

然后输入git用户的密码 输入完成之后一路回车等待设置完成之后
切换至git用户,创建 ~/.ssh 文件夹和 ~/.ssh/authorized_keys 文件,并赋予相应的权限

su git
mkdir ~/.ssh
vim ~/.ssh/authorized_keys
然后进入电脑中(你自己的电脑)C:\Users\Administrator\.ssh文件夹下看一下有没有id_rsa.pub文件
如果没有则通过Git Bash新建一个
创建.ssh命令为:ssh-keygen -t rsa -C "[email protected]"
创建好后在C:\Users\Administrator\.ssh文件夹下使用笔记本方式打开id_rsa.pub文件,打开后就能看到公钥了。
然后将公钥复制粘贴到authorized_keys 写入方式和上面在sudoers插入方式一样,完成之后执行下面命令
chmod 600 ~/.ssh/authorzied_keys
chmod 700 ~/.ssh

然后在客户端(电脑上),通过Git Bash执行ssh -v root@ip地址(就是你阿里云的外网地址) ,应该就能免密登陆了。

安装Nginx和配置

安装

yum install nginx

启动 直接输入nginx然后回车就可以启动nginx

nginx

然后把服务器的公网地址输入浏览器, 出现下面的图片就对了,没出来就有问题
nginx starts successfully

nginx启动成功

配置Nginx

vim /etc/nginx/conf.d/default.conf

依照下图进行修改,插入方式往下就不做介绍了,就那几步,如果有不会的可以去百度一下。
img
listen:端口号。
server_name:你自己的域名,如果没有域名可以不填写,然后在访问博客的时候使用你服务器的外网IP地址就可以。
location:地址内容。
root:指向的博客文件夹目录。
index:指定博客Index文件。

配置完成以后保存退出开始执行接下来的内容

sudo mkdir -p /usr/share/nginx/html/blog
sudo chown -R git:git /usr/share/nginx/html/blog

nginx的配置到这里已经完成,接下来就要创建我们自己的私有git仓库了哦

在服务器上初始化一个git仓库

切换到git用户,然后切换到git用户目录,接着初始化裸库,代码如下:

su git
cd ~
git init --bare blog.git

接着新建一个post-receive文件

vim ~/blog.git/hooks/post-receive

然后在该文件中输入以下内容:

#!/bin/sh
git --work-tree=/usr/share/nginx/html/blog --git-dir=/home/git/blog.git checkout -f

这里的 #!/bin/sh 也是要加进去的,不要当成注释从而遗漏掉了哦。

保存退出之后,再输入以下代码,赋予该文件可执行权限。

chmod +x ~/blog.git/hooks/post-receive

好了,到这里我们的服务器配置已经完成。我们先喘一口气休息一下,回过头检查一下有没有遗漏或者出现错误的地方,出现差错到时候可能会导致配置不成功的,要仔细一点哦。

本地Hexo初始化

首先要安装 hexo-cli,安装hexo-cli 需要 root 权限,使用 sudo 运行

sudo npm install -g hexo-cli

然后初始化Hexo程序

cd E:\hexo
hexo init blog

等执行成功以后安装两个插件, hexo-deployer-git 和 hexo-server ,这俩插件的作用分别是使用Git自动部署,和本地简单的服务器。

hexo-deployer-git帮助文档
hexo-server帮助文档
安装hexo-deployer-git 和 hexo-server

cd blog
npm install hexo-deployer-git --save
npm install hero-server

初始化Nodejs

install nodejs

生成自己的第一篇文章 hello world !

hexo new "hello Hexo"

Use hexo new <article name> to create a new article, the command to become a .md file in the root directory hexo source / _posts folder.
Use hexo g render .md files into static files, and then start hexo-server

hexo g
hexo server

Now you can open a browser to access http: // localhost: 4000 to see our blog up!

Then stopped

Configuring _config.yml, complete automated deployment

Then open E: /hexo/_config.yml find deploy

deploy:
    type: git
    repo: root@YOUR_SERVER_IP:/home/git/blog.git       #此处的YOUR_SERVER_IP需改为你自己服务器的ip
    branch: master                                     #这里填写分支
    message:                                           #提交的信息

hexo_config Configuration

hexo_config Configuration

Once saved, we just write "hello hexo" try to deploy to the server

hexo clean
hexo g
hexo s
hexo generate --deploy

Access server address, you can see the articles we write "Hello hexo", just after writing articles:

hexo new "Blog article name"
···写文章
hexo clean
hexo g
hexo s
hexo generate --deploy

Here our blog would be able to use. Now go and experience the fruits of your labor deployment to blog on the go.

Configuring Domain Name

Ali cloud at the DNS - beginners guide - add a host address, you can automatically create two records.

OVER


Problems encountered:

CentOs under nginx configuration file

It is on /etc/nginx/nginx.conf, rather than nginx.default.

mark


Nginx failed to start because the port 80 is occupied.

Use command to close the port occupied by the program 80

sudo fuser -k 80/tcp

or it could be

I first encountered this problem with the Chinese answer to search a bit and found loaded to force everyone to say kill nginx repeat process. I tried finding is nonsense, then looked at Google search to the first page in English, foreigners say that after listening nginx first port 80 of ipv4 and ipv6 monitor port 80, so he repeated occupied. More deceptive is that you went to see it again 80 ports occupy port release, it is not very embarrassing.

The solution is to edit the nginx configuration file

hankcs@ubuntu:~$ sudo gedit /etc/nginx/sites-available/default

Amend this paragraph:

listen 80;listen [::]:80 default_server;

for

listen 80;listen [::]:80 ipv6only=on default_server;

Then start nginx, perfect solution!


ssh login fails

Most of the reason is due to the known_hosts under .ssh directory

47.98.147.134 ecdsa-sha2-nistp256 

Error, delete this section of code.


Tutorial

Guess you like

Origin www.cnblogs.com/senup/p/11974699.html
Recommended