admin.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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>Kea Database Administration</title>
  8. <section id="kea-database-version">
  9. <title>Databases and Database Version Numbers</title>
  10. <para>
  11. Kea stores leases in one of several supported databases.
  12. As future versions of Kea are released, the structure of those
  13. databases will change. For example, Kea currently only stores
  14. lease information: in the future, additional data - such as host
  15. reservation details - will also be stored.
  16. </para>
  17. <para>
  18. A given version of Kea expects a particular structure in
  19. the database. It ensures this by checking the version of the
  20. database it is using. Separate version numbers are maintained for
  21. backend databases, independent of the version of Kea itself. It
  22. is possible that the backend database version will stay the same
  23. through several Kea revisions. Likewise, it is possible that the
  24. version of backend database may go up several revisions during a
  25. Kea upgrade. Versions for each database are independent, so an
  26. increment in the MySQL database version does not imply an increment
  27. in that of PostgreSQL.
  28. </para>
  29. <para>
  30. Backend versions are specified in
  31. a <replaceable>major.minor</replaceable> format. The minor
  32. number is increased when there are backward compatibile changes
  33. introduced. For example, the addition of a new index. It is
  34. desirable, but not mandatory to to apply such a change; you
  35. can run on older database version if you want to. (Although, in
  36. the example given, running without the new index may be at the
  37. expense of a performance penalty.) On the other hand, the major
  38. number is increased when an incompatible change is introduced,
  39. for example an extra column is added to a table. If you try to
  40. run Kea software on a database that is too old (as signified by
  41. mismatched backend major version number), Kea will refuse to run:
  42. administrative action will be required to upgrade the database.
  43. </para>
  44. </section>
  45. <section id="kea-admin">
  46. <title>The kea-admin Tool</title>
  47. <para>
  48. To manage the databases, Kea provides the
  49. <command>kea-admin</command> tool. It is able to initialize
  50. a new database, check its version number, and perform a
  51. database upgrade.
  52. </para>
  53. <para>
  54. <command>kea-admin</command> takes two mandatory
  55. parameters: <command>command</command> and
  56. <command>backend</command>. Additional, non-mandatory options
  57. may be specified. Currently supported commands are:
  58. <itemizedlist>
  59. <listitem>
  60. <simpara>
  61. <command>lease-init</command> &mdash;
  62. Initializes a new lease database. Useful during first
  63. Kea installation. The database is initialized to the
  64. latest version supported by the version of the software.
  65. </simpara>
  66. </listitem>
  67. <listitem>
  68. <simpara>
  69. <command>lease-version</command> &mdash;
  70. Reports the lease database version number. This is
  71. not necessarily equal to the Kea version number as
  72. each backend has its own versioning scheme.
  73. </simpara>
  74. </listitem>
  75. <listitem>
  76. <simpara>
  77. <command>lease-upgrade</command> &mdash;
  78. Conducts a lease database upgrade. This is useful when
  79. upgrading Kea.
  80. </simpara>
  81. </listitem>
  82. <listitem>
  83. <simpara>
  84. <command>lease-dump</command> &mdash;
  85. Dumps the contents of the lease database (for MySQL or PostgreSQL
  86. backends) to CSV text file. The first line of the file contains
  87. the column names.
  88. </simpara>
  89. </listitem>
  90. </itemizedlist>
  91. <command>backend</command> specifies the backend type. Currently
  92. supported types are:
  93. <itemizedlist>
  94. <listitem>
  95. <simpara>
  96. <command>memfile</command> &mdash; Lease information is
  97. stored on disk in a text file.
  98. </simpara>
  99. </listitem>
  100. <listitem>
  101. <simpara>
  102. <command>mysql</command> &mdash;
  103. Lease information is stored in a MySQL relational
  104. database.
  105. </simpara>
  106. </listitem>
  107. <listitem>
  108. <simpara>
  109. <command>pgsql</command> &mdash;
  110. Lease information is stored in a PostgreSQL relational
  111. database.
  112. </simpara>
  113. </listitem>
  114. </itemizedlist>
  115. Additional parameters may be needed, depending on your setup
  116. and specific operation: username, password and database name or
  117. the directory where specific files are located. See appropriate
  118. manual page for details (<command>man 8 kea-admin</command>).
  119. </para>
  120. </section>
  121. <section>
  122. <title>Supported Databases</title>
  123. <section>
  124. <title>memfile</title>
  125. <para>
  126. There are no special initialization steps necessary
  127. for the memfile backend. During the first run, both
  128. <command>kea-dhcp4</command> and <command>kea-dhcp6</command>
  129. will create an empty lease file if one is not
  130. present. Necessary disk write permission is required.
  131. </para>
  132. <!-- @todo: document lease file upgrades once they are implemented in kea-admin -->
  133. </section>
  134. <section>
  135. <title>MySQL</title>
  136. <para>
  137. The MySQL database must be properly set up if you want Kea to
  138. store information in MySQL. This section can be safely ignored
  139. if you chose to store the data in other backends.
  140. </para>
  141. <section id="mysql-database-create">
  142. <title>First Time Creation of Kea Database</title>
  143. <para>
  144. If you are setting the MySQL database for the first time,
  145. you need to create the database area within MySQL and set up
  146. the MySQL user ID under which Kea will access the database.
  147. This needs to be done manually: <command>kea-admin</command>
  148. is not able to do this for you.
  149. </para>
  150. <para>
  151. To create the database:
  152. <orderedlist>
  153. <listitem>
  154. <para>
  155. Log into MySQL as "root":
  156. <screen>
  157. $ <userinput>mysql -u root -p</userinput>
  158. Enter password:
  159. mysql>
  160. </screen>
  161. </para>
  162. </listitem>
  163. <listitem>
  164. <para>
  165. Create the MySQL database:
  166. <screen>
  167. mysql> <userinput>CREATE DATABASE <replaceable>database-name</replaceable>;</userinput>
  168. </screen>
  169. (<replaceable>database-name</replaceable> is the name
  170. you have chosen for the database.)
  171. </para>
  172. </listitem>
  173. <listitem>
  174. <para>
  175. Create the user under which Kea will access the database
  176. (and give it a password), then grant it access to the
  177. database tables:
  178. <screen>
  179. mysql> <userinput>CREATE USER '<replaceable>user-name</replaceable>'@'localhost' IDENTIFIED BY '<replaceable>password</replaceable>';</userinput>
  180. mysql> <userinput>GRANT ALL ON <replaceable>database-name</replaceable>.* TO '<replaceable>user-name</replaceable>'@'localhost';</userinput>
  181. </screen>
  182. (<replaceable>user-name</replaceable> and
  183. <replaceable>password</replaceable> are the user ID
  184. and password you are using to allow Keas access to the
  185. MySQL instance. All apostrophes in the command lines
  186. above are required.)
  187. </para>
  188. </listitem>
  189. <listitem>
  190. <para>
  191. At this point, you may elect to create the database
  192. tables. (Alternatively, you can exit MySQL and create
  193. the tables using the <command>kea-admin</command> tool,
  194. as explained below.) To do this:
  195. <screen>
  196. mysql> <userinput>CONNECT <replaceable>database-name</replaceable>;</userinput>
  197. mysql> <userinput>SOURCE <replaceable>path-to-kea</replaceable>/share/kea/scripts/mysql/dhcpdb_create.mysql</userinput>
  198. </screen>
  199. (<replaceable>path-to-kea</replaceable> is the
  200. location where you installed Kea.)
  201. </para>
  202. </listitem>
  203. <listitem>
  204. <para>
  205. Exit MySQL:
  206. <screen>
  207. mysql> <userinput>quit</userinput>
  208. Bye
  209. $
  210. </screen>
  211. </para>
  212. </listitem>
  213. </orderedlist>
  214. </para>
  215. <para>
  216. If you elected not to create the tables in step 4, you can do
  217. so now by running the <command>kea-admin</command> tool:
  218. <screen>
  219. $ <userinput>kea-admin lease-init mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -n <replaceable>database-name</replaceable></userinput>
  220. </screen>
  221. (Do not do this if you did create the tables in step 4.)
  222. <command>kea-admin</command> implements rudimentary checks:
  223. it will refuse to initialize a database that contains any
  224. existing tables. If you want to start from scratch, you
  225. must remove all data manually. (This process is a manual
  226. operation on purpose to avoid possibly irretrievable mistakes
  227. by <command>kea-admin</command>.)
  228. </para>
  229. </section>
  230. <section id="mysql-upgrade">
  231. <title>Upgrading a MySQL Database from an Earlier Version of Kea</title>
  232. <para>
  233. Sometimes a new Kea version may use newer database schema, so
  234. there will be a need to upgrade the existing database. This can
  235. be done using the <command>kea-admin lease-upgrade</command>
  236. command.
  237. </para>
  238. <para>
  239. To check the current version of the database, use the following command:
  240. <screen>
  241. $ <userinput>kea-admin lease-version mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -n <replaceable>database-name</replaceable></userinput>
  242. </screen>
  243. (See <xref linkend="kea-database-version"/> for a discussion
  244. about versioning.) If the version does not match the minimum
  245. required for the new version of Kea (as described in the
  246. release notes), the database needs to be upgraded.
  247. </para>
  248. <para>
  249. Before upgrading, please make sure that the database is
  250. backed up. The upgrade process does not discard any data but,
  251. depending on the nature of the changes, it may be impossible
  252. to subsequently downgrade to an earlier version. To perform
  253. an upgrade, issue the following command:
  254. <screen>
  255. $ <userinput>kea-admin lease-upgrade mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -n <replaceable>database-name</replaceable></userinput>
  256. </screen>
  257. </para>
  258. </section>
  259. </section> <!-- end of MySQL sections -->
  260. <section>
  261. <title>PostgreSQL</title>
  262. <para>
  263. A PostgreSQL database must be set up if you want Kea to store
  264. lease and other information in PostgreSQL. This step can be
  265. safely ignored if you are using other database backends.
  266. </para>
  267. <section id="pgsql-database-create">
  268. <title>Manually Create the PostgreSQL Database and the Kea User</title>
  269. <para>
  270. The first task is to create both the lease database and the
  271. user under which the servers will access it. A number of steps
  272. are required:
  273. <orderedlist>
  274. <listitem>
  275. <para>
  276. Log into PostgreSQL as "root":
  277. <screen>
  278. $ <userinput>sudo -u postgres psql postgres</userinput>
  279. Enter password:
  280. postgres=#
  281. </screen>
  282. </para>
  283. </listitem>
  284. <listitem>
  285. <para>
  286. Create the database:
  287. <screen>
  288. postgres=#<userinput> CREATE DATABASE <replaceable>database-name</replaceable>;</userinput>
  289. CREATE DATABASE
  290. postgres=#
  291. </screen>
  292. (<replaceable>database-name</replaceable> is the name
  293. you have chosen for the database.)
  294. </para>
  295. </listitem>
  296. <listitem>
  297. <para>
  298. Create the user under which Kea will access the database
  299. (and give it a password), then grant it access to the
  300. database:
  301. <screen>
  302. postgres=#<userinput> CREATE USER <replaceable>user-name</replaceable> WITH PASSWORD '<replaceable>password</replaceable>';</userinput>
  303. CREATE ROLE
  304. postgres=#
  305. postgres=#<userinput> GRANT ALL PRIVILEGES ON DATABASE <replaceable>database-name</replaceable> TO <replaceable>user-name</replaceable>;</userinput>
  306. GRANT
  307. postgres=#
  308. </screen>
  309. </para>
  310. </listitem>
  311. <listitem>
  312. <para>
  313. Exit PostgreSQL:
  314. <screen>
  315. postgres=# <userinput>\q</userinput>
  316. Bye
  317. $
  318. </screen>
  319. </para>
  320. </listitem>
  321. <listitem>
  322. <para>
  323. Create the database tables using the new user's
  324. credentials and the dhcpdb_create.pgsql script supplied
  325. with Kea. After entering the following command, you
  326. will be prompted for the new user's password. When the
  327. command completes you will be returned to the shell
  328. prompt. You should see output similar to following:
  329. <screen>
  330. $ <userinput>psql -d <replaceable>database-name</replaceable> -U <replaceable>user-name</replaceable> -f <replaceable>path-to-kea</replaceable>/share/kea/scripts/pgsql/dhcpdb_create.pgsql</userinput>
  331. Password for user <replaceable>user-name</replaceable>:
  332. CREATE TABLE
  333. CREATE INDEX
  334. CREATE INDEX
  335. CREATE TABLE
  336. CREATE INDEX
  337. CREATE TABLE
  338. START TRANSACTION
  339. INSERT 0 1
  340. INSERT 0 1
  341. INSERT 0 1
  342. COMMIT
  343. CREATE TABLE
  344. START TRANSACTION
  345. INSERT 0 1
  346. COMMIT
  347. $
  348. </screen>
  349. (<replaceable>path-to-kea</replaceable> is the location
  350. where you installed Kea.)
  351. </para>
  352. <para>
  353. If instead you encounter an error like:
  354. <screen>
  355. psql: FATAL: no pg_hba.conf entry for host "[local]", user "<replaceable>user-name</replaceable>", database "<replaceable>database-name</replaceable>", SSL off
  356. </screen>
  357. ... you will need to alter the PostgreSQL configuration.
  358. Kea uses password authentication when connecting to
  359. the database and must have the appropriate entries
  360. added to PostgreSQL's pg_hba.conf file. This file is
  361. normally located in the primary data directory for your
  362. PostgreSQL server. The precise path may vary but the
  363. default location for PostgreSQL 9.3 on Centos 6.5 is:
  364. <filename>/var/lib/pgsql/9.3/data/pg_hba.conf</filename>.
  365. </para>
  366. <para>
  367. Assuming Kea is running on the same host as PostgreSQL,
  368. adding lines similar to following should be sufficient to
  369. provide password-authenticated access to Kea's database:
  370. <screen>
  371. local <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> password
  372. host <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> 127.0.0.1/32 password
  373. host <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> ::1/128 password
  374. </screen>
  375. </para>
  376. <para>
  377. Please consult your PostgreSQL user manual before making
  378. these changes as they may expose your other databases
  379. that you run on the same system.
  380. </para>
  381. </listitem>
  382. </orderedlist>
  383. </para>
  384. </section>
  385. <section>
  386. <title>Initialize the PostgreSQL Database Using kea-admin</title>
  387. <para>
  388. Support for PostgreSQL in <command>kea-admin</command> is
  389. currently not implemented.
  390. </para>
  391. <!-- @todo: document PgSQL upgrade once they are implemented in kea-admin -->
  392. </section>
  393. </section> <!-- end of PostgreSQL sections -->
  394. <section>
  395. <title>Limitations related to the use of the SQL databases</title>
  396. <para>
  397. The lease expiration time is stored in the SQL database for each lease
  398. as a timestamp value. Kea developers observed that MySQL database doesn't
  399. accept timestamps beyond 2147483647 seconds (maximum signed 32-bit number)
  400. from the beginning of the epoch. At the same time, some versions of PostgreSQL
  401. do accept greater values but the value is altered when it is read back.
  402. For this reason the lease database backends put the restriction for the
  403. maximum timestamp to be stored in the database, which is equal to the
  404. maximum signed 32-bit number. This effectively means that the current
  405. Kea version can't store the leases which expiration time is later than
  406. 2147483647 seconds since the beginning of the epoch (around year 2038).
  407. </para>
  408. </section>
  409. </section> <!-- End of Database sections -->
  410. </chapter>