Redhat6.5 Linux 安装yum docker mongodb yapi

Redhat6.5 Linux安装yum

  1. 检查是否安装yum包。查看RHEL是否安装了yum,若是安装了,那么又有哪些yum包:
    rpm -qa |grep yum

  2. 删除redhat自带的yum包

    1
    2
    rpm -qa|grep yum|xargs rpm -e --nodeps(不检查依赖,直接删除rpm包)
    rpm -qa |grep yum (查询确认)
  3. 下载新的yum包。使用Centos6.5的yum包
    A. 查看版本号和系统类别32 64位:

    cat /etc/redhat-release
    

    B. 根据上一步,找到对应的yum包,然后下载。我的服务器对应的为:

    wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm   
    wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm
    wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
    

    C. 安装

    rpm -e python-urlgrabber-3.9.1-9.el6.noarch
    rpm -ivh python-urlgrabber-3.9.1-11.el6.noarch.rpm
    rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm yum-3.2.29-81.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm 
    
  4. 使用163数据源

    1
    2
    3
    4
    5
    cd /etc/yum.repos.d/
    wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
    vi CentOS6-Base-163.repo
    编辑文件,把文件里面的$releasever全部替换为版本号:6(注意,不是6.5)最后保存!
    mv CentOS6-Base-163.repo rhel-source.repo

    详细配置:
    CentOS6-Base-163

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    # CentOS-Base.repo
    #
    # The mirror system uses the connecting IP address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client. You should use this for CentOS updates
    # unless you are manually picking other mirrors.
    #
    # If the mirrorlist= does not work for you, as a fall back you can try the
    # remarked out baseurl= line instead.
    #
    #

    [base]
    name=CentOS-6 - Base - 163.com
    baseurl=http://mirrors.163.com/centos/6/os/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
    gpgcheck=1
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

    #released updates
    [updates]
    name=CentOS-6 - Updates - 163.com
    baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
    gpgcheck=1
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

    #additional packages that may be useful
    [extras]
    name=CentOS-6 - Extras - 163.com
    baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
    gpgcheck=1
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-6 - Plus - 163.com
    baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
    gpgcheck=1
    enabled=0
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

    #contrib - packages by Centos Users
    [contrib]
    name=CentOS-6 - Contrib - 163.com
    baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
    gpgcheck=1
    enabled=0
    gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

    epel.repo内容与CentOS6-Base-163相同

    rhel-source.repo

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [rhel-source]
    name=Red Hat Enterprise Linux $releasever - $basearch - Source
    #baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/
    baseurl=file:///RPMS/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

    [rhel-source-beta]
    name=Red Hat Enterprise Linux $releasever Beta - $basearch - Source
    baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/SRPMS/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
  5. 清除原有缓存

    1
    yum clean all
  6. 重建缓存,以提高搜索安装软件的速度

    1
    yum makecache
  7. 测试

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    yum list |grep vsftp
    yum repolist all
    ## 安装测试
    yum -y install httpd-tools
    ## 安装mysql
    wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
    yum linstall mysql-community-release-el6-5.noarch.rpm
    yum repolist enabled | grep mysql
    yum install mysql-community-server
    ## 如果出现错误执行下面一句操作临时跳过验证,或者尝试重启服务:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
    ## UPDATE user SET Password=PASSWORD('root') where USER='root';FLUSH PRIVILEGES;
    ## service mysql(d) restart
    vim /etc/my.cnf #在 [mysqld] 这个模块最后一行插入语句:skip-grant-tables
    service mysqld restart
    mysql -u root -p
    ## 远程需要连接还需要做些其他配置,设置完密码去掉跳过验证的语句。
    ## 1. grant all privileges on *.* to 'root'@'%'identified by 'root' with grant option;
    ## 2. flush privileges;
  8. 测试更新系统不能随便执行(很危险),会更新系统跟内核

    1
    yum update

扩展 Redhat6.5 安装本地yum数据源

跟前面类似:

  1. 挂载光盘:mount dev/cdrom /mnt/cdr
  2. 编辑yum源配置文件最好先备份一个:vi /etc/yum.repos.d/rhel-source.repo
    name=Red Hat Enterprise Linux $releasever - $basearch - Source
    baseurl=file:///mnt/cdr # 光盘挂载目录路径
    enabled=1 # 是否禁用此yum源,1生效 0不生效
    gpgcheck=1 # 是否进行gpg校验,0为不校验,1校验
    … # 其他
  3. 执行
    1
    2
    yum clean all   //清除缓存
    yum makecache   //把yum源缓存到本地,加快软件的搜索

问题

解决方法: 把/etc/yum.repos.d/epel.repo,文件第3行注释去掉,把第四行注释掉。具体如下:

打开/etc/yum.repos.d/epel.repo,将

1
2
3
4
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch

修改为

1
2
3
4
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch

再清理源,重新安装

1
2
yum clean all
yum install -y 需要的包

Yum报yummain.user_main(sys.argv[1:], exit_code=True)错解决办法

/etc/yum.conf文件中的 plugins 设为 0 即可

error: rpmdb: BDB0113 Thread/process 2975/140037971011648 failed: BDB1507 Thread died in Berkeley DB library

1
2
rpm --rebuilddb
yum repolist

通过yum安装Docker

一、安装epel源

1
2
3
wget http://mirrors.yun-idc.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum clean all

二、安装Docker

1
yum -y install docker-io

无法安装的话使用下面

1
yum install https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm

三、启动Docker

1
2
service docker start
docker -d

简单使用

1.查看进程:

1
docker ps

2.关闭镜像

1
docker stop $CONTAINER_ID

3.查看本地镜像

1
docker images

问题解决

yum安装docker失败,提示“No package docker-io available”

方法一:

  • yum -y remove epel-release 卸载
  • 执行yum -y install epel-release 重新安装
  • 这个安装是不行的:sudo yum install docker
  • 执行命令yum -y install docker-io,最后docker成功安装好了。这个可能找不到镜像
  • docker --version 查看版本号
  • docker info 查看详情

方法二:

方法一无效的话使用方法二

1
yum install https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm

You are running linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running docker.

升级内核
执行:

1
yum upgrade device-mapper-libs

Docker安装MongoDB

  1. 查找: docker search mongo
  2. 下载: docker pull mongo
  3. 查看镜像: docker images mongo
  4. 执行前面1-3三步就行。mongo目录创建: mkdir -p ~/mongo ~/mongo/db
  5. 使用 docker run -p 27017:27017 -v $PWD/db:/data/db -d mongo
  6. 查看启动情况docker ps

命令说明:

1
2
-p 27017:27017 :将容器的27017 端口映射到主机的27017 端口
-v $PWD/db:/data/db :将主机中当前目录下的db挂载到容器的/data/db,作为mongo数据存储目录

centos7安装docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
yum install -y yum-utils device-mapper-persistent-data lvm2 # 安装依赖
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 配置源
yum list docker-ce --showduplicates | sort -r # 查看支持版本
yum install docker-ce-18.06.3.ce # 安装
systemctl start docker # 启动
systemctl enable docker # 开机启动
docker version
docker ps # 查看当前正在运行的容器
docker start/stop id/name #启动/停止某个容器
docker images #查看本地镜像

curl -L https://get.daocloud.io/docker/compose/releases/download/1.26.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose #下载docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

在编辑好的yml目录中执行启动关闭项目

1
2
docker-compose up
docker-compose down

镜像加速

1
2
3
4
5
6
7
8
9
10
11
12
https://cr.console.aliyun.com # 注册阿里云,选择镜像中心,镜像加速
会有使用说明:
针对Docker客户端版本大于 1.10.0 的用户
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

报错:tcp 47.107.215.73:443: i/o timeout

Error response from daemon: Get https://registry.cn-hangzhou.aliyuncs.com/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

DNS设置成 8.8.8.8

1
2
3
vi /etc/resolv.conf # nameserver 8.8.8.8 或者 nameserver 114.114.114.114
vi /etc/sysconfig/network-scripts/xx # DNS1=8.8.8.8 DNS2=114.114.114.114
service network restart

可能原因:网络不通,url地址拼写错误
还可以通过

1
2
3
yum install bind-utils
dig @114.114.114.114 cn-shenzhen.aliyuncs.com
vim /etc/hosts #挖掘可用IP配置到配置文件中

错误

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running
Docker未启动,执行命令:service docker start

ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-3cf202aa8f9b -j RETURN: iptables: No chain/target/match by that name.
关闭防火墙需要重启docker,执行命令:service docker restart

常用命令

docker ps 查看启动的容器
docker exec -it 487ab18d9c7c /bin/bash 进入容器,如果出错用把/bin/bash改成/bin/sh

Docker安装Yapi

  1. 启动 MongoDB

    1
    docker run -d --name mongo-yapi mongo
  2. 获取 Yapi 镜像,版本信息可在 阿里云镜像仓库 查看

    1
    docker pull registry.cn-hangzhou.aliyuncs.com/anoy/yapi
  3. 初始化 Yapi 数据库索引及管理员账号

    1
    2
    3
    4
    5
    6
    docker run -it --rm \
    --link mongo-yapi:mongo \
    --entrypoint npm \
    --workdir /api/vendors \
    registry.cn-hangzhou.aliyuncs.com/anoy/yapi \
    run install-server

自定义配置文件挂载到目录 /api/config.json

  1. 启动 Yapi 服务

    1
    2
    3
    4
    5
    6
    7
    docker run -d \
    --name yapi \
    --link mongo-yapi:mongo \
    --workdir /api/vendors \
    -p 3000:3000 \
    registry.cn-hangzhou.aliyuncs.com/anoy/yapi \
    server/app.js
  2. 使用 Yapi

    1
    2
    curl 127.0.0.1:3000 #验证是否可以访问
    访问 http://localhost:3000 登录账号 admin@admin.com,密码 ymfe.org
  3. 关闭 Yapi

    1
    docker stop yapi
  4. 启动 Yapi

    1
    2
    docker start mongo-yapi
    docker start yapi

访问问题

启动后无法访问,telnet 192.168.33.201 22 telnet: connect to address 192.168.33.201: No route to host,是被防火墙挡住了
防火墙添加端口:firewall-cmd --zone=public --add-port=3000/tcp --permanent

直接使用yum安装

需要安装nodejs,mongo

nodejs安装

  1. 下载wget https://nodejs.org/dist/v9.8.0/node-v9.8.0-linux-x64.tar.xz
  2. 解压安装包

    1
    2
    xz -d node-v9.8.0-linux-x64.tar.xz
    tar -xvf node-v9.8.0-linux-x64.tar
  3. 进入目录cd node-v9.8.0-linux-x64

  4. 软链接

    1
    2
    安装目录ln -s /node-v9.8.0-linux-x64/bin/node /usr/bin/node   # 或者/usr/local/bin/node目录
    安装目录ln -s /node-v9.8.0-linux-x64/bin/npm /usr/bin/npm
  5. 验证版本

    1
    2
    3
    whereis node
    node -v
    npm -v
  6. 使用淘宝镜像 npm config set registry https://registry.npm.taobao.org

mongoDB安装

  1. 添加阿里源vi /etc/yum.repos.d/mongodb-org.repo

    1
    2
    3
    4
    5
    6
    [mongodb-org] 
    name = MongoDB Repository
    baseurl = https://mirrors.aliyun.com/mongodb/yum/redhat/6/mongodb-org/3.6/x86_64/
    gpgcheck = 0
    enabled = 1
    gpgkey = https://www.mongodb.org/static/pgp/server-3.6.asc
  2. 安装yum install mongodb-org

  3. 默认位置

    1
    2
    3
    /var/lib/mongo
    /var/log/mongodb
    /etc/mongod.conf

    修改 将net:bindIp: 127.0.0.1 改为 0.0.0.0 开发外部访问

  4. 开放27017端口

    1
    vim /etc/sysconfig/iptables
    1
    2
    添加
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
    1
    service iptables reload
  5. 开启服务

    1
    service mongod start 或 systemctl start mongod

    还有stop restart命令

  6. 开机自启

    1
    2
    3
    chkconfig mongod on
    # 或者
    systemctl ennable mongod
  7. 启动客户端

    1
    mongo --host 127.0.0.1:27017
  8. 关闭服务

    1
    service mongod stop
  9. 卸载软件

    1
    2
    3
    yum erase $(rpm -qa | grep mongodb-org)
    # 或者
    yum remove mongodb-org
  10. 删除文件

    1
    2
    3
    rm -r /var/log/mongodb
    rm -r /var/lib/mongo
    rm -r /etc/mongod.conf

git安装

方式一:编译安装

1
sudo yum install -y git # 不建议使用安装的版本太旧,1.7.1的版本
  1. 安装依赖,一般都已经安装好。rpm -qa | grep wget查询命令

    1
    2
    3
    sudo yum install -y wget
    sudo yum install -y gcc-c++
    sudo yum install -y zlib-devel perl-ExtUtils-MakeMaker
  2. 获取镜像wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz

  3. 安装

    1
    2
    3
    4
    5
    tar -zxvf git-2.9.0.tar.gz
    cd git-2.9.0
    ./configure --prefix=/usr/local # –prefix=/usr/local,指定安装路径
    make
    sudo make install
  4. 验证git --version

方式二:IUS 源方式安装,不一定为最新版本

  1. 添加 IUS 源

    1
    yum install -y https://centos7.iuscommunity.org/ius-release.rpm
  2. 安装

    1
    2
    yum install -y git2u
    git --version

yapi安装

参考官方文档

1
2
3
4
5
6
7
8
9
mkdir yapi
cd yapi
git clone https://github.com/YMFE/yapi.git vendors //或者下载 zip 包解压到 vendors 目录。国内地址:https://gitee.com/mirrors/YApi.git
cp vendors/config_example.json ./config.json //复制完成后请修改相关配置,如果mongodb没设置密码就删除配置里面的密码
cd vendors
sudo npm install --production --registry https://registry.npm.taobao.org
npm run install-server //安装程序会初始化数据库索引和管理员账号,管理员账号名可在 config.json 配置
node server/app.js //启动服务器后,请访问 127.0.0.1:{config.json配置的端口},初次运行会有个编译的过程,请耐心等候
nohup node server/app.js & # 后台启动,或者使用pm2

PM2安装

1
2
3
4
5
npm install -g pm2 # 按照完成自动创建$HOME/.pm2 相关目录
pm2 start server/app.js --watch # watch参数可以监控路径变化自动重启,如果提示命令没找到,就得软连接下安装后显示的左侧路径:ln -s /xxx/node-v9.8.0-linux-x64/bin/pm2 /usr/bin/pm2
pm2 stop server/app.js
pm2 stop all
pm2 list # 查看进程状态

问题:
如果出现gyp WARN EACCES user "root" does not have permission to access the dev dir

1
npm install ethereumjs-abi -g --unsafe-perm # 执行即可解决

其他错误修复

问题:Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor
修复:在server/utils/db.js第19行加入mongoose.set('useUnifiedTopology',true);,找到yapi ps -ef|grep node进行重启

建议

  • 操作系统建议使用Centos7 安装会简单很多

参考