CentOS7安装git-2.17.0并配置使用(总结)

CentOS7安装git-2.17.0并配置使用

一,安装背景:

自己想自动化部署自己服务器上的代码,不想使用传统的 ftp (不方便),网上的资料要么老旧,
要么不怎么全面,不利于自己学习备用,我自己的Windows10上是git-2.17.0版本(同步)

二,安装:

1,环境:oneinstack,安装不安装oneinstack,对于安装 git 没有任何影响

 lnmp ==> CentOS7.2 / mysql-5.7 / php-7.0 / nginx-1.14.0

 软件安装的位置:就在 root目录 下(学习便利,实际看业务需求)

2,安装:

 > git --version   # CentOS 7 一般自带了git,版本较老

( CentOS的弊端,源码库一般较老,可以使用 ubuntu系统 安装,源码库会新一点 )

 >  查找git所在位置: find / -name git

 安装依赖包:

 # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
 # yum install gcc perl-ExtUtils-MakeMaker

 > 卸载git : yum remove git

 > git --version

 1,出现:-bash: /usr/bin/git: No such file or directory

 2,github中拉取重命名为 git-2.17.0.tar.gz

 > wget https://github.com/git/git/archive/v2.17.0.tar.gz -O  git-2.17.0.tar.gz

 > tar -zvxf git-2.17.0.tar.gz

 > cd git-2.17.0

3,编译安装,配置全局变量:

 # make prefix=/usr/local/git all
 # make prefix=/usr/local/git install
 # echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
 # source /etc/bashrc

(1)make prefix=/usr/local/git install 后,出现问题:

LINK git-credential-store
libgit.a(utf8.o): In function `reencode_string_iconv':
/root/git-2.17.0/utf8.c:464: undefined reference to `libiconv'
libgit.a(utf8.o): In function `reencode_string_len':
/root/git-2.17.0/utf8.c:525: undefined reference to `libiconv_open'
/root/git-2.17.0/utf8.c:536: undefined reference to `libiconv_close'
/root/git-2.17.0/utf8.c:530: undefined reference to `libiconv_open'
collect2: error: ld returned 1 exit status
make: *** [git-credential-store] Error 1

(2)解决问题:

 >  cd

 >  wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

 >  tar zxvf libiconv-1.14.tar.gz 

 >  cd libiconv-1.14

 >  ./configure --prefix=/usr/local/libiconv

 >  make && make install

(3)编译libiconv出现错误:

> cd /root/libiconv-1.14/srclib   #下载libiconv的位置

> vi stdio.in.h

:set nu  #对 stdio.in.h

#搜索到所在的位置,大概698行
/_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

i 替换下面的代码,这是软件本身的bug原因:

if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
   _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif

:wq   # 保存并退出

(4)再次编译安装libiconv:

>  cd 

>  cd libiconv-1.14

>  ./configure --prefix=/usr/local/libiconv

>  make && make install

(5)创建一个软链接到/usr/lib

# ln -s /usr/local/lib/libiconv.so  /usr/lib
# ln -s /usr/local/lib/libiconv.so.2  /usr/lib

4,回到git目录继续编译

> cd git-2.17.0

> make configure

> ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv

> make

> make install

> git --version

5,【git --version】 出现 【-bash: /usr/bin/git: No such file or directory】错误

ln -s /usr/local/git/bin/git  /usr/bin/git  #软链一下

出现: git version 2.17.0

注意:安装的位置是可以更换的,git --version不出现要求软链,可以不在 /usr/local/git下编译安装

安装不安装oneinstack,对于安装 git 没有任何影响

make prefix=/usr/local/git all

make prefix=/usr/local/git install

三,git在Linux上的使用:

1,用户名与邮箱,我的是 oneinstack的 /data/wwwroot/下创建项目

 # cd /data/wwwroot/
 # git config --global user.name "Your Name"
 # git config --global user.email "[email protected]"
 # git init
 # git clone 你的github的项目

2,也可以在 Linux上创建项目,提交到 github / 码云

 # cd /data/wwwroot/
 # git config --global user.name "Your Name"
 # git config --global user.email "[email protected]"

 # mkdir your-project  #在服务器中创建your-project文件夹
 # cd your-project
 # git init  #初始化这个目录为git可以管理的仓库

 # vim test.txt
 # i  "hello ,world"    # 编辑文件内容
 # :x  #保存并退出

(1)上传到 github / 码云 ,第一步:

# git add read.txt  #把文件添加到仓库

(2)上传到 github / 码云 ,第二步:

# git commit -m "wrote a read file"

# git remote add origin https://git.oschina.net/username/cccc.git  #和远程仓库进行关联  #第一次这样使用,后面不需要了

# git push -u origin master //上传仓库到码云

之后上传:

# git add .  #添加工程目录下所有文件 (add 和 “.” 之间有空格)
# git commit -m “添加注释信息"
# git push -u origin master #推送要上传的文件

(3)以后使用:

 注意: 拉取代码,要  cd  /data/wwwroot/your-project下

 1、git init 初始化git目录这时你会发现多了一个.git的隐藏文件夹,好了,我们开始添加要上传的项目文件吧

 2、git add 所要上传的源码目录及配置文件

 3、git remote add origin (这里是你刚刚在码云上复制的git地址) 在git创建名为origin的仓库

 4、git pull origin master 从git上获取自动创建的项目概述README.md(这可是个很神奇的文件啊,赶快去自行百度啦)

 5、git add README.md 把本地README.md添加进去

 6、git commit -m "first commit" 把添加的项目文件提交到缓存中等待提交到git

 7、git push -u origin master 好了,来让我们上传项目吧,这里我们要输入自己的码云账号和密码哦。

(4)其他用法,请百度 廖雪峰 廖大神的 git 使用教程

 https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

四,Apache / nginx Linux web应用配置:

参考:https://www.cnblogs.com/yinxiang/p/5298960.html

1,Apache 配置域名(安装我在这里不复述了,我的是oneinstack是一键包;自己搭建服务比较费时间,配置项较多,依赖项较多,以后有机会我会写上一篇介绍的,这里不说了)

1-1,位置:wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf,
  我的项目是laravel,注意  80 端口是否占用(自行百度解决)。

   # Virtual Hosts
   <VirtualHost *:80>
      ServerName www.你的域名.com
      DocumentRoot /data/wwwroot/your-project/public
      <Directory  "/data/wwwroot/your-project/public">
         Options +Indexes +Includes +FollowSymLinks +MultiViews
         AllowOverride All
         Require local
      </Directory>
  </VirtualHost>


 1-2,修改hosts,配置域名     

  # whereis  hosts
    出现:hosts: /etc/hosts /etc/hosts.deny /etc/hosts.allow
  # cd
  # vi /etc/hosts

2,Nginx 配置域名

 2-1,位置:/usr/local/nginx/conf/

  # cd /usr/local/nginx/conf/
  # vi nginx.conf

(1) 原始文件,备份 # vi /usr/local/nginx/conf/nginx.conf

  user www www;
  worker_processes auto;

  error_log /data/wwwlogs/error_nginx.log crit;
  pid /var/run/nginx.pid;
  worker_rlimit_nofile 51200;

  events {
    use epoll;
    worker_connections 51200;
    multi_accept on;
  }

  http {
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 1024m;
    client_body_buffer_size 10m;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 120;
    server_tokens off;
    tcp_nodelay on;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_intercept_errors on;

    #Gzip Compression
    gzip on;
    gzip_buffers 16 8k;
    gzip_comp_level 6;
    gzip_http_version 1.1;

(2) nginx配置多域名的需要,对上面的进行改写

  user www www;
  worker_processes auto;

  error_log /data/wwwlogs/error_nginx.log crit;
  pid /var/run/nginx.pid;
  worker_rlimit_nofile 51200;

  events {
    use epoll;
    worker_connections 51200;
    multi_accept on;
  }

  http {
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 1024m;
    client_body_buffer_size 10m;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 120;
    server_tokens off;
    tcp_nodelay on;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
    fastcgi_intercept_errors on;

    #Gzip Compression
    gzip on;
    gzip_buffers 16 8k;
    gzip_comp_level 6;
    gzip_http_version 1.1;

    ----------------下面是新增,实际使用,本行要删除---------------

    include vhosts/*.conf;

(3)创建 vhosts 位置: /usr/local/nginx/conf

     # mkdir vhosts

(4)在 /usr/local/nginx/conf/vhosts 下创建 xxx.conf

 server {
     listen       80 default;    #监听端口
     server_name  www.A.com;      #绑定域名
     index index.html index.htm index.jsp login.jsp;  #默认文件
     root /data/wwwroot/showhere;   #网站根目录 
     location / 
     {
         proxy_pass http:  //127.0.0.1:8080;
         proxy_redirect off;
         proxy_set_header   Host    $host; 
         proxy_set_header   X-Real-IP   $remote_addr; 
         proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
     }
     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
     {
         expires 30d;
     }

     location ~ .*\.(js|css)?$
     {
         expires 1h;
     }

     access_log  /alidata/log/nginx/access/default.log;
 }

(5)重启nginx: /etc/init.d/nginx restart

 --end

猜你喜欢

转载自blog.csdn.net/gaokcl/article/details/81486062
今日推荐