lxc.sh.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. With the use of *Linux Containers* (LXC_) we can scale our tasks over a stack of
  13. containers, what we call the: *lxc suite*. The :ref:`lxc-searxng.env` is
  14. loaded by default, every time you start the ``lxc.sh`` script (*you do not need
  15. to care about*).
  16. .. sidebar:: further reading
  17. - snap_, `snapcraft LXD`_
  18. - LXC_, LXD_
  19. - `LXC/LXD Image Server`_
  20. - `LXD@github`_
  21. .. contents::
  22. :depth: 2
  23. :local:
  24. :backlinks: entry
  25. .. _lxd install:
  26. Install LXD
  27. ===========
  28. Before you can start with containers, you need to install and initiate LXD_
  29. once::
  30. $ snap install lxd
  31. $ lxd init --auto
  32. To make use of the containers from the *SearXNG suite*, you have to build the
  33. :ref:`LXC suite containers <lxc.sh help>` initial. But be warned, **this might
  34. take some time**::
  35. $ sudo -H ./utils/lxc.sh build
  36. .. sidebar:: hint
  37. If you have issues with the internet connectivity of your containers read
  38. section :ref:`internet connectivity docker`.
  39. A cup of coffee later, your LXC suite is build up and you can run whatever task
  40. you want / in a selected or even in all :ref:`LXC suite containers <lxc.sh
  41. help>`.
  42. .. _internet connectivity docker:
  43. Internet Connectivity & Docker
  44. ------------------------------
  45. .. sidebar:: further read
  46. - `Docker blocking network of existing LXC containers <https://github.com/docker/for-linux/issues/103>`__
  47. - `Docker and IPtables (fralef.me) <https://fralef.me/docker-and-iptables.html>`__
  48. - `Docker and iptables (docker.com) <https://docs.docker.com/network/iptables/#docker-on-a-router/>`__
  49. There is a conflict in the ``iptables`` setup of Docker & LXC. If you have
  50. docker installed, you may find that the internet connectivity of your LXD
  51. containers no longer work.
  52. Whenever docker is started (reboot) it sets the iptables policy for the
  53. ``FORWARD`` chain to ``DROP`` `[ref]
  54. <https://docs.docker.com/network/iptables/#docker-on-a-router>`__::
  55. $ sudo -H iptables-save | grep FORWARD
  56. :FORWARD ACCEPT [7048:7851230]
  57. :FORWARD DROP [7048:7851230]
  58. A handy solution of this problem might be to reset the policy for the
  59. ``FORWARD`` chain after the network has been initialized. For this create a
  60. file in the ``if-up`` section of the network (``/etc/network/if-up.d/iptable``)
  61. and insert the following lines::
  62. #!/bin/sh
  63. iptables -F FORWARD
  64. iptables -P FORWARD ACCEPT
  65. Don't forget to set the execution bit::
  66. sudo chmod ugo+x /etc/network/if-up.d/iptable
  67. Reboot your system and check the iptables rules::
  68. $ sudo -H iptables-save | grep FORWARD
  69. :FORWARD ACCEPT [7048:7851230]
  70. :FORWARD ACCEPT [7048:7851230]
  71. .. _searxng lxc suite:
  72. SearXNG LXC suite
  73. =================
  74. The intention of the *SearXNG LXC suite* is to build up a suite of containers
  75. for development tasks or :ref:`buildhosts <Setup SearXNG buildhost>` with a very
  76. small set of simple commands. At the end of the ``--help`` output the SearXNG
  77. suite from the :ref:`lxc-searxng.env` is introduced::
  78. $ sudo -H ./utils/lxc.sh --help
  79. ...
  80. LXC suite: searxng
  81. Suite includes installation of SearXNG
  82. images: ubu2004 ubu2204 fedora35 archlinux
  83. containers: searxng-ubu2004 searxng-ubu2204 searxng-fedora35 searxng-archlinux
  84. As shown above there are images and containers build up on this images. To show
  85. more info about the containers in the *SearXNG LXC suite* call ``show suite``.
  86. If this is the first time you make use of the SearXNG LXC suite, no containers
  87. are installed and the output is::
  88. $ sudo -H ./utils/lxc.sh show suite
  89. LXC suite (searxng-*)
  90. =====================
  91. +------+-------+------+------+------+-----------+
  92. | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
  93. +------+-------+------+------+------+-----------+
  94. WARN: container searxng-ubu2004 does not yet exists
  95. WARN: container searxng-ubu2204 does not yet exists
  96. WARN: container searxng-fedora35 does not yet exists
  97. WARN: container searxng-archlinux does not yet exists
  98. If you do not want to run a command or a build in all containers, **you can
  99. build just one**. Here by example in the container that is build upon the
  100. *archlinux* image::
  101. $ sudo -H ./utils/lxc.sh build searxng-archlinux
  102. $ sudo -H ./utils/lxc.sh cmd searxng-archlinux pwd
  103. Otherwise, to apply a command to all containers you can use::
  104. $ sudo -H ./utils/lxc.sh build
  105. $ sudo -H ./utils/lxc.sh cmd -- ls -la .
  106. Running commands
  107. ----------------
  108. **Inside containers, you can run scripts** from the :ref:`toolboxing` or run
  109. what ever command you need. By example, to start a bash use::
  110. $ sudo -H ./utils/lxc.sh cmd searxng-archlinux bash
  111. INFO: [searxng-archlinux] bash
  112. [root@searxng-archlinux SearXNG]#
  113. .. _Good to know:
  114. Good to know
  115. ------------
  116. Each container shares the root folder of the repository and the command
  117. ``utils/lxc.sh cmd`` **handle relative path names transparent**::
  118. $ pwd
  119. /share/SearXNG
  120. $ sudo -H ./utils/lxc.sh cmd searxng-archlinux pwd
  121. INFO: [searxng-archlinux] pwd
  122. /share/SearXNG
  123. The path ``/share/SearXNG`` will be different on your HOST system. The commands
  124. in the container are executed by the ``root`` inside of the container. Compare
  125. output of::
  126. $ ls -li Makefile
  127. 47712402 -rw-rw-r-- 1 markus markus 2923 Apr 19 13:52 Makefile
  128. $ sudo -H ./utils/lxc.sh cmd searxng-archlinux ls -li Makefile
  129. INFO: [searxng-archlinux] ls -li Makefile
  130. 47712402 -rw-rw-r-- 1 root root 2923 Apr 19 11:52 Makefile
  131. ...
  132. Since the path ``/share/SearXNG`` of the HOST system is wrapped into the
  133. container under the same name, the shown ``Makefile`` (inode ``47712402``) in
  134. the output is always the identical ``/share/SearXNG/Makefile`` from the HOST
  135. system. In the example shown above the owner of the path in the container is
  136. the ``root`` user of the container (and the timezone in the container is
  137. different to HOST system).
  138. .. _lxc.sh install suite:
  139. Install suite
  140. -------------
  141. .. sidebar:: further read
  142. - :ref:`working in containers`
  143. - :ref:`FORCE_TIMEOUT <FORCE_TIMEOUT>`
  144. To install the complete :ref:`SearXNG suite <lxc-searxng.env>` into **all** LXC_
  145. containers leave the container argument empty and run::
  146. $ sudo -H ./utils/lxc.sh build
  147. $ sudo -H ./utils/lxc.sh install suite
  148. To *build & install* suite only in one container you can use by example::
  149. $ sudo -H ./utils/lxc.sh build searxng-archlinux
  150. $ sudo -H ./utils/lxc.sh install suite searxng-archlinux
  151. The command above installs a SearXNG suite (see :ref:`installation scripts`).
  152. To :ref:`install a nginx <installation nginx>` reverse proxy (or alternatively
  153. use :ref:`apache <installation apache>`)::
  154. $ sudo -H ./utils/lxc.sh cmd -- FORCE_TIMEOUT=0 ./utils/searxng.sh install nginx
  155. Same operation just in one container of the suite::
  156. $ sudo -H ./utils/lxc.sh cmd searxng-archlinux FORCE_TIMEOUT=0 ./utils/searxng.sh install nginx
  157. The :ref:`FORCE_TIMEOUT <FORCE_TIMEOUT>` environment is set to zero to run the
  158. script without user interaction.
  159. To get the IP (URL) of the SearXNG service in the containers use ``show suite``
  160. command. To test instances from containers just open the URLs in your
  161. WEB-Browser::
  162. $ sudo ./utils/lxc.sh show suite | grep SEARXNG_URL
  163. [searxng-ubu2110] SEARXNG_URL : http://n.n.n.170/searxng
  164. [searxng-ubu2004] SEARXNG_URL : http://n.n.n.160/searxng
  165. [searxnggfedora35] SEARXNG_URL : http://n.n.n.150/searxng
  166. [searxng-archlinux] SEARXNG_URL : http://n.n.n.140/searxng
  167. Clean up
  168. --------
  169. If there comes the time you want to **get rid off all** the containers and
  170. **clean up local images** just type::
  171. $ sudo -H ./utils/lxc.sh remove
  172. $ sudo -H ./utils/lxc.sh remove images
  173. .. _Setup SearXNG buildhost:
  174. Setup SearXNG buildhost
  175. =======================
  176. You can **install the SearXNG buildhost environment** into one or all containers.
  177. The installation procedure to set up a :ref:`build host<buildhosts>` takes its
  178. time. Installation in all containers will take more time (time for another cup
  179. of coffee). ::
  180. sudo -H ./utils/lxc.sh cmd -- ./utils/searxng.sh install buildhost
  181. To build (live) documentation inside a archlinux_ container::
  182. sudo -H ./utils/lxc.sh cmd searxng-archlinux make docs.clean docs.live
  183. ...
  184. [I 200331 15:00:42 server:296] Serving on http://0.0.0.0:8080
  185. To get IP of the container and the port number *live docs* is listening::
  186. $ sudo ./utils/lxc.sh show suite | grep docs.live
  187. ...
  188. [searxng-archlinux] INFO: (eth0) docs.live: http://n.n.n.140:8080/
  189. .. _lxc.sh help:
  190. Command Help
  191. ============
  192. The ``--help`` output of the script is largely self-explanatory:
  193. .. program-output:: ../utils/lxc.sh --help
  194. .. _lxc-searxng.env:
  195. SearXNG suite config
  196. ====================
  197. The SearXNG suite is defined in the file :origin:`utils/lxc-searxng.env`:
  198. .. literalinclude:: ../../utils/lxc-searxng.env
  199. :language: bash