Article directory
- My Hexo blog address
- Mainly in the Tencent cloud server Centos7.9 version, use the pagoda to build the Hexo blog site, build the Hexo blog project locally on Windows, realize local one-click automatic deployment to the server, and have your own blog site
- Centos installs git and configures it, and uses the pagoda to configure the site
- Configure Git
- Linux automated deployment settings
- Build Hexo on Windows, configure automatic deployment
- common problem
My Hexo blog address
If you have any questions, you can leave a message to discuss with each other . My hexo blog address , please do not visit or attack frequently, it is only for learning and reference.
Mainly in the Tencent cloud server Centos7.9 version, use the pagoda to build the Hexo blog site, build the Hexo blog project locally on Windows, realize local one-click automatic deployment to the server, and have your own blog site
Centos installs git and configures it, and uses the pagoda to configure the site
check git version
git --version
install dependencies
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc
yum install gcc perl-ExtUtils-MakeMaker
Uninstall the old version of git
yum remove git
open folder
Used to store downloaded git packages
cd /usr/local/src/
Download the latest version of git compressed package
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.32.0.tar.xz
decompress
tar -xvf git-2.32.0.tar.xz
Switch to the decompressed file directory
cd git-2.32.0
compile
make prefix=/usr/local/git all
A bunch of .o type files will be displayed, indicating that it is compiling from source code. Skip to the " Install " step
without displaying an error
If there is an error collect2: error: ld returned 1 exit status.
The reason is that the gcc version is relatively low, which does not match the required compilation conditions.
Upgrade gcc version (optional)
- install scl source
yum install centos-release-scl scl-utils-build -y
- Make a list of available scl
yum list all --enablerepo='centos-sclo-rh' | grep "devtoolset-"
- Install 8 versions of gcc, gcc-c++, gdb toolchain (toolchian)
yum install devtoolset-8-toolchain -y
- start gcc8
scl enable devtoolset-8 bash
报错:bash: __vsc_prompt_cmd_original: command not found
bash: __vsc_prompt_cmd_original: command not found
Borrow the Solution on stackoverflow
You can test the following method.
Using an editor such as nano or vim, Add the line unset PROMPT_COMMAND to your .bashrc file, and it will take effect on the next session.
To apply the change immediately for the life of the current shell session, type unset PROMPT_COMMAND in your terminal window.
vi ~/.bashrc
for adding unset PROMPT_COMMAND at the end of the line
source ~/.bashrc
Indicates reloading the file .bashrc
Start gcc8 again after execution
scl enable devtoolset-8 bash
Start gcc through the scl command. This is only temporary. When your shell is closed or restarted, the original version will be restored. If you want to use the upgraded version all the time, you can use the following command:
echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
Execute the compile command again and find another error:
reftable/libreftable.a(block.o): In function `block_reader_init':
/usr/local/src/git-2.37.3/reftable/block.c:218: undefined reference to `uncompress2'
collect2: error: ld returned 1 exit status
make: *** [Makefile:3077: t/helper/test-tool] Error 1
This issue cannot be resolved for the time being.
It may be because the git version is relatively new and some new functions are used. It is recommended to install an older version of git
Install
make prefix=/usr/local/git install
Configure environment variables
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile && source /etc/profile
You can also directly write the statement into the corresponding file, and then execute the source command to make it take effect.
vim /etc/profile
Add the following two lines of commands to the end of the profile file
PATH=$PATH:/usr/local/git/bin # git 的目录
export PATH
Press i to enter editing mode, press esc to exit, and press :wq to save the edit.
Make the write statement effective:
source /etc/profile
Check the installed git version
git --version
The successful appearance of git version 2.32.0 means that the installation is successful.
Configure Git
create git user
adduser git
Set user password (optional)
passwd git
assign permissions
chmod 740 /etc/sudoers
vim /etc/sudoers
Press the i key to enter the edit mode of the file, find the following field and
root ALL=(ALL) ALL
add a sentence after it:
git ALL=(ALL) ALL
Press the Esc key to exit the editing mode, and enter :wq to save and exit.
Return permission:
chmod 400 /etc/sudoers
Generate Windows local key
This part is very simple, just search for the ssh configuration of git on Baidu.
configuration key
- Open the local side, that is, the .ssh file folder under the user name folder under the user folder under the C disk directory of your Windows host, and open id_isa.pub
Copy the content inside.
- Return to the Linux server and create a .ssh folder
su git mkdir ~/.ssh
- Create the .ssh/authorized_keys file, open the authorized_keys file and copy the content just copied on the local machine and save it
vim ~/.ssh/authorized_keys
Press i to enter edit mode, press Esc key to exit edit mode after pasting, enter: wq to save and exit.
- Modify permissions
chmod 755 ~ chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
test connection
yourIp is the ip address of the remote server, and the Tencent Cloud lightweight cloud server is generally the public network IP: 12X.XXX.XXX.XX
ssh -v git@yourIp //yourIp为你的服务器ip
If a password is set, enter the password to connect to the remote terminal.
Create a remote blog directory
- Switch to the remote Linux server
- Switch to the root user, create a directory for storing the root directory of the website /home/hexo and assign corresponding permissions
su root mkdir /home/hexo chown git:git -R /home/hexo
Linux automated deployment settings
Linux server configuration
The actual effect to be achieved is that after creating a blog locally, it can be deployed to the server with one click, and when the blog is subsequently modified, it can be synchronized to the server with one click. This is automated deployment.
First, configure the corresponding files on the remote server.
- Get root privileges
su root
- Create a git repository and initialize
cd /home/git git init --bare blog.git
- Modify the permissions of blog.git (-R is recursive, that is, all folders or files under the folder will recursively modify permissions)
chown git:git -R blog.git
- Under /home/git/blog.git, there is an automatically generated hooks folder, we create a new git hook post-receive for automatic deployment.
vim blog.git/hooks/post-receive
- Press the i key to enter the editing mode of the file, add two lines of code to the file (paste the code below), and specify the Git working tree (source code) and Git directory.
#!/bin/bash git --work-tree=/home/hexo --git-dir=/home/git/blog.git checkout -f
Press the Esc key to exit the editing mode, and enter :wq to save and exit.
- Modify the execute permission of the file
chmod +x /home/git/blog.git/hooks/post-receive
Pagoda configuration
Here we use Pagoda's one-key LAMP configuration, and then you can use some functions very conveniently.
add site
- Add the domain name you purchased in the domain name, and make sure that the IP has been resolved to your own Tencent Cloud server. There are many tutorials on the Internet for this step, and you can complete domain name related issues, certificate SSL application, etc., if the domain name has resolution, you can check it directly.
- To add the certificate, you can search on Baidu yourself, and force the https switch to be turned on to ensure security.
- It can be seen that the domain name filled in /www/wwwroot/ of the site directory at this time does not match the root directory location /home/hexo of our actual Hexo blog .
- A feasible solution is to move the hexo folder under /home to the domain name folder filled in /www/wwwroot/, so that we can access our blog by adding /hexo to the domain name, which is www
www.domain.com/hexo
here .domain.com should be changed to the domain name purchased by yourself, the same below - The modification method is as follows:
- Under /home/git, there is an automatically generated hooks folder. Enter this file directory, and we create a new git hook post-receive for automatic deployment.
cd /home/git vim blog.git/hooks/post-receive
- Press the i key to enter the editing mode of the file, rewrite the original two lines of code in the file, change the working tree directory to the pagoda site directory (paste the code below), specify the Git working tree (source code) and Git Table of contents.
#!/bin/bash git --work-tree=/www/wwwroot/www.domain.com/hexo --git-dir=/home/git/blog.git checkout -f
- Press the Esc key to exit the editing mode, and enter :wq to save and exit.
- Pay attention to re-modify the access permissions of the git user to this directory
chown git:git -R /www/wwwroot/www.domain.com/hexo
Build Hexo on Windows, configure automatic deployment
Install Git on Windows
Windows: Go to the git official website to download, Download git, there will be a Git Bash command line tool after downloading, and use this tool to use git in the future.
You can change the Git installation directory to other disks. Generally, the environment variables will be automatically configured during installation. If the command line interface generates the git --version
corresponding git version, it means the installation is successful.
Install Node.js on Windows and initialize Hexo
-
Download the node.js installation program (windows.msi) (it can also be installed on other disks) Similarly, the environment variables will be automatically configured when the program is installed.
-
Enter the following command in the command line interface to install Hexo
$ npm install -g hexo-cli
-
Generally, the cmd interface of Windows is on the C drive. If you want to create a blog directory on another drive, you can jump to other paths first. Type the following command to create a directory named Blog in the current directory
hexo init Blog
-
Go into that folder and execute the install command
cd Blog npm install
After the creation is completed, the specified folder contains:
node_modules: dependent package
public: store generated pages
scaffolds: some templates for generating articles
source: used to store your articles
themes: theme_config.yml
: blog configuration fileInstall the deployment package
npm install hexo-deployer-git --save
-
Start the Hexo service locally
hexo g hexo server
Enter localhost:4000 in the browser to see the generated blog. ctrl+c to close the service
Automatic deployment of Windows local configuration
configure hexo
-
Configure the _config.yml file
Find and open the _config.yml file under the Blog folder, find deploy at the end of the file and do the following configurationdeploy: type: git repo: git@这里改为服务器公网IP:/home/git/blog.git branch: master
Save and exit.
This is where the real deployment begins.cd Blog hexo clean hexo generate hexo deploy
-
cmd to enter the command line interface, first enter your Blog folder.
-
Execute the hexo clean command
-
The hexo generate command can be abbreviated as hexo g just as the previous hexo server can be abbreviated as hexo s
-
The hexo deploy command can be abbreviated as hexo d
-
Under normal circumstances, the local blog can be deployed to the remote server at this time, and this purpose can be achieved by logging in as the git user of the configured remote server, but there may be some strange errors, the most important thing is that the git user There is a problem with the permission of the remote directory to be replaced , and there is a problem with filling in the paths of some configuration files . Below are some common mistakes to be solved uniformly.
common problem
Question 1
hexo automated deployment shows Permission denied or permission issues
Solution 1:
Modify the file permissions of the working directory and the git directory by executing the chmod command on the server side,
which is similar to
chown git:git -R /www/wwwroot/www.domain.com/hexo
The last parameter is the modified folder directory, and -R means recursive, that is, all things under the folder have permission to modify.
Solution 2:
You can directly access the deployment remote server as the root user, that is, modify the repo parameter of deploy in _config.yaml under the local Blog folder.
deploy:
type: git
repo: root@这里改为服务器公网IP:/home/git/blog.git
branch: master
Question 2
The page built by the server has no pictures, css and other styles
Solution :
You can view the source code of the blog page and find out what the link referenced by the url is under example.com. Obviously, you need to make some changes here. Instead of directly changing the source code, change the content in the _config.yaml file of the local blog and deploy again Just upload it.
Find the url parameter under the configuration file, and change the content to http://public network ip/hexo or https://www.domain.com, which is actually the site added by the pagoda (/www/wwwroot/ The resources under the /hexo folder under the domain name).
url: https://www.domain.com/hexo
Re-execute the three deployment commands
hexo clean
hexo g
hexo d
At this time, the format and pictures can be displayed on the server normally.
Question 3
Apache virtual directory configuration
Because I modify the configuration too frequently, it is difficult to remember what the Apache configuration file has been changed to now, so you may have some problems in the Apache configuration of the pagoda.
But I remember that the configuration files related to the virtual directory have been written when Apache is installed on the pagoda
Solution :
In the pagoda panel->software store, click configuration modification in Apache settings, Ctrl+F to find, enter follow, you can see the location in the figure below
Modify it as shown in the figure.
<Directory />
Options FollowSymLinks
AllowOverride none
Require all granted
</Directory>
The same effect can be achieved by replacing Options FollowSymLinks with Options Indexes FollowSymLinks, but at this time, visitors can also access the file resources in the virtual directory, which is equivalent to directly exposing part of the source code. It is not recommended to modify the configuration with Indexes.
After that, you can access the blog built on the server locally through https://domain name/hexo.
Question 4
firewall problem
Solution :
Generally, the local firewall does not need any settings, it may only be a problem with the server firewall.
Generally, these ports should be opened in the pagoda panel or command line interface
If the problem of port release cannot be solved, temporarily close the firewall to test the website access.