1.更新源
sudo apt update
2.安装gcc gcc-c++
sudo apt install build-essential
3.安装PCRE库
cd /usr/local/ wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz tar -xvf pcre-8.37.tar.gz cd pcre-8.37 ./configure make && make install pcre-config --version
4.安装Nginx常见依赖gcc,zlib,pcre,openssl安装
gcc $ sudo apt-get install gcc zlib $ sudo apt-get install zlib1g-dev pcre $ sudo apt-get install libpcre3 libpcre3-dev openssl $ sudo apt-get install openssl libssl-dev
另外:使用centOs,可以使用yum来下载依赖,Ubuntu只能使用以上方法
4安装nginx
安装nginx一定要在local文件夹下
cd /usr/local/ wget http://nginx.org/download/nginx-1.21.4.tar.gz tar -zxvf nginx-1.21.4.tar.gz cd nginx-1.17.9 ./configure make && make install
2.安装Git以及Node.js
2.1安装Node.js
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt-get install -y nodejs
查看是否成功
node -v npm -v
可以显示版本号即为成功
2.2安装Git及配置仓库
安装git及新建git用户
sudo apt-get install git adduser git chmod 740 /etc/sudoers vim /etc/sudoers
在如下位置添加
git ALL=(ALL:ALL) ALL
vim指令执行之后按i进入输入模式
编辑完成之后按一下esc
然后输入:wq即可退出
执行以下指令更改文件夹权限
chmod 400 /etc/sudoers sudo passwd git
切换git用户并且建立密钥
su git cd ~ mkdir .ssh cd .ssh vi authorized_keys chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
创建git仓库
cd ~ git init --bare blog.git vim ~/blog.git/hooks/post-receive
输入
git --work-tree=/home/www/website --git-dir=/home/git/blog.git checkout -f
保存退出
chmod +x ~/blog.git/hooks/post-receive
*以上指令都需要在su git 之后执行 如果中途断开重新连接过,需要重新执行 su git指令 进入git账户。
新建/home/www/website文件夹
在root用户下执行,所限先su root切换为root账户
su root
输入密码
cd /home mkdir www cd www mkdir website
修改文件夹权限 这步很重要 视频中没有提及
chmod 777 /home/www/website chmod 777 /home/www
在本地电脑输入
ssh -v git@服务器的公网ip
返回如下则成功。
修改本地配置文件
repo: git@这里改为服务器公网IP:/home/git/blog.git
$ hexo d
ERROR Deployer not found: git
npm install --save hexo-deployer-git
即可
写入启动脚本
在/etc/init.d/路径下添加脚本文件,名称为nginx,内容如下
#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
然后执行
控制指令
启动service nginx start
停止service nginx stop
重启service nginx reload



