admin.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2014;" >
  5. ]>
  6. <chapter id="admin">
  7. <title>Database administration</title>
  8. <section id="kea-admin">
  9. <title>kea-admin tool</title>
  10. <para>
  11. Kea is able to store leases in one of several supported databases.
  12. Additional types of data, like host reservation details, will
  13. be supported in the near future. To manage those databases, a
  14. tool called <command>kea-admin</command> was introduced. Currently
  15. it is able to initialize new database, check its version
  16. and perform database upgrade, if needed.
  17. </para>
  18. <para>
  19. Kea mantains separate version numbering for its database backends. These
  20. are independent of the Kea version. It is possible that the backend
  21. revision will stay the same through several Kea revisions. Likewise, it
  22. is possible that a backend may go up several times between two Kea
  23. revisions, if there were several changes introduced that required database
  24. schema change. Versions for each backend are independent, so a bump
  25. in MySQL version does not imply bump in the Postgres version.
  26. </para>
  27. <para>
  28. Backend versions are specified in major.minor format. Minor number is
  29. increased when there are backward compatibile changes introduced. For
  30. example, a new index is added. It is desirable, but not mandatory to
  31. have it. You can run on older database version if you want to. On
  32. the other hand, major number is increased when there's an incompatible
  33. change introduced, for example an extra column is added. If you try
  34. to run Kea software on a database that is too old (which is signified
  35. by mismatched major backend version number), Kea will refuse to run
  36. and an administrative action will be required to upgrade the database.
  37. </para>
  38. <para>
  39. <command>kea-admin</command> takes two mandatory parameters:
  40. <command>command</command> and <command>backend</command>. Additional,
  41. non-mandatory options may be specified. Currently supported commands
  42. are:
  43. <itemizedlist>
  44. <listitem>
  45. <simpara>
  46. <command>lease-init</command> &mdash;
  47. Initializes a new lease database. Useful during first Kea
  48. installation. The database is initialized to the latest version
  49. supported by the version of the software.
  50. </simpara>
  51. </listitem>
  52. <listitem>
  53. <simpara>
  54. <command>lease-version</command> &mdash;
  55. Reports lease database version. This is not necessarily
  56. equal to Kea version as each backend has its own versioning
  57. scheme.
  58. </simpara>
  59. </listitem>
  60. <listitem>
  61. <simpara>
  62. <command>lease-upgrade</command> &mdash;
  63. Conducts lease database upgrade. This is useful when
  64. migrating between old and new Kea versions.
  65. </simpara>
  66. </listitem>
  67. </itemizedlist>
  68. The <command>backend</command> specified backend type. Currently
  69. allowed backends are: memfile, mysql and pgsql. There are additional
  70. parameters that may be needed, depending on your setup and specific
  71. operation: specify username, password and database name or the directory
  72. where specific files are located. See appropriate manual page for
  73. details (<command>man 8 kea-admin</command>).
  74. </para>
  75. </section>
  76. <section>
  77. <title>memfile</title>
  78. <para>There are no special initialization steps necessary for memfile
  79. backend. During the first run, both <command>kea-dhcp4</command> and
  80. <command>kea-dhcp6</command> will create an empty lease file, if it is not
  81. present. Necessary disk write permission is required.
  82. </para>
  83. <!-- @todo: document lease file upgrades once they are implemented in kea-admin -->
  84. </section>
  85. <section>
  86. <title>MySQL</title>
  87. <para>
  88. MySQL database must be properly set up if you want Kea to store lease
  89. and other information in MySQL. This step can be safely skipped if you
  90. chose to store the data in other backends, like memfile or PosgreSQL.
  91. </para>
  92. <section id="mysql-database-create">
  93. <title>Initialize the MySQL Database using kea-admin</title>
  94. <para>
  95. There are two ways to initialize the database. The first one involves
  96. running <command>kea-admin</command> tool, which attempts to automate
  97. the process. It is convenient to use, but may not cover more complex
  98. cases. The second alternative is to run all the commands
  99. manually.
  100. </para>
  101. <para>
  102. When <command>kea-admin</command> is told to initialize the database, it
  103. assumes that the database and database user has been created. If not,
  104. please follow the necessary instructions in <xref
  105. linkend="mysql-database-create-manual" />.
  106. </para>
  107. <para>
  108. To initialize new MySQL database using <command>kea-admin</command>, use the
  109. following command:
  110. <screen>$ <userinput>kea-admin lease-init mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -d <replaceable>database-name</replaceable></userinput>
  111. </screen>
  112. <command>kea-admin</command> has rudimentary checks implemented. It will
  113. refuse to initialize a database that has any existing tables. If you want
  114. to start from scratch, you must remove existing data manually. This process
  115. is left manual on purpose to avoid mistakes that could not be undone.
  116. </para>
  117. </section>
  118. <section id="mysql-upgrade">
  119. <title>Upgrading MySQL database from earlier Kea versions</title>
  120. <para>Sometime a new Kea version may use newer database schema and there may
  121. be a need to upgrade existing database. This can be done using <command>kea-admin</command>.
  122. It is possible to check existing database version:
  123. <screen>$ <userinput>kea-admin lease-version mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -d <replaceable>database-name</replaceable></userinput>
  124. </screen>
  125. See <xref linkend="kea-admin"/> for a discussion about versioning.</para>
  126. <para>It may be required to run database upgrade. This process is designed
  127. to not discard any data, but depending on the nature of the changes, it
  128. may be impossible to downgrade to earlier Kea version. Please back up your
  129. database if you consider reverting to an earlier Kea version. To conduct
  130. an upgrade, the following command should be used:
  131. <screen>$ <userinput>kea-admin lease-upgrade mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -d <replaceable>database-name</replaceable></userinput>
  132. </screen>
  133. </para>
  134. </section>
  135. <section id="mysql-database-create-manual">
  136. <title>Manually create the MySQL Database and the Kea User</title>
  137. <note>
  138. <simpara>
  139. This paragraph explains how to create and initialize MySQL database
  140. manually. See <xref linkend="mysql-database-create" /> for a kea-admin,
  141. a tool that automates most of those steps.
  142. </simpara>
  143. </note>
  144. <para>
  145. The first task is to create both the lease database and the user under
  146. which the servers will access it. A number of steps are required:
  147. </para>
  148. <para>
  149. 1. Log into MySQL as "root":
  150. <screen>$ <userinput>mysql -u root -p</userinput>
  151. Enter password:<userinput/>
  152. :<userinput/>
  153. mysql></screen>
  154. </para>
  155. <para>
  156. 2. Create the database:
  157. <screen>mysql> <userinput>CREATE DATABASE <replaceable>database-name</replaceable>;</userinput></screen>
  158. (<replaceable>database-name</replaceable> is the name you
  159. have chosen for the database.)
  160. </para>
  161. <para>
  162. 3. Create the database tables by running the dhcpdb_create.mysql script supplied as part of Kea:
  163. <screen>mysql> <userinput>CONNECT <replaceable>database-name</replaceable>;</userinput>
  164. mysql> <userinput>SOURCE <replaceable>path-to-kea</replaceable>/share/kea/dhcpdb_create.mysql</userinput></screen>
  165. </para>
  166. <para>
  167. 4. Create the user under which Kea will access the database (and give it a password), then grant it access to the database tables:
  168. <screen>mysql> <userinput>CREATE USER '<replaceable>user-name</replaceable>'@'localhost' IDENTIFIED BY '<replaceable>password</replaceable>';</userinput>
  169. mysql> <userinput>GRANT ALL ON <replaceable>database-name</replaceable>.* TO '<replaceable>user-name</replaceable>'@'localhost';</userinput></screen>
  170. </para>
  171. <para>
  172. 5. Exit MySQL:
  173. <screen>mysql> <userinput>quit</userinput>
  174. Bye<userinput/>
  175. $</screen>
  176. </para>
  177. </section>
  178. </section> <!-- end of MySQL sections -->
  179. <section>
  180. <title>PostgreSQL</title>
  181. <para>
  182. PostgreSQL database must be properly set up if you want Kea to store lease
  183. and other information in PostgreSQL. This step can be safely skipped if you
  184. chose to store the data in other backends, like memfile or MySQL.
  185. </para>
  186. <section>
  187. <title>Initialize the PostgreSQL Database using kea-admin</title>
  188. <para>
  189. Support for PostgreSQL in kea-admin is currently not implemented.
  190. </para>
  191. <!-- @todo: document PgSQL upgrade once they are implemented in kea-admin -->
  192. </section>
  193. <section id="pgsql-database-create">
  194. <title>Create PostgreSQL Database and Kea User</title>
  195. <para>
  196. The next task is to create both the lease database and the user under which the servers will
  197. access it. A number of steps are required:
  198. </para>
  199. <para>
  200. 1. Log into PostgreSQL as "root":
  201. <screen>$ <userinput>sudo -u postgres psql postgres</userinput>
  202. Enter password:<userinput/>
  203. :<userinput/>
  204. postgres=#</screen>
  205. </para>
  206. <para>
  207. 2. Create the database:
  208. <screen>
  209. postgres=#<userinput> CREATE DATABASE <replaceable>database-name</replaceable>;</userinput>
  210. CREATE DATABASE
  211. postgres=#
  212. </screen>
  213. (<replaceable>database-name</replaceable> is the name you
  214. have chosen for the database.)
  215. </para>
  216. <para>
  217. 3. Create the user under which Kea will access the database (and give it a password), then grant it access to the database:
  218. <screen>postgres=#<userinput> CREATE USER <replaceable>user-name</replaceable> WITH PASSWORD '<replaceable>password</replaceable>';</userinput>
  219. CREATE ROLE
  220. postgres=#
  221. postgres=#<userinput> GRANT ALL PRIVILEGES ON DATABASE <replaceable>database-name</replaceable> TO <replaceable>user-name</replaceable>;</userinput>
  222. GRANT
  223. postgres=#
  224. </screen>
  225. </para>
  226. <para>
  227. 4. Exit PostgreSQL:
  228. <screen>postgres=# <userinput>\q</userinput>
  229. Bye<userinput/>
  230. $</screen>
  231. </para>
  232. <para>
  233. 5. Create the database tables using the new user's credentials and the dhcpdb_create.pgsql script supplied with Kea.
  234. After entering the following command, you will be prompted for the new
  235. user's password. When the command completes you will be returned to
  236. the shell prompt. You should see output similar to following:
  237. <screen>$ <userinput>psql -d <replaceable>database-name</replaceable> -U <replaceable>user-name</replaceable> -f <replaceable>path-to-kea</replaceable>/share/kea/dhcpdb_create.pgsql</userinput>
  238. Password for user <replaceable>user-name</replaceable>:
  239. CREATE TABLE
  240. CREATE INDEX
  241. CREATE INDEX
  242. CREATE TABLE
  243. CREATE INDEX
  244. CREATE TABLE
  245. START TRANSACTION
  246. INSERT 0 1
  247. INSERT 0 1
  248. INSERT 0 1
  249. COMMIT
  250. CREATE TABLE
  251. START TRANSACTION
  252. INSERT 0 1
  253. COMMIT
  254. $
  255. </screen>
  256. </para>
  257. <para>
  258. If instead you encounter an error like:
  259. </para>
  260. <screen>
  261. psql: FATAL: no pg_hba.conf entry for host "[local]", user "<replaceable>user-name</replaceable>", database "<replaceable>database-name</replaceable>", SSL off
  262. </screen>
  263. <para>
  264. ... you will need to alter the PostgreSQL configuration.
  265. Kea uses password authentication when connecting to the database and must
  266. have the appropriate entries added to PostgreSQL's pg_hba.conf file. This
  267. file is normally located in the primary data directory for your PostgreSQL
  268. server. The precise path may vary but the default location for PostgreSQL 9.3
  269. on Centos 6.5 is:
  270. <filename>/var/lib/pgsql/9.3/data/pg_hba.conf</filename>.
  271. Assuming Kea is running on the same host as PostgreSQL, adding lines similar
  272. to following should be sufficient to provide password-authenticated access to
  273. Kea's database:
  274. </para>
  275. <screen>
  276. local <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> password
  277. host <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> 127.0.0.1/32 password
  278. host <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> ::1/128 password
  279. </screen>
  280. <para>
  281. Please consult your PostgreSQL user manual before making these changes as they
  282. may expose your other databases that you run on the same system.
  283. </para>
  284. </section>
  285. </section> <!-- end of postgres sections -->
  286. </chapter>