存档十一月 2020

Gitlab 搭建




Gitlab 搭建


    # yum install curl policycoreutils-python openssh-server
    # yum install postfix

    # wget https://d20rj4el6vkp4c.cloudfront.net/7/8/el/7/package_files/60918.rpm?t=1606710995_a8be4bf75bf4f234e99360afe8be8bf095276ce5
    # rpm -ivh gitlab-ce-13.6.1-ce.0.el7.x86_64.rpm
    # vim /etc/gitlab/gitlab.rb
        external_url 'http://192.168.10.13:80'
        unicorn['port'] = 80
    # gitlab-ctl reconfigure   \\ 安装   慢
    # gitlab-ctl restart
        # gitlab-ctl status      \\ 查看服务状态:
        # gitlab-ctl start        \\ 开启服务: 
        # gitlab-ctl stop          \\ 关闭服务:

    http://192.168.10.13/
        12345678                      \\ 修改密码 用户名root


    # git clone http://gitlab.stagingvip.net/louis/vpnadmin.git                             \\ 拉取远程 默认主分支
    # git clone -b croce http://gitlab.stagingvip.net/louis/vpnadmin.git                     \\ 拉取远程 -b 分支
    # git clone -b croce http://online:solaris###@gitlab.stagingvip.net/louis/vpnadmin.gitlab \\ 加入用户名 密码
    # git pull                                               \\ 在项目中执行 默认拉取 主分支


    注: https://packages.gitlab.com/gitlab/gitlab-ce            \\ 下载地址 ce社区版本 ee企业版收费
        gitlab-ce-13.6.1-ce.0.el7.x86_64.rpm
        git 仓库
        github 在线
        gitlab 自己搭建
        https://git-scm.com/book/zh/v2  官方文档
        头像 --> Settings --> Preferences --> Language

        使用 ssh 方式 拉 代码 流程
            # git clone git@172.21.34.204:gitlab-instance-6e5786b9/monitoring.git

            ssh 方式 是 在安装gitlib的时候会自动创建名字为git的用户 使用此用户名登录服务器 如果不创建秘钥 会提示输入密码 
            有的服务器即使创建秘钥也会提示输入密码 是因为 创建git的时候 没有密码 系统会自动 锁住 此用户 不允许登录 解除锁定即可

            # passwd -S git           \\ 查看git 用户的状态 是否被锁住   如果提示 locked 则被锁定住
                git LK 2020-12-18 -1 -1 -1 -1 (Password locked.)
            # passwd -l git              \\ 锁定 git 用户   不能登录
            # passwd -u -f git            \\ 解锁 git 用户  如果设置密码 -u即可  -f为强制此用户密码为空的时候使用

            # passwd -d git                 \\ 移除 git 用户的密码 使之为空
            # awk -F ':' '{if($2=="") print $0 }' /etc/shadow   \\ 查看系统上 所有的 空密码 的用户

yum 安装 git

    # yum install git-all
    # git --version           \\ yum 安装的版本为 1.8.3.1


编译 安装 git 并 添加 git 命令补全

    # yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
    # wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
    # tar -zxvf git-2.9.5.tar.gz
    # cd git-2.9.5
    # ./configure --prefix=/usr/local/git          \\ 安装路径
    # make && make install
    # cd git-2.9.5/contrib/completion/               \\ 加入命令行 补全功能
    # cp git-completion.bash ~/.git-completion.bash   \\ 复制到root 家目录下
    # source ~/.git-completion.bash
    # yum remove git                                    \\ 删除老版本
    # vim /etc/profile                                   \\ 加入的环境
        GIT_HOME=/usr/local/git
        export PATH=$PATH:$GIT_HOME/bin
    # source /etc/profile
    # git version


git 命令补全
    # wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
    # tar -zxvf git-2.9.5.tar.gz
    # cd git-2.9.5/contrib/completion/               \\ 加入命令行 补全功能
    # cp git-completion.bash ~/.git-completion.bash   \\ 复制到root 家目录下 只需要一个文件即可
    # source ~/.git-completion.bash


修改 gitlib 的 root的密码
    # su - git                                \\ 需要 使用 git 用户操作
    # gitlab-rails console production          \\ 进入gitlab控制台  如果报错使用下面的命令 版本的事
        # gitlab-rails console -e production

    > user = User.where(username:"root").first   \\ 查看 root 用户
        => #<User id:1 @root>
    > user.password = "12345678"                   \\ 修改密码
        => "12346578"
    > user.save!                                     \\ 保存  登录即可
        => true


创建用户/秘钥/群组/项目

    1  管理中心 --> 用户 --> 新用户
    2  管理中心 --> 群组 --> 新建群组
                        --> test --> 将用户加入群组  加入刚创建的用户
                                 --> 管理权限
    3  管理中心 --> 新建项目 --> 
    # ssh-keygen
    # cat id_rsa.pub                \\ 复制公钥 到 gitlib上  在gitlib上的公钥其实是 服务器上用于登录git用户的
    创建用户 --> 创建组 --> 创建项目 --> 添加公钥
    设置 --> SSH秘钥   添加进去公钥


使用

    创建新的 仓库
        # git init watch_git_objects


    基础使用
        # git config --list             \\ 查看 所有配置
        # git config --list --local      \\ 查看 当前仓库的配置

        # git config --global user.name 'teooo1'                  \\ 创建 全局的 用户名
        # git config --global user.email 'teooo1@kok.work'         \\ 创建 全局的 邮箱
        # git config --global --list                                \\ 查看 所有配置

        # git init  git_learning                                      \\ 创建项目 创建仓库
        # cd git_learning
        # git config --local user.name 'katana'
        # git config --local user.email 'katana@kok.work'
        # git config --local --list

        # touch aa.sh                        \\ 创建文件
        # git add aa.sh                       \\ 提交管理 把文件放到暂存区 对于新创建的文件需要执行
        # git status                           \\ 查看工作区代码相对于暂存区的差别,
        # git commit -m 'add aa.sh'             \\ 将暂存区的代码提交到本地版本库  -m 注释 
        # git log                                \\ 日志 可以查看 提交的日志
        # git add -u                              \\ 提交 已经管理的所有文件
        # git log                       \\ 查看所有操作          

        # git rm bb.sh                    \\ 从暂存区 删除
                                           \\ 每一次更改文件 都要执行 git add  和 git commit -m 'a'
        # mv aa.sh bb.sh
        # git mv aa.sh bb.sh                 \\ 重名文件之后

        # git config --global color.ui true    \\ 开启 颜色 显示
        # git config --global color.ui false    \\ 关闭 颜色 显示
        

    新建文件
        # echo "aaa" aa.txt         \\ 创建文件
        # git add aa.txt             \\ 提交管理 把文件放到暂存区 对于新创建的文件需要执行
        # git status                  \\ 查看工作区代码相对于暂存区的差别,
        # git commit -m 'add aa.txt'   \\ 提交 -m 注释
        # git log                       \\ 日志 可以查看 提交的日志
        # git push                       \\ 上传

        # git add -u                       \\ 添加 已经管理的所有文件
        # git log                           \\ 查看所有操作   提交的历史  commit 历史    

        # git branch            查看本地的所有分支  结果列表中前面标*号的表示当前使用分支
        # git branch -a         查看本地和远程分支 

        # git add .         \\ 将当前目录下修改的所有代码从工作区添加到暂存区 . 代表当前目录


    修改commit -m注释

        # git commit -m 'add aa.txt'   \\ 提交 -m 注释
        # git commit --amend            \\ 对最近一次 提交的  注释 做变更
                hahha i want add aa.tx
        # git rebase -i f436453fb3        \\ 修改任意一次 提交的 这里的commit号要选择 要变更的 父亲号     
            reword 480b430 add aaaaaa from aa.sh          \\ 在要修改的 pick 改成 reword 保存退出 后有新窗口
            pick 8b96cc2 may an add bb.sh                  \\ 在新窗口中 修改 即可 保存退出
        # git log


    合并 连续的 commit 
        # git log
        # git rebase -i f436453fb37a112ac30ed438f17e      \\ 找出想要合并的 父
            pick 480b430 add aaaaaa from aa.sh
            squash 8b96cc2 may an add bb.sh  \\ 把pick 改成 squash ..把想要合成的都改成squash 会合并第一个新窗口添加合成的注释


    重命名
        方法一:
            # mv aa.txt readme.md
            # git add readme.md
            # git rm aa.txt            \\ 删除文件也需要 添加到 git 管理
            # git status


        方法二:
            # git mv aa.txt readme.md                   \\ 重命名文件
            # git commit -m 'move aa.txt to readme.md'   \\ 提交
            # git log                                     \\ 查看 提交的历史


        退回 修改前的状态
            # git reset --hard       \\ 清理 工作区 暂存区  就是 返回到上一次 commit提交 时的状态
            # git status
                nothing to commit, working directory clean     \\ 


    日志 git log

        # git log --oneline      \\ 查看 commit提交 的 列表
        # git log -n4 --oneline   \\ 查看 最近的4条
        # git log --all            \\ 查看所有的分支的  commit提交历史
        # git log --all --graph     \\ 带父子关系的 方式
        # git log --oneline --all
        # git log --oneline --all --graph
        # git log --oneline --all -n4
        # git log --oneline --all -n4 --graph
        # gitk                                    \\ 图形化 界面


    新建分支
        # git branch -v                \\ 查看本地有多少分支
            katana 568f2c6 [ahead 3] move aa.txt to readme.md
            master 80455b3 add aa.txt bbbb
        # git checkout -b teo1 568f2c6    \\ 创建 新分支 基于  commit的 号
        # vim readme.md                    \\ 随便修改一个文件
        # git commit -am 'add teo1.txt'     \\ -am 直接 提交


    删除分支
        # git branch                \\ 查看当前分支
        # git branch -D teo1         \\ 删除其中一个分支


    .git目录
        # cat HEAD
            ref: refs/heads/teo2   \\  当前 分支
        # cat config                \\ 存放 配置信息


    commit tree blob 之间的关系
        commit 类似快照
        tree   文件夹
        blob   文件

        # git log --oneline
        # git cat-file -p 72336cc                               \\ 查看 commit
            tree bef6b64f1d2f94f34d4d9f7f08bc7c097a8fa411
        # git cat-file -p bef6b64f1d                              \\ 查看 tree
            100644 blob 0424fdec972ca33304849cabd357fa17def89797    teo.stash
        # git cat-file -p 0424fdec972ca                             \\ 查看 blob


    比较两个分支的差异
        # git diff master teo1             \\ 比较 两个 分支的 差异
        # git diff master teo1 -- aa.txt   \\ 只比较 new.txt 文件

        # git branch -av             
        # git diff 005f79a c92c1a9                \\ 比较两个分支的 差异 可以 使用对应的 commit
        # git diff 005f79a c92c1a9 -- aa.txt      \\ 只比较 aa.txt 文件


    恢复 暂存区 到 HEAD 的状态
        # git reset HEAD           \\ 恢复 暂存区 到 HEAD 的状态 ...删除所有暂存区
        # git reset HEAD -- aa.sh   \\ 把文件 aa.sh 恢复 到 HEAD的状态  ...


    恢复工作区 到 暂存区的状态
        # git checkout -- mayan.sh    \\ 恢复工作区 到 暂存区的状态 ... 删除所有 未 add 的改变 恢复 mayan.sh 文件
        # git reset --hard HEAD        \\ 是将工作区、暂存区和HEAD保持一致    只能恢复已经添加过的文件 新建的恢复不了


    恢复文件到 commit的状态     删除 后面所有的 commit 
        # git log --oneline
        # git reset --hard f436453fb3


    删除文件
        # rm aa.sh          \\ 本机删除
        # git rm aa.sh       \\ 添加到git 管理

        # git rm aa.sh         \\ 直接使用git 就可以


    堆栈空间
        # git stash list     \\ 查看 现在 堆栈空间     可以理解 查看有哪些 快照
        # git stash           \\ 把现有文件 已经添加到管理的(add之前的和commit之前的) 保存到 堆栈空间   可以理解快照  
                               \\ 同时恢复文件到 commit提交时 新建文件不会在此列
            stash@{0}: WIP on teo1: c92c1a9 teo1 add new.txt    \\ {0} 为每次存储的最新的 依次往后推
        # git stash apply       \\ 恢复 默认恢复最新的{0}
        # git stash pop          \\ 恢复 并删除 默认恢复最新的{0}

        # git stash pop stash@{2}  \\ 恢复 指定 原始的


        # git stash clear            \\ 删除所有的 stash


    把本地仓库 push 到 远端

            # git remote -v               \\ 显示所有远程仓库
            # git remote add aaa git@192.168.10.13:root/git_learning.git          \\ 新增远端git仓库  自定义aaa 仓库的别名
            # git remote -v
                aaa git@192.168.10.13:root/git_learning.git (fetch)                \\ fetch 拉
                aaa git@192.168.10.13:root/git_learning.git (push)                  \\ push 放到远端
            # git push aaa --all                                                     \\ 把本地 放到远端  --all 所有仓库
            # git fetch                    \\ 只拉  不会关联
            # git fetch --all
            # gitk --all                     \\ 查看所有分支
            # git merge origin/master         \\ 合并 远端仓库 和 本地master仓库
            # git push

            # git pull    \\ 先拉  后 把远端和本地的做 合并    git pull = git fetch + git merge


    不同人修改了不同文件如何处理

        1. a把本地仓库 同步到远端  (远端仓库为空)     实现创建仓库
            首先在gitlib网页上新建仓库 project_2020.12.11
            # cd /data
            # mkdir project_2020.12.11                          \\ 新建项目
            # cd project_2020.12.11
            # git init                                            \\ 新建 仓库
            # git config --list                                    \\ 查看 所有配置
            # git config --list --local                             \\ 查看 当前仓库的配置
            # git config --add --local user.name 'katana'
            # git config --add --local user.mail 'katana@kok.work'
            # echo "# Linux_base" >> README.md                       \\ 新建测试文件
            # git add README.md
            # git commit -m 'add README.md'
            # git branch -av                                                     \\ 查看分支
            # git remote add origin git@192.168.10.13:root/project_2020.12.11.git \\ 添加远程仓库 origin别名而已 后面是地址
            # git remote -v                                                        \\ 分支名是可以修改的
            # git push origin master  \\ 将本地版本库推送到远程服务器 origin是远程主机 master表示是远程服务器上的master分支
        2. b在分支上 拉取 代码   实现创建仓库
            在gitlib网页上创建分支 katana
            # cd /data/
            # git clone git@192.168.10.13:root/project_2020.12.11.git project_2020.12.11_02     \\ 拉取到 指定目录
            # git config --list --local
            # git config --add --local user.name 'katana'
            # git config --add --local user.mail 'katana@kok.work'
            # git branch -av
            # git checkout -b katana origin/katana        \\ 基于远端的katana分支 创建本地分支katana 同时切换到katana分支
            # git branch -v
            # vim README.md
            # git add -u
            # git status
            # git commit -m'add git commands description in README.md'
            # git push
        3. a拉取 katana分支 并且使用
            # cd /data/project_2020.12.11
            # git config --local -l
            # git branch -av
            # git fetch origin                      \\ 拉取所有的 oringin 下的分支  oringin 为新建的别名 指的是远程端的仓库
            # git branch -av                         \\ 会拉取到 katana分支
            # git checkout -b katana origin/katana    \\ 基于远端的katana分支 创建本地分支katana 同时切换到katana分支
            # git branch                               \\ 已经 切换到katana分支
        4. b修改文件 并上传到gitlib仓库
            # cd /data/project_2020.12.11_02
            # vim README.md
            # git add -u
            # git commit -m'fix readme.md'
            # git push
        5. a修改文件 发现上传报错 把本地和远端合并 之后 上传
            # cd /data/project_2020.12.11
            # git branch -av
            # vim aa.sh
            # git add aa.sh
            # git commit -m'add ss.sh'
            # git push                                  \\ 会报错 提示 不是 fast-forwards 这是远端文件 已经修改 不能再同步
                ce23a47..da3d7b8  katana     -> origin/katana  \\ 老的commit ce23a47 变成了da3d7b8

            # git fetch origin                 \\ 更新远端的文件 可发现 commit已经改变 
            # git branch -av                                          \\ behind 1 代表 远端有一个commit比 本地新
                * katana   ca836b0 [ahead 1, behind 1] fix README.md   \\ ahead 1 代表本地的commit比远端的新 
            # git merge origin/katana            \\ 合并 katana 分支
            # git push


    不同人修改了相同文件如何处理
        6. b修改文件 并上传到gitlib仓库
            # git pull
            # vim aa.sh
            # git add -u
            # git commit -am'fix3 aa.sh'
            # git push
        7. a修改文件 发现上传报错 把本地和远端合并 之后 上传
            # vim aa.sh
            # git add -u
            # git commit -am'fix4 aa.sh'
            # git push
            # git fetch origin
            # git branch -av
            # git merge origin/katana
            # vim aa.sh
                eeeeeeeeee     333333333333
                <<<<<<< HEAD                            \\ 此为不一样的区域     标记而已 修改完删除
                zzzzzzzzzzzzz   44444444444
                =======                                  \\ 删除
                hhhhhhhhh
                >>>>>>> origin/katana                     \\ 此为不一样的区域    标记而已 修改完删除
            # git add -u
            # git commit -am'fix5 aa.sh'
            # git commit -am'fix5 aa.sh'
            # git branch -av
                * katana                fdf5f7c [ahead 2] fix5 aa.sh     \\ ahead 2  只有此状态 可以直接提交
            # git push

    同时变更了文件名和文件内容如何处理
        8. b修改文件名 并上传到gitlib仓库
            # git pull
            # git mv aa.sh cc.sh
            # git add -u
            # git commit -am'mv aa.sh'
            # git push
        9. a修改文件 发现上传报错 把本地和远端合并 之后 上传
            # vim aa.sh
            # git add -u
            # git commit -am'mv aa.sh'
            # git push
            # git fetch origin
            # git branch -av
            # git pull
            # git push
            # git branch -av
    把同一文件改成了不同的文件名如何处理
        10 b修改文件名 并上传到gitlib仓库
            # git pull
            # git mv teo3.sh teo4.sh
            # git -am'mv teo3 teo4'
            # git commit -am'mv teo3 teo4'
            # git push
        11 a修改文件名 并上传到gitlib仓库
            # git pull
            # git mv teo3.sh teo5.sh
            # git commit -am'teo3 teo5'
            # git push
            # git branch -av
            # git fetch
            # git status
            # git pull
            # ls                 \\ 会发现有同事有 teo4 teo5 文件
            # git status          \\ 会有 三条 未解决  依次解决就好
            # git rm teo3.sh
            # git status
            # git add teo5.sh
            # git statu        
            # git rm teo4.sh
            # git status
            # git commit -m'teo5'
            # git push
            # git branch -av


    关于分离头指针            \\ 基于commit 切换分支的时候 会出现 未保存的 状态  如果想要保存 要新建分支以用来保存
        # git branch -av
            fix_css               77f2ac2 dd.sh
            * katana                573ba04 teo5
            master                9ebe57b add README.md
            remotes/origin/HEAD   -> origin/master
            remotes/origin/katana 573ba04 teo5
            remotes/origin/master 9ebe57b add README.md
        # git log --oneline
            7b272d0 Merge branch 'katana' of 192.168.10.13:root/project_2020.12.12 into katana
            32df047 a
            eb71ea9 a
        # git checkout b2fd236                 \\ 基于某一个 commit 切换 称为 分离头指针
        # git branch -av
            * (detached from b2fd236) b2fd236 a         \\ 此为分离头指针的状态
              katana                  573ba04 teo5
        # vim dd.sh                                 \\ 创建新文件
        # git add dd.sh
        # git commit -am'dd.sh'
        # git branch -av
            * (detached from b2fd236) 13f3dfd aaaa
            fix_css                 77f2ac2 dd.sh
        # git branch tmp 13f3dfd                      \\ 新建tmp 分支 以保存刚刚的 commit
        # git branch -av
            * (detached from b2fd236) 13f3dfd aaaa
            katana                  573ba04 teo5
            tmp                     13f3dfd aaaa        \\ 已保存到 新建的tmp 分支


git pull 拉取文件 提示本地文件 被修改 处理方法

    1 放弃单个文件
        # git pull                                          \\ 会提示 bb.txt 本地修改过
            error: Your local changes to the following files would be overwritten by merge:
                bb.txt
            Please, commit your changes or stash them before you can merge.

        # git branch -av                                         \\ 查看所有分支的状态     本地和远端的 commit 不一样
            * katana                23616c7 [behind 1] fix bb.txt
              remotes/origin/katana 53a1c98 fix3 bb.txt
        # git checkout -- bb.txt                                   \\ 放弃单个文件的修改
        # git pull



git 常用命令

    # git branch 命令
        查看分支
            # git branch     不带参数 列出本地已经存在的分支 并且在当前分支的前面用"*"标记
            # git branch -v  详细信息
            # git branch -r  查看远程版本库分支列表
            # git branch -a  查看所有分支列表 包括本地和远程
            # git branch -vv 可以查看本地分支对应的远程分支

            # git branch -av 查看所有分支

        创建 删除 分支
            # git branch tmp            创建名为tmp的分支 创建分支时需要是最新的环境 创建分支但依然停留在当前分支
            # git branch -d tmp         删除tmp分支,如果在分支中有一些未merge的提交,那么会删除分支失败,此时可以使用 -D
            # git branch -D tmp2        强制删除tmp分支
            # git branch -m tmp tmp2    给分支重命名

    # git checkout 命令
        操作文件
            # git checkout a.txt    放弃单个文件的修改
            # git checkout .        放弃当前目录下的修改
        操作分支
            # git checkout master    将分支切换到master
            # git checkout -b master 如果分支存在则只切换分支,若不存在则创建并切换到master分支
                                     repo start是对git checkout -b这个命令的封装 将所有仓库的分支都切换到master master是分支名

    # git add 命令           . 来标识路径, . 表示当前目录,路径可以修改,下列操作的作用范围都在版本库之内。
        git add .         不加参数默认为将修改操作的文件和未跟踪新添加的文件添加到git系统的暂存区,注意不包括删除
        git add -u .      表示将已跟踪文件中的修改和删除的文件添加到暂存区,不包括新增加的文件,注意这些被删除的文件被加入
                          到暂存区再被提交并推送到服务器的版本库之后这个文件就会从git系统中消失了。
        git add -A .      表示将所有的已跟踪的文件的修改与删除和新增的未跟踪的文件都添加到暂存区。


    # git commit 命令
        主要是将暂存区里的改动给提交到本地的版本库。每次使用git commit 命令我们都会在本地版本库生成一个40位的哈希值也叫commit-id,

        # git commit                  会调用一个vim编辑器 来让你输入提交的 注释信息
        # git commit -m 'add a.txt'   -m 直接指明注释信息 
        # git commit -am 'add a.txt'  -a 所有已跟踪文件中的  修改或删除操作的文件都提交到本地仓库,即使没有经过git add添加到暂存区
                                         新加的文件(即没有被git系统管理的文件)是不能被提交到本地仓库的。建议一般不要使用-a参数,
                                         正常的提交还是使用git add先将要改动的文件添加到暂存区,再用git commit 提交到本地版本库。
        # git commit --amend             提交了一版我们不满意的代码还推送到服务器了,在代码没被merge之前我们希望再修改一版满意的

    # git push
        git push <远程主机名> <本地分支名>  <远程分支名>

        # git push origin master      \\ 如果远程分支被省略,则表示将本地分支推送到与之存在追踪关系的远程分支(通常两者同名)
                                       \\ 如果该远程分支不存在,则会被新建

        # git push origin:remotes/origin/master

    命令详解    https://www.cnblogs.com/qianqiannian/p/6011404.html


其他未归类命令

    # git checkout master   切换到主分支 
    # git checkout katana   切换到分支

    # git merge master      把master上的 合并到本地 

    # git stash       \\ 带看 https://www.cnblogs.com/tocy/p/git-stash-reference.html
    # git stash clear
    # git stash list

    # git clean -fd       \\ 删除空目录 及空文件夹

    # git diff --cached     \\ 比较 暂存区(add 后的区域)和 HEAD(commit 提交后的) 之间的差异 就是 commit 未提交的部分 
    # git diff               \\ 比较 暂存区和 工作区(现在的目录) 之间的差异 所有的文件 只能比较已经添加过的文件 新建的比较不出
    # git diff -- mayan.sh    \\ 只 比较 mayan.sh 文件 可以加路径



    # git clone git@192.168.10.13:root/git_learning.git git_learning_02         \\ 指明文件夹名称


    # vim .git/config            \\ git仓库的配置文件 里面有 全局的信息 及本地的信息
    # git config --local --list   \\ 查看
    # git branch -v                \\ 查看 本地所有分支
    # git branch -av                \\ 查看所有的分支 包括远端

    # git checkout -b add_git_commands remotes/origin/add_git_commands    \\ 新建分支 add_... 基于分支 re...
    # git push



    # git fetch aaa         

....................................................................................................

2021.4.23 总结的 git


创建一个新仓库         \\ 需要在gitlib 上 新建项目 会出现以下代码页

    Git 全局设置
        # git config --global --list                       \\ 查看 所有配置  看是否有 用户邮箱  没有则创建
        # git config --global user.name "Administrator"
        # git config --global user.email "admin@example.com"

    创建一个新仓库
        # git clone http://172.21.34.204/root/ssyy99.git       \\ 最好使用http 使用 git@... 需要添加秘钥
        # cd ssyy99.com
        # touch README.md
        # git add README.md
        # git commit -m "add README"
        # git push -u origin master

    推送现有文件夹
        # cd ssyy99
        # git init
        # git remote add origin http://172.21.34.204/root/ssyy99.git   \\ 此地址为 项目-->克隆 的http地址
        # git add .
        # git commit -m "Initial commit"
        # git push -u origin master

    推送现有的 Git 仓库 并使用新的仓库          \\ 1. 把现有本地仓库 推送到 新建仓库  从此使用 新的远程仓库
        # cd ssyy99
        # git remote rename origin old-origin  \\ 把默认的仓库 改名    亦可以使用 # git remote rm origin 删除掉
        # git remote add origin http://172.21.34.204/root/ssyy99.git    \\ 添加 远程仓库origin 地址为http://... ...
        # git push -u origin --all           \\ 把本地仓库 推送到 名字为 origin的地址 --all 所有分支推送到远程主机 没有则新建
        # git push -u origin --tags           \\ --tags
                                
    推送现有的 Git 仓库 本地依然使用原来的仓库     \\ 2. 把现有本地仓库 推送到 远端并新建仓库 本地依然使用原来的仓库
        # cd ssyy99
        # git remote add aaa http://172.21.34.204/root/ssyy99.git     \\ 新增远端git仓库 aaa本地链接的别名而已
        # git remote -av
        # git push -u aaa --all                                        \\ ssyy99.git 可以不存在 会自动创建
        # git push -u aaa --tags


关于  remote 远端仓库 命令    \\ 此远端仓库只是 远端仓库的一个 链接地址而已

    # git remote          \\ 查看 可以连接的  远程仓库的信息
    # git remote -v        \\ 查看远端仓库的信息 此信息 只是写进 ./.git/config  配置文件中的仓库地址 可直接修改此配置文件即可
        aaa  http://172.21.34.204/root/test_310goo.git (fetch)\\ 此 aaa 为 给远端仓库链接地址 一个名字而已 不影响任何东西
        aaa  http://172.21.34.204/root/test_310goo.git (push) \\ ↓当执行 git pull 或git push时候 会自动使用此 仓库后面的地址
        origin  http://172.21.34.204/root/test_2.git (fetch)   \\ origin 为默认远端仓库 origin只是也个代称而已 
        origin  http://172.21.34.204/root/test_2.git (push)      \\ (fetch)拉取的地址    (push)上传的地址


    修改 默认 远端仓库链接地址
        # git config -l                         \\ 查看 git的配置文件
            branch.master.remote=origin          \\ 默认远端仓库的 名字为origin
        # git config branch.master.remote aaa     \\ 修改 默认远端仓库的名字为 aaa
        # git remote rm aaa                        \\ 删除可连接的远端仓库

    # vim ./.git/config     \\ git仓库配置文件 以上关于修改远程仓库 默认仓库 都可以在此修改
        [core]
            repositoryformatversion = 0
            filemode = true                     \\ git 文件权限管理 详细看注解
            bare = false
            logallrefupdates = true
        [remote "old-origin"]                      \\ 远程仓库 old-origin  代号而已
            url = http://172.21.34.204/root/test_310goo.git       \\ 地址
            fetch = +refs/heads/*:refs/remotes/aa/*
        [branch "master"]
            remote = origin                           \\ 默认远程仓库的 名字 
            merge = refs/heads/master
        [remote "origin"]                               \\ 远程仓库的名字代号 origin 
            url = http://172.21.34.204/root/tteeoo.git   \\ 远程仓库的地址
            fetch = +refs/heads/*:refs/remotes/origin/*

        注:
            filemode = true 默认git会记录文件的权限信息 如文件的权限信息被修改 在git中改变文件会出现很多我们并不需要提交的文件
                            但是有时候我们clone下来的文件权限不对 但是我们更新权限后 又不想提交 会把此项关闭
            # git config core.filemode false    \\ 关闭git 文件权限管理 亦可以直接修改配置文件
            # git config --get core.filemode     \\ 显示 当前 git文件权限的状态
            # git config --list                  \\ 显示当前仓库的配置

# git checkout -b tmp           \\ 基于当前 commit 创建 分支 tmp


关于分支的操作

    新建本地分支 并同步到远端
        # git branch -av         \\ 查看所有分支 *为当前使用的分支
        # git branch tmp          \\ 基于当前 commit 创建 分支 tmp
        # git branch -av           \\ 可以不用 切换到 tpm分支  亦可以同步
        # git push origin tmp:tmp   \\ 把 tpm 分支 同步到远端 tpm分支   远端不存在tmp 则会新建

    删除本地分支
        # git branch -av        \\ 查看所有分支
        # git branch -d tmp      \\ 删除 tmp分支   只删除了本地的tmp分支 与远程仓库的tmp分支没有影响

    删除远程分支
        # git branch -av
        # git push origin --delete tmp2   \\ 删除远程分支tmp2   对于本地 tmp2 没有影响
        # git push origin tmp2:tmp2        \\ 新建远程 tmp2分支 且 远程tmp2与本地tmp2同步

    拉取单个远程分支
        # git branch -av              \\ 查看所有分支
        # git pull origin tmp2:tmp2    \\ 把远程的 tmp2分支 拉取 到本地的tmp2分支

    把分支 合并到 master

        # git checkout -b tmp           \\ 基于当前 commit 创建 分支 tmp


工作区: 工作目录
暂存区: add 后的区域  事实上它只是一个文件 保存即将提交的文件列表信息
仓库区: commit 后的区域 其中HEAD指向最新放入仓库的版本
远程仓库: 


关于添加  .gitignore   不纳入git管理的文件      \\ .gitignore 只能忽略那些没有被追踪的档案

    1. 新仓库 直接添加 .gitignore文件即可
        # vim .gitignore                         \\ 以下文件或文件夹   不纳入git管理的文件
            include/dbinfo.inc.php
            include/config/siteConfig.inc.php
            templates_c/
            .idea/
            uploads/
            log/
            .user.ini
            data/cache/
            .well-known/
        # git add .gitignore
        # git commit -m 'add .gitignore'
        # git branch
        # git remote -v
        # git push origin master:master

    2. 项目已经开发到一半 发现有不该提交的文件已经提交后 仅仅在.gitignore中加入忽略是不行的
        1. 删除 指定目录 git管理的档案
            # git status                         \\ 要先确认没有未提交 的文件    
            # git rm -r --cached uploads/         \\ 在git管理中 删除所有 管理的文件 并非删除文件
            # git rm -r --cached templates_c/
            # git rm -r --cached log/
            # git checkout .htaccess
            # git rm --cached .user.ini
            # git rm -r --cached data/cache/
            # git rm --cached include/config/siteConfig.inc.php
            # git rm --cached include/dbinfo.inc.php
            # git rm --cached include/class/aliyun-php-sdk-push/Push/Request/.DS_Store
            # git rm --cached include/class/aliyun-php-sdk-push/Push/Request/V20160801/.DS_Store
            # git status
            # git add .gitignore
            # git commit -m 'add .gitignore'
            # git branch
            # git remote -v
            # git push origin master:master

        2. 删除所有git管理  在重新添加git管理
            # git status             \\ 要先确认没有未提交 的文件
            # git ls-files            \\ 查看 git 所有管理的文件
            # git rm -r --cached .     \\ 在git管理中 删除所有 管理的文件   并非删除文件 
            # git ls-files
            # git branch
            # git remote -v


# git status                            \\ 查看上次提交之后是否有对文件进行再次修改   查看工作区 与 暂存区的差别   所有文件
    状态1 Untracked files                 \\ 新建的文件 未 add 添加到暂存区的文件     状态1
        # git add a.txt                    \\ 保留修改 添加到暂存区  变成状态3
        # rm a.txt                          \\ 删除此文件 不保留修改
    状态2 Changes not staged for commit      \\ 已经添加到add暂存区的文件 修改过后 未add添加到暂存区的文件   状态2
        # git add a.txt                      \\ 把修改后的a.txt 添加到暂存区  就是要保留修改  变成状态3
        # git checkout c.txt                  \\ 放弃修改a.txt 会把a.txt 还原到未修改前的状态  就是不保留此次修改
        # git checkout -- a.txt                \\ 意义同上 亦可以加 --


        # git diff .htaccess  \\ 比较这个文件的不同

    状态3 Changes to be committed               \\ 已经 add 添加到暂存区 但是未 commit的文件         状态3
        # git commit -m 'add new'                \\ 把所有的改变 提交到 仓库区  就是要 保留所有的改变
        # git reset HEAD -- a.txt                 \\ 把 a.txt 回退到 未add的状态 会变成状态2

    # git status -s   \\ -s 参数来获得简短的输出结果
        A              \\ 状态1       或显示 ??
        AM              \\ 状态2      或显示  M     空格M
        MA               \\ 状态3     或显示 M      M空格








ELK 搭建




ELK搭建


yum 安装 ELK

# vim /etc/yum.repos.d/elk.repo
    [elasticsearch-7.x]

    name=Elasticsearch repository for 7.x packages
    baseurl=https://artifacts.elastic.co/packages/7.x/yum
    gpgcheck=1
    gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
    enabled=1
    autorefresh=1
    type=rpm-md

# yum install elasticsearch
# yum install kibana
# yum install logstash

# vim /etc/elasticsearch/elasticsearch.yml
    network.host: 0.0.0.0
    cluster.initial_master_nodes: ["node-1"]
# systemctl enable elasticsearch
# systemctl start elasticsearch                   \\ 9200   9300 被监听


使用 ELK 收集 nginx 日志                                 \\ 环境 CentOS 7.8   ELK版本7.9.2  nginx18.0


Elasticsearch 二进制包 安装                                \\ 下载网址 https://elasticsearch.cn/download/

    # wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-linux-x86_64.tar.gz
    # tar zxf elasticsearch-7.9.2-linux-x86_64.tar.gz -C /usr/local/
    # cd /usr/local/
    # mv elasticsearch-7.9.2/ elasticsearch
    # vim /usr/local/es/config/elasticsearch.yml           \\ 主配置文件
        network.host: 192.168.10.12
        cluster.initial_master_nodes: ["node-1"]             \\ 解决错误3
    # vim /etc/security/limits.conf     \\ linux资源限制配置文件  解决错误1、2
        * hard nofile 65536              \\ * 所有的账户 系统中所能设定的 打开文件最大数目的 最大值
        * soft nofile 131072              \\ 当前系统生效的 打开文件最大数据的 设置值
        * hard nproc 4096                  \\ 系统中所能设定的 进程的最大数目的 最大值
        * soft nproc 2048                   \\ 当前系统生效的 进程的最大数目的 设置值
        # End of file                        \\ 在End前添加
    # vim /etc/sysctl.conf
        vm.max_map_count=655360
        fs.file-max=655360
    # sysctl -p

    # groupadd elk
    # useradd -g elk elk                         \\ 创建用户 ELK 不允许 root 启动
    # chown -R elk.elk /usr/local/elasticsearch
    # su elk
    # /usr/local/elasticsearch/bin/elasticsearch    \\ 启动 elasticsearch   注意 防火墙及selinux 放行
    # ss -tnl                                        \\ 9200  9300 被监听 需要新开窗口查看 
    # http://192.168.10.12:9200                       \\ 浏览器访问  或使用curl访问
    # curl 127.0.0.1:9200                              \\ 另开一个连接  出现此 Elasticsearch已经启动成功
        {
          "name" : "localhost.localdomain",              \\ Elasticsearch 名称      
          "cluster_name" : "elasticsearch",               \\ 集群的名称
          "cluster_uuid" : "34Su3E64SOq2J6w0sFs29w",       \\ uuid 唯一标识
          "version" : {
            "number" : "7.9.2",                              \\ Elasticsearch 版本
            "build_flavor" : "default",
            "build_type" : "tar",
            "build_hash" : "d34da0ea4a966c4e49417f2da2f244e3e97b4e6e",
            "build_date" : "2020-09-23T00:45:33.626720Z",
            "build_snapshot" : false,
            "lucene_version" : "8.6.2",
            "minimum_wire_compatibility_version" : "6.8.0",
            "minimum_index_compatibility_version" : "6.0.0-beta1"
          },
          "tagline" : "You Know, for Search"
        }

    注: 会出现的错误 error
        1. max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
        2. max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
        3. the default discovery settings are unsuitable for production use; at least one of must be configured


Kibana 安装                    \\下载网址   https://www.elastic.co/cn/downloads/kibana
    
    # wget https://artifacts.elastic.co/downloads/kibana/kibana-7.9.2-linux-x86_64.tar.gz \\ 要和Elasticsearch的版本对应 
    # tar zxf kibana-7.9.2-linux-x86_64.tar.gz -C /usr/local/
    # cd /usr/local/
    # mv kibana-7.9.2/ kibana
    # vim /usr/local/kibanna/config/kibana.yml
        server.port: 5601                                     \\ 监听端口
        server.host: "192.168.10.12"   
        elasticsearch.hosts: ["http://192.168.10.12:9200"]      \\ 指定Elasticsearch地址
        kibana.index: ".kibana"                                  \\ 指定索引名
        i18n.locale: "zh-CN"                                      \\ 修改kibana界面为中文
    # chown -R elk.elk /usr/local/kibanna/*
    # su elk
    # /usr/local/kibana/bin/kibana                                  \\ 启动 kibana   注意 防火墙及selinux 放行
    # ss -tnl                                                        \\ 5601 被监听 需要新开窗口查看
    http://192.168.10.12:5601/    --> Dev Tools                       \\ 浏览器访问


Logstash 安装                        \\下载网址   https://www.elastic.co/cn/downloads/logstash

    # wget https://artifacts.elastic.co/downloads/logstash/logstash-7.9.2.tar.gz       \\ 要和Elasticsearch的版本对应
    # tar zxf logstash-7.9.2.tar.gz -C /usr/local/
    # cd /usr/local/
    # mv logstash-7.9.2/ logstash
    # vim /usr/local/logstash/nginx_access.conf              \\ 创建自定义脚本 以json 的方式返回
        input {
            file {
                path => "/usr/local/nginx/logs/access.log"
                start_position => beginning
            }
        }
        filter {
            grok {
                match => { "message" => "%{COMBINEDAPACHELOG} %{QS:x_forwarded_for}"}
            }
            date {
                match => [ "timestamp" , "dd/MMM/YYYY:HH:mm:ss Z" ]
            }
            geoip {
                source => "clientip"
            }
        }
        output {
            elasticsearch {
            hosts => "192.168.10.12:9200"
            }
            stdout { codec => rubydebug }
        }
    # mkdir /usr/local/logstash/patterns           \\ 创建
    # vim /usr/local/logstash/patterns/nginx        \\ logstash中grok的正则
        WZ ([^ ]*)
        NGINXACCESS %{IP:remote_ip} \- \- \[%{HTTPDATE:timestamp}\] "%{WORD:method} %{WZ:request} HTTP/%{NUMBER:httpversion}" %{NUMBER:status} %{NUMBER:bytes} %{QS:referer} %{QS:agent} %{QS:xforward}
    # /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/text.conf
    # ss -tnl                                        \\ 9600 被监听 需要新开窗口查看

    注: 需要安装nginx . nginx日志格式 默认即可

    使用 Kibana 查看 统计信息 
          -->   Dev Tools

    http://192.168.10.12:5601/
        Stack Management --> Index Patterns --> Create index pattern --> 搜索 lo* -->logstash-2020.10* 
        --> next step--> @timestamp --> Create index pattern
        
        Dev Tools
            logstash-2020.10.01-000001/_search                             \\ 查看收集到的nginx日志
        Visualize --> Create visualization --> line --> logstash-2020.10*   \\ 查看 曲线图 或饼状图等
            Metrics --> Y-axis --> Count                                     \\ Y 轴 访问量
            Buckets --> Add --> X-axis --> Date Histogram --> Update          \\ X 轴 时间


ES集群搭建

    # vim /usr/local/es/config/elasticsearch.yml
        cluster.name: my-elk                   \\ 集群名字 两台机器要一样
        node.name: node-1                       \\ 节点名字 两台机器要不一样
        path.data: /usr/local/es/data            \\ 数据 存储路径
        path.logs: /usr/local/es/logs             \\ 日志
        node.master: true                          \\ 主节点
        node.data: true                             \\ 从节点 即可为主节点又可以为从节点 加入
        http.port: 9200                              \\ es 访问端口
        transport.tcp.port: 9300                      \\ 集群之间 通讯的端口
        discovery.zen.minimum_master_nodes: 2          \\ 避免脑裂 ,集群节点数最少为 半数+1
        discovery.seed_hosts: ["192.168.10.14"]         \\ 集群之间的通讯ip 需要填写对方ip 可以是多个 使用,隔开
    # /usr/local/elasticsearch/bin/elasticsearch         \\ 如果不能发现集群 删除各自的data与logs目

    cerebro 安装                                           \\ ES集群监控管理工具 
        # wget https://github.com/lmenezes/cerebro/releases/download/v0.9.2/cerebro-0.9.2.tgz
        # tar zxf cerebro-0.9.2.tgz -C /usr/local/
        # cd /usr/local
        # mv cerebro-0.9.2/ cerebro
        # /usr/local/cerebro/bin/cerebro                         \\ 启动cerebro 9000端口被监听
        http://192.168.10.12:9000/                                \\ 浏览器 访问
            http://192.168.10.12:9200                              \\ 输入 ES地址


    cerebro 使用
        more --> create index 创建索引
            name   my                     \\ my索引创建2个主分片 每个主分片创建1个副本
            number of shards    2              主分片   存储数据            负载的作用
            number of replicas  1              副分片   主分片的数据的副本   高可用

            name   my1                       \\ my1索引创建3个主分片 每个主分片创建1个副本
            number of shards    3             \\ 会随机分配到各个节点上
            number of replicas  1


        监控界面
            my-elk    集群名字
            nodes     es节点
            indices   2个副本  每一个分片有一个副本 共2个
            shards    所有分片
            docs      文档数
            KB        占用的空间

            颜色
                green   所有主分片和副本分片都可用
                yellow  所有主分片可用 但不是所有副本分片都可用
                red     不是所有的主要分片都可用


------------------------------------------------------------------------------------------------------------------------


Logstash 的自定义脚本格式
    input 插件
        stdin : 输入插件 可以管道输入 也可以从终端交互输入  可以有以下两种方式启动
            1 # /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/text.conf
                lucy111
            2 # echo "lucy111" | /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/text.conf 
            codec:类型为 codec 
            type:类型为string 自定义该事件类型 可用于后续判断...就是想要显示的 信息 随便 
            tags: 类型为array 自定义事件的tag 可用于后续判读 
            add_field : 类型为hash 为该事件添加字段

        file : 从文件读取数据 如常见的日志文件
            # vim /usr/local/logstash/text2.conf 
                input {
                    file {
                        path => ["/usr/local/nginx/logs/access.log"]
                        start_position => "beginning"
                        type => "nginx"
                    }
                }
                output {
                    stdout {
                        codec => "rubydebug"
                    }
                }
            # /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/text2.conf

                path => ["/var/log/*/*.log","/var/log/message"]         文件位置 可是多个
                exclue => "*.gz"                                        不读取哪些文件
                sincedb_path => "var/log/message"                       记录sincedb文件路径   .......                 
                start_postion => "beginning"                            是否从头读取文件 或者end
                stat_interval => 1000                                   单位 秒 定时检查文件是否有更新 默认1s

        查询 elasticsearch
            # vim /usr/local/logstash/text3.conf
                input {
                    elasticsearch {
                        hosts => "192.168.14.10"
                        index => "teo4"
                        query => '{ "query": { "match_all": {} }}'
                    }
                }

                output {
                    stdout {
                        codec => "rubydebug"
                    }
                }

            # ./bin/logstash -f ./config/text3.conf


Kibana 使用
    http://192.168.10.12:9200/_cat               \\ kibanan 常用命令
    http://192.168.10.12:9200/_cat/health         \\ kibanan 健康状态
    
    创建索引
        PUT /info1/doc/1                  \\ PUT 为插入数据   PUT/POST都可以插入数据
        {                                  \\ info:索引名  doc: 类型    1:id 如果没有id字段会自动生成一段id
            "name":"lucy",                  \\ name:字段   对应的内容 而已
            "first_name":"xiaol",
            "last_name":"ming",
            "age":22,
            "job":"java"
            "about":"i love to go rock climbing",
            "interests":["sports","music"]
        }
        PUT /info2/doc/1
        {
            "name":"king",              
            "first_name":"xiaok",
            "last_name":"empty",
            "age":18,
            "job":"php",
        "about":"i like to collect rock albums",
        "interests":["music"]
        }

    批量创建                               \\ 可实现 mysql等数据库中的数据 使用python等 转换成 es语言 并插入
        POST info3/doc/_bulk
        {"index":{"_id":1}}                 \\ 插入id为1的数据 要在一行 不能使用换行
        {"username":"lucy3","age":"19"}
        {"index":{"_id":2}}
        {"username":"king3","age":"26"}

    更新/覆盖文档
        POST /info2/doc/1             \\ 此会覆盖所有 文档1的内容 只是剩下age
        {
            "age":55,
        }

    删除 文档
        DELETE info2/doc/2

    查询/检索 索引
        GET _search                      \\ 查询所有索引文档
        GET info1/_search                 \\ 查询指定索引文档
        GET info1,info2/_search            \\ 多索引查询
        GET info*/_search                   \\ * 通配符
        GET info1/doc/1                      \\ 查询 id 为1的 所有内容
            {
              "_index" : "info",                    \\ 索引名
              "_type" : "doc",                       \\ 类型
              "_id" : "1",                            \\ id
              "_version" : 2,                          \\ 版本 就是修改了几次
              "_seq_no" : 1,
              "_primary_term" : 1,
              "found" : true,
              "_source" : {
                "name" : "lucy",
                "first_name" : "xiaol",
                "last_name" : "ming",
                "age" : 22,
                "job" : "java",
                "about" : "i love to go rock climbing",
                "interests" : [
                  "sports",
                  "music"
                ]
              }
            }
        GET info1/doc/1?_source=first_name    \\ 查询 id 为1的 first_name 字段的内容
        GET info1/doc/_search                  \\ 查询 info中的doc的所有文档的内容  _search获取所有内容
            {
              "took" : 1,                     \\ 时间
              "timed_out" : false,
              "_shards" : {                     \\ 分片
                "total" : 1,                     \\ 一共 1条
                "successful" : 1,                 \\ 成功 1
                "skipped" : 0,                     \\ 跳过 0
                "failed" : 0                        \\ 失败 0
              },
              "hits" : {                              \\ 查询的内容
                "total" : {
                  "value" : 2,
                  "relation" : "eq"
                },
                "max_score" : 1.0,            \\ 打分 高频词
                "hits" : [
                  {
                    "_index" : "info",
                    "_type" : "doc",
                    "_id" : "1",
                    "_score" : 1.0,
                    "_source" : {
                      "name" : "lucy",
                      "first_name" : "xiaol",
                      "last_name" : "ming",
                      "age" : 22,
                      "job" : "java",
                      "about" : "i love to go rock climbing",
                      "interests" : [
                        "sports",
                        "music"
                      ]
                    }
                  },
                  {
                    "_index" : "info",
                    "_type" : "doc",
                    "_id" : "2",
                    "_score" : 1.0,
                    "_source" : {
                      "name" : "hank",
                      "first_name" : "xiaok",
                      "last_name" : "king",
                      "age" : 18,
                      "job" : "php",
                      "about" : "i like to collect rock albums",
                      "interests" : [
                        "music"
                      ]
                    }
                  }
                ]
              }
            }
        GET info1/doc/_search?q=lucy            \\ 查询 search搜索 包含lucy的 ?q=要查询的关键字
        GET info1/doc/_search?q=lucy&df=username&sort=age:asc&from=4&size=10
            ?:  后接条件
            q:  指定 关键字
            df: 指定默认查询的字段,如果不指定 es会查询所有字段
            sort: 排序 asc升序 desc降序
                sort=age:asc 按age字段 做升序排列
            timeout: 指定超时时间 默认不超时
            from,size: 用于分页
                from=0 从第0个索引开始
                size=10 显示10条数据
            timeout: 超时 防止查询的时候 数据量较大 长时间没有响应 造成阻塞
                timeout=1s
            &: 连接符号
        GET info1/doc/_search?q=username:lucy king            \\ 此查询方式为term查询 等效于 lucy 或者 king 的
        GET teo4/doc/_search?q=username:"collect rock"         \\ 此查询方式为phrase查询 词语查询 查询到 lucy king 的字符串
        GET teo4/doc/_search?q=username:(lucy OR king) AND lili \\ 包含 lucy或king 和 lili 的字段
            "profile":true                                       \\ 查看 查询的过程
        GET teo4/doc/_search?q=username:(luc NOT kin)             \\ 包含luc 不包含kin的
        GET teo4/doc/_search?q=username:(+luc -kin)                \\ 包含teo 不包含kata的
        GET teo4/doc/_search?q=age:[18 TO 22]
            [ ] 闭区间
            { } 开区间
            [1 TO 10]                 \\ 1 <= age <= 10
            [1 TO]                     \\ 1 <= age
            [* TO 10]                   \\ age <= 10
        通配符查询
            ?: 1个字符
            *: 0或多个字符
        正则表达式
            /   /        需要用 / / 括起来
        GET info1/doc/_search?q=username:lucy~1         \\ 匹配与lucy差一个字母的词 如 lucya luc lucy2 lucb
            ~1              \\ 模糊匹配 范围只能是 0 1 2
            ~2
        POST /teo4/doc/_mget                               \\ 查询/检索 多个文档
            {
                "ids":["1","2"]                              \\ 查询 id 为1和2的文档
            }

    浏览器查询 Search API(RUI) 查询                             \\ 语句 放在查询路径的后面
        http://192.168.10.12:9200/lucy1/doc/1                   \\ 查询某一个文档
        http://192.168.10.12:9200/lucy1/doc/_search              \\ 查询某一个类型中的id 所有的文档

    Kibana 分词器 简介
        post _analyze                     \\ 请求  分析器
        {
            "analyzer":"standard",         \\ analyzer 分词器类型   standard
            "text":"we are a family"         \\ 分的词
        }

        通用分词器类型
            standard: 默认分词器 支持多语言 按词切分并做小写处理
            simple: 按照非字母切分 小写处理
            whitespace: 按照空格来切分
            stop: 去除语气助词 如 the an 的 这等
            keyword: 不分词
            pattern: 正则分词 默认\w+ 即非字词符号做分隔符
            language: 常见语言的分词器 30+
        中文分词器类型
            ik: 实现中英文单词切分 自定义词库 https://github.com/medcl/elasticsearch-analysis-ik
                ik_smart: 最少切分 想要效率更高一些速度快一些使用此分词器 企业内部建议用此分词器
                ik_max_word: 最细粒度划分 想要搜索更全面使用此分词器 分的词会更多 占用空间较多 检索效率较低 提供外界用户建议用此分词器
            jieba: python流行分词系统 支持分词和词性标注 支持繁体 自定义 并行分词 https://github.com/singlee/elasticsearch-jieba-plugin
            Hanlp: 由一系列模型于算法组成的java工具包 普及自然语言处理在生产环境中的应用 https://github.com/hankcs/hanlp
            THULAC: 清华大学中文词法分析工具包 具有中文分词和词性标注功能 https://github.com/microbun/elasticsearch-thulac-plugin
    
        ik分词器    \\ 版本要和Elasticsearch的版本对应 下载网址 https://github.com/medcl/elasticsearch-analysis-ik/releases

        # cd /data/
        # unzip -o -d /usr/local/es/plugins/analysis-ik/ elasticsearch-analysis-ik-7.9.2.zip
        # cd /usr/local/es/plugins
        重启elasticsearch
        重启Kibana
        http://192.168.10.12:5601/    --> Dev Tools             \\ 浏览器访问
            POST _analyze
            {
              "analyzer": "ik_smart",                              \\ 使用 ik_smart 分词器
              "text":"php是世界上最好的语言"
            }

        自定义分词器
            PUT my_analyzer                     \\ 定义 索引
            {
                "settings":{                      \\ 设置 定义分词器
                    "analysis":{                   \\ 主分词器
                        "analyzer":{    
                            "my":{                                   \\ 主分词器名字 随便起
                                "tokenizer":"punctuation",            \\ punctuation分词器类型   第二步
                                "type":"custom",                       \\ 类型 自定义
                                "char_filter":["emoticons"],            \\ 字符过滤              第一步
                                "filter":["lowercase","english_stop"]    \\ 分词后的处理         第三步
                            } 
                        },
                        "tokenizer":{                   \\ 分词器参数自定义
                            "punctuation":{              \\ 定义punctuation分词器 的参数
                                "type":"pattern",
                                "pattern":"[.,!?]"         \\ 遇到 .,!? 做分词 的匹配  [a]a做分词 [0-9]数字做分词 
                            }
                        },
                        "char_filter":{                      \\ 定义字符过滤
                            "emoticons":{
                                "type":"mapping",              \\ 类型 mapping
                                "mappings":[                    \\ 定义mapping
                                    ":)=>_happy_",               \\ 遇到 :) 转化成  _happy_
                                    ":(=>_sad_"
                                ]
                            }
                        },
                        "filter":{                            \\ 定义 分词后的处理
                            "english_stop":{
                                "type":"stop",                  \\ 停用词 敏感词
                                "stopwords":"_english_"          \\ 停用 _english_
                            }
                        }
                    }                                              \\ 结束 定义分词器
                }
            }

            post my_analyzer/_analyze
            {
                "analyzer":"my",                                      \\ 使用 自定义分词器 my
                "text":"1 ' m a : ) person,and you?"
            }


ELK是Elasticsearch、Logstash、Kibana的简称,这三者是核心套件,但并非全部。

Elasticsearch 是实时全文搜索和分析引擎,提供搜集、分析、存储数据三大功能;是一套开放REST和JAVA API等结构提供高效搜索功能,
              可扩展的分布式系统。它构建于Apache Lucene搜索引擎库之上。

Logstash      是一个用来搜集、分析、过滤日志的工具。它支持几乎任何类型的日志,包括系统日志、错误日志和自定义应用程序日志。
              它可以从许多来源接收日志,这些来源包括 syslog、消息传递(例如 RabbitMQ)和JMX,它能够以多种方式输出数据,
              包括电子邮件、websockets和Elasticsearch。

Kibana        是一个基于Web的图形界面,用于搜索、分析和可视化存储在 Elasticsearch指标中的日志数据。它利用Elasticsearch
              的REST接口来检索数据,不仅允许用户创建他们自己的数据的定制仪表板视图,还允许他们以特殊的方式查询和过滤数据