美文网首页
2020-03-29 安装ectd服务启动失败问题

2020-03-29 安装ectd服务启动失败问题

作者: FredWorks | 来源:发表于2020-03-29 00:33 被阅读0次

    在主机 192.168.1.236 上,通过如下安装 etcd 服务,然后修改配置文件:

    yum -y install etcd
    

    其中 etcd 的数据目录为:/data/k8s/etcd/,通过如下指令设置的访问权限:

    chown etcd.etcd /appdata/k8s/etcd
    chmod 754 /appdata/k8s/
    

    结果启动失败。通过命令 ‘ journalctl -xe ' 查看日志,发现如下报错信息:

    Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: Starting Etcd Server...
    -- Subject: Unit etcd.service has begun start-up
    -- Defined-By: systemd
    -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
    -- 
    -- Unit etcd.service has begun starting up.
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: recognized and used environment variable ETCD_ADVERTISE_CLIENT_URLS=http://localhost:2379
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: recognized environment variable ETCD_NAME, but unused: shadowed by corresponding flag
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: recognized environment variable ETCD_DATA_DIR, but unused: shadowed by corresponding flag
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: recognized environment variable ETCD_LISTEN_CLIENT_URLS, but unused: shadowed by corresponding flag
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: etcd Version: 3.3.11
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: Git SHA: 2cf9e51
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: Go Version: go1.10.3
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: Go OS/Arch: linux/amd64
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: setting maximum number of CPUs to 8, total number of available CPUs is 8
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: listening for peers on http://localhost:2380
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: listening for client requests on localhost:2379
    Mar 28 13:51:05 test.saas.microreal.cn etcd[2809]: cannot access data directory: mkdir /data/k8s/etcd: permission denied
    Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: etcd.service: main process exited, code=exited, status=1/FAILURE
    Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: Failed to start Etcd Server.
    -- Subject: Unit etcd.service has failed
    -- Defined-By: systemd
    -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
    -- 
    -- Unit etcd.service has failed.
    -- 
    -- The result is failed.
    Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: Unit etcd.service entered failed state.
    Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: etcd.service failed.
    Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: etcd.service holdoff time over, scheduling restart.
    Mar 28 13:51:05 test.saas.microreal.cn systemd[1]: Stopped Etcd Server.
    -- Subject: Unit etcd.service has finished shutting down
    -- Defined-By: systemd
    -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
    -- 
    -- Unit etcd.service has finished shutting down.
    

    通过如下命令:

    vi /usr/lib/systemd/system/etcd.service
    

    查看 etcd.service 的内容:

    [Unit]
    Description=Etcd Server
    After=network.target
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    Type=notify
    WorkingDirectory=/var/lib/etcd/
    EnvironmentFile=-/etc/etcd/etcd.conf
    User=etcd
    # set GOMAXPROCS to number of processors
    ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\""
    Restart=on-failure
    LimitNOFILE=65536
    
    [Install]
    WantedBy=multi-user.target
    

    可以发现其运行用户是 etcd,那么修改为 root:

    [Unit]
    Description=Etcd Server
    After=network.target
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    Type=notify
    WorkingDirectory=/var/lib/etcd/
    EnvironmentFile=-/etc/etcd/etcd.conf
    User=root
    # set GOMAXPROCS to number of processors
    ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\""
    Restart=on-failure
    LimitNOFILE=65536
    
    [Install]
    WantedBy=multi-user.target
    

    再将数据目录的权限修改为 root:

    chown -R root.root /data/k8s/etcd
    chmod -R 754 /data/k8s/etcd
    

    在通过如下命令重新加载配置:

    systemctl daemon-reload
    

    再重新启动etcd.service:

    service etcd start
    

    发现这次启动成功了。查看其状态:

    service etcd status
    

    内容为:

    [root@test system]# systemctl status etcd
    ● etcd.service - Etcd Server
       Loaded: loaded (/usr/lib/systemd/system/etcd.service; disabled; vendor preset: disabled)
       Active: active (running) since Sat 2020-03-28 14:37:11 CST; 8s ago
     Main PID: 21851 (etcd)
        Tasks: 19
       Memory: 16.2M
       CGroup: /system.slice/etcd.service
               └─21851 /usr/bin/etcd --name=etcd1 --data-dir=/data/k8s/etcd/ --listen-client-urls=http://localhost:2379
    
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 2
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: 8e9e05c52164694d became leader at term 2
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 2
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: setting up the initial cluster version to 3.3
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: set the initial cluster version to 3.3
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: enabled capabilities for version 3.3
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: published {Name:etcd1 ClientURLs:[http://localhost:2379]} to cluster cdf818194e3a8c32
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: ready to serve client requests
    Mar 28 14:37:11 test.saas.microreal.cn etcd[21851]: serving insecure client requests on 127.0.0.1:2379, this is strongly discouraged!
    Mar 28 14:37:11 test.saas.microreal.cn systemd[1]: Started Etcd Server.
    

    尝试往 etcd 中插入一条数据,然后再取出来:

    etcdctl set /test/data 123455
    etcdctl get /test/data
    

    相关文章

      网友评论

          本文标题:2020-03-29 安装ectd服务启动失败问题

          本文链接:https://www.haomeiwen.com/subject/dhaeuhtx.html