lxc.sh.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. .. _snap: https://snapcraft.io
  2. .. _snapcraft LXD: https://snapcraft.io/lxd
  3. .. _LXC/LXD Image Server: https://uk.images.linuxcontainers.org/
  4. .. _LXC: https://linuxcontainers.org/lxc/introduction/
  5. .. _LXD: https://linuxcontainers.org/lxd/introduction/
  6. .. _`LXD@github`: https://github.com/lxc/lxd
  7. .. _archlinux: https://www.archlinux.org/
  8. .. _lxc.sh:
  9. ================
  10. ``utils/lxc.sh``
  11. ================
  12. .. sidebar:: further reading
  13. - snap_, `snapcraft LXD`_
  14. - LXC_, LXD_
  15. - `LXC/LXD Image Server`_
  16. - `LXD@github`_
  17. With the use of *Linux Containers* (LXC_) we can scale our tasks over a stack of
  18. containers, what we call the: *lxc suite*. The *SearXNG suite*
  19. (:origin:`lxc-searxng.env <utils/lxc-searxng.env>`) is loaded by default, every time
  20. you start the ``lxc.sh`` script (*you do not need to care about*).
  21. Before you can start with containers, you need to install and initiate LXD_
  22. once::
  23. $ snap install lxd
  24. $ lxd init --auto
  25. To make use of the containers from the *SearXNG suite*, you have to build the
  26. :ref:`LXC suite containers <lxc.sh help>` initial. But be warned, **this might
  27. take some time**::
  28. $ sudo -H ./utils/lxc.sh build
  29. A cup of coffee later, your LXC suite is build up and you can run whatever task
  30. you want / in a selected or even in all :ref:`LXC suite containers <lxc.sh
  31. help>`.
  32. .. hint::
  33. If you see any problems with the internet connectivity of your
  34. containers read section :ref:`internet connectivity docker`.
  35. If you do not want to build all containers, **you can build just one**::
  36. $ sudo -H ./utils/lxc.sh build searxng-archlinux
  37. *Good to know ...*
  38. Each container shares the root folder of the repository and the command
  39. ``utils/lxc.sh cmd`` **handles relative path names transparent**, compare output
  40. of::
  41. $ sudo -H ./utils/lxc.sh cmd -- ls -la Makefile
  42. ...
  43. In the containers, you can run what ever you want, e.g. to start a bash use::
  44. $ sudo -H ./utils/lxc.sh cmd searxng-archlinux bash
  45. INFO: [searxng-archlinux] bash
  46. [root@searxng-archlinux SearXNG]#
  47. If there comes the time you want to **get rid off all** the containers and
  48. **clean up local images** just type::
  49. $ sudo -H ./utils/lxc.sh remove
  50. $ sudo -H ./utils/lxc.sh remove images
  51. .. _internet connectivity docker:
  52. Internet Connectivity & Docker
  53. ==============================
  54. .. sidebar:: further read
  55. - `Docker blocking network of existing LXC containers <https://github.com/docker/for-linux/issues/103>`__
  56. - `Docker and IPtables (fralef.me) <https://fralef.me/docker-and-iptables.html>`__
  57. - `Docker and iptables (docker.com) <https://docs.docker.com/network/iptables/#docker-on-a-router/>`__
  58. There is a conflict in the ``iptables`` setup of Docker & LXC. If you have
  59. docker installed, you may find that the internet connectivity of your LXD
  60. containers no longer work.
  61. Whenever docker is started (reboot) it sets the iptables policy for the
  62. ``FORWARD`` chain to ``DROP`` `[ref]
  63. <https://docs.docker.com/network/iptables/#docker-on-a-router>`__::
  64. $ sudo -H iptables-save | grep FORWARD
  65. :FORWARD ACCEPT [7048:7851230]
  66. :FORWARD DROP [7048:7851230]
  67. A handy solution of this problem might be to reset the policy for the
  68. ``FORWARD`` chain after the network has been initialized. For this create a
  69. file in the ``if-up`` section of the network (``/etc/network/if-up.d/iptable``)
  70. and insert the following lines::
  71. #!/bin/sh
  72. iptables -F FORWARD
  73. iptables -P FORWARD ACCEPT
  74. Don't forget to set the execution bit::
  75. sudo chmod ugo+x /etc/network/if-up.d/iptable
  76. Reboot your system and check the iptables rules::
  77. $ sudo -H iptables-save | grep FORWARD
  78. :FORWARD ACCEPT [7048:7851230]
  79. :FORWARD ACCEPT [7048:7851230]
  80. .. _lxc.sh install suite:
  81. Install suite
  82. =============
  83. To install the complete :ref:`SearXNG suite (includes searx, morty & filtron)
  84. <lxc-searxng.env>` into all LXC_ use::
  85. $ sudo -H ./utils/lxc.sh install suite
  86. The command above installs a SearXNG suite (see :ref:`installation scripts`).
  87. To :ref:`install a nginx <installation nginx>` reverse proxy (or alternatively
  88. use :ref:`apache <installation apache>`)::
  89. sudo -H ./utils/lxc.sh cmd -- FORCE_TIMEOUT=0 ./utils/searxng.sh install nginx
  90. To get the IP (URL) of the SearXNG service in the containers use ``show suite``
  91. command. To test instances from containers just open the URLs in your
  92. WEB-Browser::
  93. $ sudo ./utils/lxc.sh show suite | grep SEARXNG_URL
  94. [searxng-ubu2110] SEARXNG_URL : http://n.n.n.147/searxng
  95. [searxng-ubu2004] SEARXNG_URL : http://n.n.n.246/searxng
  96. [searxnggfedora35] SEARXNG_URL : http://n.n.n.140/searxng
  97. [searxng-archlinux] SEARXNG_URL : http://n.n.n.165/searxng
  98. Running commands
  99. ================
  100. **Inside containers, you can use make or run scripts** from the
  101. :ref:`toolboxing`. By example: to setup a :ref:`buildhosts` and run the
  102. Makefile target ``test`` in the archlinux_ container::
  103. sudo -H ./utils/lxc.sh cmd searxng-archlinux ./utils/searxng.sh install buildhost
  104. sudo -H ./utils/lxc.sh cmd searxng-archlinux make test
  105. Setup SearXNG buildhost
  106. =======================
  107. You can **install the SearXNG buildhost environment** into one or all containers.
  108. The installation procedure to set up a :ref:`build host<buildhosts>` takes its
  109. time. Installation in all containers will take more time (time for another cup
  110. of coffee).::
  111. sudo -H ./utils/lxc.sh cmd -- ./utils/searxng.sh install buildhost
  112. To build (live) documentation inside a archlinux_ container::
  113. sudo -H ./utils/lxc.sh cmd searxng-archlinux make docs.clean docs.live
  114. ...
  115. [I 200331 15:00:42 server:296] Serving on http://0.0.0.0:8080
  116. To get IP of the container and the port number *live docs* is listening::
  117. $ sudo ./utils/lxc.sh show suite | grep docs.live
  118. ...
  119. [searxng-archlinux] INFO: (eth0) docs.live: http://n.n.n.12:8080/
  120. .. _lxc.sh help:
  121. Overview
  122. ========
  123. The ``--help`` output of the script is largely self-explanatory:
  124. .. program-output:: ../utils/lxc.sh --help
  125. .. _lxc-searxng.env:
  126. SearXNG suite
  127. =============
  128. .. literalinclude:: ../../utils/lxc-searxng.env
  129. :language: bash