lxc.sh.rst 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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-searx.env <utils/lxc-searx.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 searx-ubu1804
  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 searx-ubu1804 bash
  45. INFO: [searx-ubu1804] bash
  46. root@searx-ubu1804:/share/searx#
  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-searx.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`). To
  87. get the IP (URL) of the filtron service in the containers use ``show suite``
  88. command. To test instances from containers just open the URLs in your
  89. WEB-Browser::
  90. $ sudo ./utils/lxc.sh show suite | grep filtron
  91. [searx-ubu1604] INFO: (eth0) filtron: http://n.n.n.246:4004/ http://n.n.n.246/searx
  92. [searx-ubu1804] INFO: (eth0) filtron: http://n.n.n.147:4004/ http://n.n.n.147/searx
  93. [searx-ubu1910] INFO: (eth0) filtron: http://n.n.n.140:4004/ http://n.n.n.140/searx
  94. [searx-ubu2004] INFO: (eth0) filtron: http://n.n.n.18:4004/ http://n.n.n.18/searx
  95. [searx-fedora31] INFO: (eth0) filtron: http://n.n.n.46:4004/ http://n.n.n.46/searx
  96. [searx-archlinux] INFO: (eth0) filtron: http://n.n.n.32:4004/ http://n.n.n.32/searx
  97. To :ref:`install a nginx <installation nginx>` reverse proxy for filtron and
  98. morty use (or alternatively use :ref:`apache <installation apache>`)::
  99. sudo -H ./utils/lxc.sh cmd -- FORCE_TIMEOUT=0 ./utils/filtron.sh nginx install
  100. sudo -H ./utils/lxc.sh cmd -- FORCE_TIMEOUT=0 ./utils/morty.sh nginx install
  101. Running commands
  102. ================
  103. **Inside containers, you can use make or run scripts** from the
  104. :ref:`toolboxing`. By example: to setup a :ref:`buildhosts` and run the
  105. Makefile target ``test`` in the archlinux_ container::
  106. sudo -H ./utils/lxc.sh cmd searx-archlinux ./utils/searx.sh install buildhost
  107. sudo -H ./utils/lxc.sh cmd searx-archlinux make test
  108. Setup SearXNG buildhost
  109. =======================
  110. You can **install the SearXNG buildhost environment** into one or all containers.
  111. The installation procedure to set up a :ref:`build host<buildhosts>` takes its
  112. time. Installation in all containers will take more time (time for another cup
  113. of coffee).::
  114. sudo -H ./utils/lxc.sh cmd -- ./utils/searx.sh install buildhost
  115. To build (live) documentation inside a archlinux_ container::
  116. sudo -H ./utils/lxc.sh cmd searx-archlinux make docs.clean docs.live
  117. ...
  118. [I 200331 15:00:42 server:296] Serving on http://0.0.0.0:8080
  119. To get IP of the container and the port number *live docs* is listening::
  120. $ sudo ./utils/lxc.sh show suite | grep docs.live
  121. ...
  122. [searx-archlinux] INFO: (eth0) docs.live: http://n.n.n.12:8080/
  123. .. _lxc.sh help:
  124. Overview
  125. ========
  126. The ``--help`` output of the script is largely self-explanatory:
  127. .. program-output:: ../utils/lxc.sh --help
  128. .. _lxc-searx.env:
  129. SearXNG suite
  130. =============
  131. .. literalinclude:: ../../utils/lxc-searx.env
  132. :language: bash