安装 Azure Linux 代理会出现与 Python 相关的问题

安装 Azure Linux 代理会出现与 Python 相关的问题

当我分配这台服务器时,它有两个版本的 python(2.7 和 3.6),然后我必须手动安装 3.10,因为我想要使用的 Netbox 版本至少需要 3.8。

一切看起来都很好,直到我意识到walinuxagent(Azure Linux 代理)不起作用。似乎 Python 有问题。

Azure Linux 代理

  • 我已经apt remove --purge walinuxagent通过以下方式重新安装apt install walinuxagent但仍然不起作用:
$ sudo systemctl status walinuxagent.service

● walinuxagent.service - Azure Linux Agent
   Loaded: loaded (/lib/systemd/system/walinuxagent.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/walinuxagent.service.d
           └─10-Slice.conf, 11-CPUAccounting.conf, 12-CPUQuota.conf
   Active: failed (Result: exit-code) since Wed 2023-02-01 15:19:50 UTC; 15s ago
  Process: 29518 ExecStart=/usr/bin/python3 -u /usr/sbin/waagent -daemon (code=exited, status=1/FAILURE)
 Main PID: 29518 (code=exited, status=1/FAILURE)
      CPU: 76ms

Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Service hold-off time over, scheduling restart.
Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Scheduled restart job, restart counter is at 5.
Feb 01 15:19:50 SERVER-01 systemd[1]: Stopped Azure Linux Agent.
Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Consumed 76ms CPU time
Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Start request repeated too quickly.
Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Failed with result 'exit-code'.
Feb 01 15:19:50 SERVER-01 systemd[1]: Failed to start Azure Linux Agent.
  • 其结果如下journalctl -u walinuxagent.service
-- Logs begin at Thu 2022-12-15 11:18:50 UTC, end at Wed 2023-02-01 15:28:33 UTC. --
Jan 31 10:03:55 SERVER-01 systemd[1]: Started Azure Linux Agent.
Jan 31 10:03:55 SERVER-01 python3[930]: /usr/sbin/waagent:27: DeprecationWarning: the imp module is deprecated in favour
Jan 31 10:03:55 SERVER-01 python3[930]:   import imp
Jan 31 10:03:56 SERVER-01 python3[930]: Traceback (most recent call last):
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 43Jan 31 10:03:56 SERVER-01 python3[930]:     supported = platform._supported_dists + (supported_dists,)
Jan 31 10:03:56 SERVER-01 python3[930]: AttributeError: module 'platform' has no attribute '_supported_dists'
Jan 31 10:03:56 SERVER-01 python3[930]: During handling of the above exception, another exception occurred:
Jan 31 10:03:56 SERVER-01 python3[930]: Traceback (most recent call last):
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/sbin/waagent", line 31, in <module>
Jan 31 10:03:56 SERVER-01 python3[930]:     import azurelinuxagent.agent as agent
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/agent.py", line 34, in <moJan 31 10:03:56 SERVER-01 python3[930]:     import azurelinuxagent.common.event as event
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/event.py", line 34,Jan 31 10:03:56 SERVER-01 python3[930]:     from azurelinuxagent.common.version import CURRENT_VERSION, CURRENT_AGENT
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/version.py", line 1Jan 31 10:03:56 SERVER-01 python3[930]:     __distro__ = get_distro()
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/version.py", line 8Jan 31 10:03:56 SERVER-01 python3[930]:     osinfo = get_linux_distribution(0, 'alpine')
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 61Jan 31 10:03:56 SERVER-01 python3[930]:     return get_linux_distribution_from_distro(get_full_name)
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 72Jan 31 10:03:56 SERVER-01 python3[930]:     distro.linux_distribution(
Jan 31 10:03:56 SERVER-01 python3[930]: NameError: name 'distro' is not defined
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Main process exited, code=exited, status=1/FAILURE
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Failed with result 'exit-code'.
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Consumed 125ms CPU time
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Service hold-off time over, scheduling restart.
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Scheduled restart job, restart counter is at 1.
Jan 31 10:03:56 SERVER-01 systemd[1]: Stopped Azure Linux Agent.
$ sudo python3 setup.py install

Traceback (most recent call last):
  File "/home/admin/Azure/WALinuxAgent-master/setup.py", line 24, in <module>
    import setuptools
  File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 12, in <module>
    import setuptools.version
  File "/usr/lib/python3/dist-packages/setuptools/version.py", line 1, in <module>
    import pkg_resources
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 77, in <module>
    __import__('pkg_resources.extern.packaging.requirements')
  File "/usr/lib/python3/dist-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
    from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 632, in _load_backward_compatible
  File "/usr/lib/python3/dist-packages/pkg_resources/extern/__init__.py", line 43, in load_module
    __import__(extant)
  File "/usr/lib/python3/dist-packages/pkg_resources/_vendor/pyparsing.py", line 943, in <module>
    collections.MutableMapping.register(ParseResults)
AttributeError: module 'collections' has no attribute 'MutableMapping'

Python

  • whereis python输出:
python: /usr/bin/python3.6m-config /usr/bin/python3.10 /usr/bin/python3.6-config /usr/bin/python /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python2.7 /usr/lib/python3.10 /usr/lib/python3.8 /usr/lib/python3.6 /usr/lib/python2.7 /usr/lib/python3.7 /etc/python3.10 /etc/python /etc/python3.6 /etc/python2.7 /usr/local/lib/python3.10 /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/include/python3.6m /usr/include/python3.6 /usr/share/python /usr/share/man/man1/python.1.gz 
  • ls -ls /usr/bin/python*输出:
   0 lrwxrwxrwx 1 root root      24 Jan 31 15:53 /usr/bin/python -> /etc/alternatives/python
   0 lrwxrwxrwx 1 root root       9 Apr 16  2018 /usr/bin/python2 -> python2.7
3544 -rwxr-xr-x 1 root root 3628904 Nov 28 18:51 /usr/bin/python2.7
   0 lrwxrwxrwx 1 root root      25 Dec 15 10:41 /usr/bin/python3 -> /etc/alternatives/python3
   0 lrwxrwxrwx 1 root root      16 Oct 25  2018 /usr/bin/python3-config -> python3.6-config
   4 -rwxr-xr-x 1 root root    1018 Oct 28  2017 /usr/bin/python3-jsondiff
   4 -rwxr-xr-x 1 root root    3661 Oct 28  2017 /usr/bin/python3-jsonpatch
   4 -rwxr-xr-x 1 root root    1342 May  1  2016 /usr/bin/python3-jsonpointer
   4 -rwxr-xr-x 1 root root     398 Nov 15  2017 /usr/bin/python3-jsonschema
5352 -rwxr-xr-x 1 root root 5477688 Jan 28 19:09 /usr/bin/python3.10
4424 -rwxr-xr-x 2 root root 4526456 Nov 25 14:10 /usr/bin/python3.6
   0 lrwxrwxrwx 1 root root      33 Nov 25 14:10 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
4424 -rwxr-xr-x 2 root root 4526456 Nov 25 14:10 /usr/bin/python3.6m
   0 lrwxrwxrwx 1 root root      34 Nov 25 14:10 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
   0 lrwxrwxrwx 1 root root      10 Oct 25  2018 /usr/bin/python3m -> python3.6m
   0 lrwxrwxrwx 1 root root      17 Oct 25  2018 /usr/bin/python3m-config -> python3.6m-config
  • 列出的 Python 版本:
$ python -V
Python 3.10.9

$ python3 -V
Python 3.10.9

$ update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.10

有人知道如何解决这个问题吗?

更新 1:情况有所改善

我卸载了 Python 3.10.9,删除了符号链接并替换为操作系统原有的 python 版本,然后重新配置update-alternativespythonpython3

$ ls -ls /usr/bin/python*
   0 lrwxrwxrwx 1 root root      24 Feb  2 10:22 /usr/bin/python -> /etc/alternatives/python
   0 lrwxrwxrwx 1 root root       9 Apr 16  2018 /usr/bin/python2 -> python2.7
3544 -rwxr-xr-x 1 root root 3628904 Nov 28 18:51 /usr/bin/python2.7
   0 lrwxrwxrwx 1 root root      25 Feb  2 10:23 /usr/bin/python3 -> /etc/alternatives/python3
   0 lrwxrwxrwx 1 root root      16 Oct 25  2018 /usr/bin/python3-config -> python3.6-config
   4 -rwxr-xr-x 1 root root    1018 Oct 28  2017 /usr/bin/python3-jsondiff
   4 -rwxr-xr-x 1 root root    3661 Oct 28  2017 /usr/bin/python3-jsonpatch
   4 -rwxr-xr-x 1 root root    1342 May  1  2016 /usr/bin/python3-jsonpointer
   4 -rwxr-xr-x 1 root root     398 Nov 15  2017 /usr/bin/python3-jsonschema
4424 -rwxr-xr-x 2 root root 4526456 Nov 25 14:10 /usr/bin/python3.6
   0 lrwxrwxrwx 1 root root      33 Nov 25 14:10 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
4424 -rwxr-xr-x 2 root root 4526456 Nov 25 14:10 /usr/bin/python3.6m
   0 lrwxrwxrwx 1 root root      34 Nov 25 14:10 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
   0 lrwxrwxrwx 1 root root      10 Oct 25  2018 /usr/bin/python3m -> python3.6m
   0 lrwxrwxrwx 1 root root      17 Oct 25  2018 /usr/bin/python3m-config -> python3.6m-config
$ python -V
Python 2.7.17

$ python3 -V
Python 3.6.9
  • 现在walinuxagent运行良好。
$ sudo systemctl status walinuxagent
● walinuxagent.service - Azure Linux Agent
   Loaded: loaded (/lib/systemd/system/walinuxagent.service; enabled; vendor preset: enabled)
  Drop-In: /lib/system/system/walinuxagent.service.d
           └─10-Slice.conf, 11-CPUAccounting.conf, 12-CPUQuota.conf, 13-MemoryAccounting.conf
   Active: active (running) since Thu 2023-02-02 10:29:31 UTC; 5s ago
 Main PID: 10593 (python3)
    Tasks: 7 (limit: 4915)
   Memory: 32.4M
      CPU: 920ms
   CGroup: /azure.slice/walinuxagent.service
           ├─10593 /usr/bin/python3 -u /usr/sbin/waagent -daemon
           └─10632 python3 -u bin/WALinuxAgent-2.9.0.4-py2.7.egg -run-exthandlers

问题是我需要将 pythoin 3.6 升级到 python 3.8、3.9、3.10 或 3.11,而不会弄乱一切

更新 2:新问题

我设法安装python 3.6python 3.10,问题是当3.6在更新替代方案中选择了 ,则walinuxagent服务在 时工作正常netboxnetbox-rq而 则nginx服务不工作;相反的情况发生在3.10已选定。

一种解决方法是根据要启动的服务选择每个 Python 版本。有没有办法避免每次都这样做?

答案1

可能已经太晚了,但我通过更改服务配置以使用 python 版本 3.6 解决了这个问题。

sudo nano /lib/systemd/system/walinuxagent.service
#Change python3 by pnone-reload
sudo systemctl restart walinuxagent
#and check that the service is working
sudo systemctl status walinuxagent
walinuxagent.service - Azure Linux Agent
   Loaded: loaded (/lib/systemd/system/walinuxagent.service; enabled; vend
  Drop-In: /lib/systemd/system/walinuxagent.service.d
           └─10-Slice.conf, 11-CPUAccounting.conf, 12-CPUQuota.conf, 13-Me
   Active: active (running) since Thu 2023-04-06 12:39:18 UTC; 11s ago
 Main PID: 15298 (python3.6)
    Tasks: 2 (limit: 4915)

相关内容