部署Git版本控制系统 | 优化Web服务器

部署Git版本控制系统 | 优化Web服务器

前序文章: https://blog.csdn.net/shengweiit/article/details/135193074

部署Git版本控制系统

部署git版本控制系统,管理网站代码

  • 基于ssh协议的服务器
  • 基于git协议的服务器
  • 基于HTTP协议的服务器
  • 上传代码到版本库

1.部署SSH协议的版本控制服务器

1. 安装软件包,创建空仓库

shell 复制代码
[root@database ~]# yum -y install git
[root@database ~]# mkdir /var/lib/git/
[root@database ~]# git init --bare /var/lib/git/wordpress.git        #创建空仓库

2. 登陆web1服务器克隆git仓库,上传网站代码到git服务器

shell 复制代码
[root@web1 var]# git config --global push.default simple
[root@web1 var]# git config --global user.email you@example.com
[root@web1 var]# git config --global user.name "Your Name"
[root@web1 var]# cd /var/
[root@web1 var]# git clone root@192.168.2.21:/var/lib/git/wordpress.git
[root@web1 var]# cd /var/wordpress
[root@web1 wordpress]# cp -a /usr/local/nginx/html/*  ./
[root@web1 wordpress]# git add .
[root@web1 wordpress]# git commit -m "wordpress code"
[root@web1 wordpress]# git push
root@192.168.2.21's password:<输入192.168.2.21主机root的密码>

2.部署Git协议的版本控制服务器

1.安装软件包(192.168.2.21操作)

shell 复制代码
[root@database ~]# yum install -y git-daemon

2.修改配置文件,启动git服务

shell 复制代码
[root@database ~]# cat /usr/lib/systemd/system/git@.service
#仅查看即可
[root@database ~]# systemctl start git.socket
[root@database ~]# systemctl status git.socket

3.客户端测试(使用web2做客户端主机)

shell 复制代码
[root@web2 ~]# cd /var/
[root@web2 var]# git clone git://192.168.2.21/wordpress.git

3.部署HTTP协议的版本控制服务器

1.安装软件包(在192.168.2.21操作)

shell 复制代码
[root@database ~]# yum -y install httpd gitweb

2.修改配置文件

shell 复制代码
[root@database ~]# vim /etc/gitweb.conf
$projectroot = "/var/lib/git";                        #添加一行

3.启动服务

shell 复制代码
[root@database ~]# systemctl start httpd

4.客户端验证

shell 复制代码
火狐浏览器访问 firefox http://192.168.2.21/git

访问网页可以查看到wordpress仓库,点击tree菜单后可以看到如图-2所示的代码。

优化web服务器(优化服务器的思想 优化手段很多)

优化web服务器

  • 自定义网站404错误
  • 升级nginx至1.15.8,开启status模块
  • 编写日志切割脚本 实现每周五备份日志
  • 开启gzip压缩功能,提高数据传输效率
  • 开启文件缓存功能

自定义404错误页面

修改Nginx配置文件,自定义错误页面

shell 复制代码
[root@web1 ~]# vim /usr/local/nginx/conf/nginx.conf         
error_page   404  /404.html;    //自定义错误页面
[root@web2 ~]# vim /usr/local/nginx/conf/nginx.conf         
error_page   404  /404.html;    //自定义错误页面
[root@web3 ~]# vim /usr/local/nginx/conf/nginx.conf         
error_page   404  /404.html;    //自定义错误页面

重启

shell 复制代码
[root@web1 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@web2 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@web3 ~]# /usr/local/nginx/sbin/nginx -s reload

升级nginx版本 开启status模块

平滑升级:在不停止服务的情况下同时升级软件的版本

1. 配置 编译新的nginx(web1、web2、web3做相同操作,下面以web1为例)

shell 复制代码
[root@web1 ~]# tar  -xf   nginx-1.15.8.tar.gz
[root@web1 ~]# cd  nginx-1.15.8
[root@web1 nginx-1.15.8]# ./configure     \
--with-http_ssl_module         \
--with-http_stub_status_module
[root@web1 nginx-1.15.8]# make

2. 备份老版本nginx,更新新版本nginx

shell 复制代码
[root@web1 nginx-1.15.8]# mv /usr/local/nginx/sbin/nginx{,.old}
[root@web1 nginx-1.15.8]# cp objs/nginx  /usr/local/nginx/sbin/

3. 升级

shell 复制代码
[root@web1 nginx-1.15.8]# make upgrade # 一定要在源码目录下

总结:

解压源码软件

进入源码目录

进入旧软件安装配置项

执行配置

编译 并拷贝高版本软件包提供的启动命令nginx到nginx的安装目录下

平滑升级

编写日志切割脚本

在nginx服务的目录下 有两种日志文件

访问日志文件 access.log

错误日志文件 error.log

编写脚本

shell 复制代码
[root@web1 ~]# vim /usr/local/nginx/logbak.sh
#!/bin/bash
date=`date +%Y%m%d`
logpath=/usr/local/nginx/logs
mv $logpath/access.log $logpath/access-$date.log
mv $logpath/error.log $logpath/error-$date.log
kill -USR1 $(cat $logpath/nginx.pid) # 创建新的日志文件
# -USR1 如果服务没有日志文件的话就创建日志文件 反之 什么都不做
# 给权限
chmod -x /usr/local/nginx/logbak.sh

创建计划任务

shell 复制代码
[root@web1 ~]# crontab -e
03 03 * * 5  /usr/local/nginx/logbak.sh # 每周五的三点三分

对页面进行压缩处理

网站服务器 在把用户访问的页面传递给客户端之前 先对页面做压缩 再传递给客户端

shell 复制代码
[root@web1 ~]# cat /usr/local/nginx/conf/nginx.conf
http {
.. ..
gzip on;                            //开启压缩
gzip_min_length 1000;                //小文件不压缩
gzip_comp_level 4;                //压缩比率
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
                                    //对特定文件压缩,类型参考mime.types
.. ..
}

服务器内存缓存

把网站经常被访问的页面加入缓存

shell 复制代码
http { 
open_file_cache          max=2000  inactive=20s;
        open_file_cache_valid    60s;
        open_file_cache_min_uses 5;
        open_file_cache_errors   off;
//设置服务器最大缓存2000个文件句柄,关闭20秒内无请求的文件句柄
//文件句柄的有效时间是60秒,60秒后过期
//只有访问次数超过5次会被缓存
} 
相关推荐
keep090127 分钟前
git revert和git reset工作中使用
git
YCyjs31 分钟前
web基础与HTTP协议
linux·运维·服务器·网络·网络协议·http·云计算
变成我1 小时前
LVS-DR模式集群:案例与概念
linux·运维·服务器·网络·ip
Lill_bin1 小时前
ES相关介绍与扫盲
大数据·运维·服务器·elasticsearch·搜索引擎·全文检索·jenkins
ssg183365439741 小时前
LVS-DR集群的部署
linux·服务器·lvs
与苟富贵1 小时前
部署LVS-DR群集
linux·服务器·lvs
抛物线.1 小时前
Kdump 原理分析及场景案例分析
linux·服务器·数据库
小小低头哥1 小时前
RabbitMQ-高级
服务器·rabbitmq·php
一只脑洞君3 小时前
Liunx---批量安装服务器
linux·运维·服务器
程序员iteng3 小时前
需求开发全流程
java·git·spring