admin.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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 compatible changes
  33. introduced. For example, the addition of a new index. It is
  34. desirable, but not mandatory 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, perform a
  51. database upgrade, and dump lease data to a text file.
  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, PostgreSQL or
  86. CQL backends) to CSV text file. The first line of the file contains
  87. the column names. This is meant to be used as a diagnostic tool
  88. that provides a portable, human-readable form of lease data.
  89. </simpara>
  90. </listitem>
  91. </itemizedlist>
  92. <command>backend</command> specifies the backend type. Currently
  93. supported types are:
  94. <itemizedlist>
  95. <listitem>
  96. <simpara>
  97. <command>memfile</command> &mdash; Lease information is
  98. stored on disk in a text file.
  99. </simpara>
  100. </listitem>
  101. <listitem>
  102. <simpara>
  103. <command>mysql</command> &mdash;
  104. Lease information is stored in a MySQL relational
  105. database.
  106. </simpara>
  107. </listitem>
  108. <listitem>
  109. <simpara>
  110. <command>pgsql</command> &mdash;
  111. Lease information is stored in a PostgreSQL relational
  112. database.
  113. </simpara>
  114. </listitem>
  115. <listitem>
  116. <simpara>
  117. <command>cql</command> &mdash;
  118. Lease information is stored in a CQL database.
  119. </simpara>
  120. </listitem>
  121. </itemizedlist>
  122. Additional parameters may be needed, depending on your setup
  123. and specific operation: username, password and database name or
  124. the directory where specific files are located. See appropriate
  125. manual page for details (<command>man 8 kea-admin</command>).
  126. </para>
  127. </section>
  128. <section>
  129. <title>Supported Databases</title>
  130. <section>
  131. <title>memfile</title>
  132. <para>
  133. There are no special initialization steps necessary
  134. for the memfile backend. During the first run, both
  135. <command>kea-dhcp4</command> and <command>kea-dhcp6</command>
  136. will create an empty lease file if one is not
  137. present. Necessary disk write permission is required.
  138. </para>
  139. <section id="memfile-upgrade">
  140. <title>Upgrading Memfile Lease Files from an Earlier Version of Kea</title>
  141. <para>
  142. There are no special steps required to upgrade memfile lease files
  143. from an earlier version of Kea to a new version of Kea.
  144. During startup the servers will check the schema version of the lease
  145. files against their own. If there is a mismatch, the servers will
  146. automatically launch the LFC process to convert the files to the
  147. server's schema version. While this mechanism is primarily meant to
  148. ease the process of upgrading to newer versions of Kea, it can also
  149. be used for downgrading should the need arise. When upgrading, any
  150. values not present in the original lease files will be assigned
  151. appropriate default values. When downgrading, any data present in
  152. the files but not in the server's schema will be dropped.
  153. If you wish to convert the files manually, prior to starting the
  154. servers you may do so by running the LFC process yourself.
  155. See <xref linkend="kea-lfc"/> for more information.
  156. </para>
  157. </section>
  158. <!-- @todo: document lease file upgrades once they are implemented in kea-admin -->
  159. </section>
  160. <section>
  161. <title>MySQL</title>
  162. <para>
  163. The MySQL database must be properly set up if you want Kea to
  164. store information in MySQL. This section can be safely ignored
  165. if you chose to store the data in other backends.
  166. </para>
  167. <section id="mysql-database-create">
  168. <title>First Time Creation of Kea Database</title>
  169. <para>
  170. If you are setting the MySQL database for the first time,
  171. you need to create the database area within MySQL and set up
  172. the MySQL user ID under which Kea will access the database.
  173. This needs to be done manually: <command>kea-admin</command>
  174. is not able to do this for you.
  175. </para>
  176. <para>
  177. To create the database:
  178. <orderedlist>
  179. <listitem>
  180. <para>
  181. Log into MySQL as "root":
  182. <screen>
  183. $ <userinput>mysql -u root -p</userinput>
  184. Enter password:
  185. mysql>
  186. </screen>
  187. </para>
  188. </listitem>
  189. <listitem>
  190. <para>
  191. Create the MySQL database:
  192. <screen>
  193. mysql> <userinput>CREATE DATABASE <replaceable>database-name</replaceable>;</userinput>
  194. </screen>
  195. (<replaceable>database-name</replaceable> is the name
  196. you have chosen for the database.)
  197. </para>
  198. </listitem>
  199. <listitem>
  200. <para>
  201. Create the user under which Kea will access the database
  202. (and give it a password), then grant it access to the
  203. database tables:
  204. <screen>
  205. mysql> <userinput>CREATE USER '<replaceable>user-name</replaceable>'@'localhost' IDENTIFIED BY '<replaceable>password</replaceable>';</userinput>
  206. mysql> <userinput>GRANT ALL ON <replaceable>database-name</replaceable>.* TO '<replaceable>user-name</replaceable>'@'localhost';</userinput>
  207. </screen>
  208. (<replaceable>user-name</replaceable> and
  209. <replaceable>password</replaceable> are the user ID
  210. and password you are using to allow Keas access to the
  211. MySQL instance. All apostrophes in the command lines
  212. above are required.)
  213. </para>
  214. </listitem>
  215. <listitem>
  216. <para>
  217. At this point, you may elect to create the database
  218. tables. (Alternatively, you can exit MySQL and create
  219. the tables using the <command>kea-admin</command> tool,
  220. as explained below.) To do this:
  221. <screen>
  222. mysql> <userinput>CONNECT <replaceable>database-name</replaceable>;</userinput>
  223. mysql> <userinput>SOURCE <replaceable>path-to-kea</replaceable>/share/kea/scripts/mysql/dhcpdb_create.mysql</userinput>
  224. </screen>
  225. (<replaceable>path-to-kea</replaceable> is the
  226. location where you installed Kea.)
  227. </para>
  228. </listitem>
  229. <listitem>
  230. <para>
  231. Exit MySQL:
  232. <screen>
  233. mysql> <userinput>quit</userinput>
  234. Bye
  235. $
  236. </screen>
  237. </para>
  238. </listitem>
  239. </orderedlist>
  240. </para>
  241. <para>
  242. If you elected not to create the tables in step 4, you can do
  243. so now by running the <command>kea-admin</command> tool:
  244. <screen>
  245. $ <userinput>kea-admin lease-init mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -n <replaceable>database-name</replaceable></userinput>
  246. </screen>
  247. (Do not do this if you did create the tables in step 4.)
  248. <command>kea-admin</command> implements rudimentary checks:
  249. it will refuse to initialize a database that contains any
  250. existing tables. If you want to start from scratch, you
  251. must remove all data manually. (This process is a manual
  252. operation on purpose to avoid possibly irretrievable mistakes
  253. by <command>kea-admin</command>.)
  254. </para>
  255. </section>
  256. <section id="mysql-upgrade">
  257. <title>Upgrading a MySQL Database from an Earlier Version of Kea</title>
  258. <para>
  259. Sometimes a new Kea version may use newer database schema, so
  260. there will be a need to upgrade the existing database. This can
  261. be done using the <command>kea-admin lease-upgrade</command>
  262. command.
  263. </para>
  264. <para>
  265. To check the current version of the database, use the following command:
  266. <screen>
  267. $ <userinput>kea-admin lease-version mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -n <replaceable>database-name</replaceable></userinput>
  268. </screen>
  269. (See <xref linkend="kea-database-version"/> for a discussion
  270. about versioning.) If the version does not match the minimum
  271. required for the new version of Kea (as described in the
  272. release notes), the database needs to be upgraded.
  273. </para>
  274. <para>
  275. Before upgrading, please make sure that the database is
  276. backed up. The upgrade process does not discard any data but,
  277. depending on the nature of the changes, it may be impossible
  278. to subsequently downgrade to an earlier version. To perform
  279. an upgrade, issue the following command:
  280. <screen>
  281. $ <userinput>kea-admin lease-upgrade mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -n <replaceable>database-name</replaceable></userinput>
  282. </screen>
  283. </para>
  284. </section>
  285. </section> <!-- end of MySQL sections -->
  286. <section>
  287. <title>PostgreSQL</title>
  288. <para>
  289. A PostgreSQL database must be set up if you want Kea to store
  290. lease and other information in PostgreSQL. This step can be
  291. safely ignored if you are using other database backends.
  292. </para>
  293. <section id="pgsql-database-create">
  294. <title>Manually Create the PostgreSQL Database and the Kea User</title>
  295. <para>
  296. The first task is to create both the lease database and the
  297. user under which the servers will access it. A number of steps
  298. are required:
  299. <orderedlist>
  300. <listitem>
  301. <para>
  302. Log into PostgreSQL as "root":
  303. <screen>
  304. $ <userinput>sudo -u postgres psql postgres</userinput>
  305. Enter password:
  306. postgres=#
  307. </screen>
  308. </para>
  309. </listitem>
  310. <listitem>
  311. <para>
  312. Create the database:
  313. <screen>
  314. postgres=#<userinput> CREATE DATABASE <replaceable>database-name</replaceable>;</userinput>
  315. CREATE DATABASE
  316. postgres=#
  317. </screen>
  318. (<replaceable>database-name</replaceable> is the name
  319. you have chosen for the database.)
  320. </para>
  321. </listitem>
  322. <listitem>
  323. <para>
  324. Create the user under which Kea will access the database
  325. (and give it a password), then grant it access to the
  326. database:
  327. <screen>
  328. postgres=#<userinput> CREATE USER <replaceable>user-name</replaceable> WITH PASSWORD '<replaceable>password</replaceable>';</userinput>
  329. CREATE ROLE
  330. postgres=#
  331. postgres=#<userinput> GRANT ALL PRIVILEGES ON DATABASE <replaceable>database-name</replaceable> TO <replaceable>user-name</replaceable>;</userinput>
  332. GRANT
  333. postgres=#
  334. </screen>
  335. </para>
  336. </listitem>
  337. <listitem>
  338. <para>
  339. Exit PostgreSQL:
  340. <screen>
  341. postgres=# <userinput>\q</userinput>
  342. Bye
  343. $
  344. </screen>
  345. </para>
  346. </listitem>
  347. <listitem>
  348. <para>
  349. At this point you are ready to create the database tables.
  350. This can be done using the <command>kea-admin</command> tool
  351. as explained in the next section (recommended), or manually.
  352. To create the tables manually enter the following command.
  353. Note that PostgreSQL will prompt you to enter the new user's
  354. password you specified in Step 3. When the command completes
  355. you will be returned to the shell prompt. You should see output
  356. similar to following:
  357. <screen>
  358. $ <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>
  359. Password for user <replaceable>user-name</replaceable>:
  360. CREATE TABLE
  361. CREATE INDEX
  362. CREATE INDEX
  363. CREATE TABLE
  364. CREATE INDEX
  365. CREATE TABLE
  366. START TRANSACTION
  367. INSERT 0 1
  368. INSERT 0 1
  369. INSERT 0 1
  370. COMMIT
  371. CREATE TABLE
  372. START TRANSACTION
  373. INSERT 0 1
  374. COMMIT
  375. $
  376. </screen>
  377. (<replaceable>path-to-kea</replaceable> is the location
  378. where you installed Kea.)
  379. </para>
  380. <para>
  381. If instead you encounter an error like:
  382. <screen>
  383. psql: FATAL: no pg_hba.conf entry for host "[local]", user "<replaceable>user-name</replaceable>", database "<replaceable>database-name</replaceable>", SSL off
  384. </screen>
  385. ... you will need to alter the PostgreSQL configuration.
  386. Kea uses password authentication when connecting to
  387. the database and must have the appropriate entries
  388. added to PostgreSQL's pg_hba.conf file. This file is
  389. normally located in the primary data directory for your
  390. PostgreSQL server. The precise path may vary but the
  391. default location for PostgreSQL 9.3 on Centos 6.5 is:
  392. <filename>/var/lib/pgsql/9.3/data/pg_hba.conf</filename>.
  393. </para>
  394. <para>
  395. Assuming Kea is running on the same host as PostgreSQL,
  396. adding lines similar to following should be sufficient to
  397. provide password-authenticated access to Kea's database:
  398. <screen>
  399. local <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> password
  400. host <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> 127.0.0.1/32 password
  401. host <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> ::1/128 password
  402. </screen>
  403. </para>
  404. <para>
  405. These edits are primarily intended as a starting point
  406. not a definitive reference on PostgreSQL administration or
  407. database security. Please consult your PostgreSQL user
  408. manual before making these changes as they may expose
  409. other databases that you run. It may be necessary to
  410. restart PostgreSQL in order for these changes to take effect.
  411. </para>
  412. </listitem>
  413. </orderedlist>
  414. </para>
  415. </section>
  416. <section>
  417. <title>Initialize the PostgreSQL Database Using kea-admin</title>
  418. <para>
  419. If you elected not to create the tables manually, you can do
  420. so now by running the <command>kea-admin</command> tool:
  421. <screen>
  422. $ <userinput>kea-admin lease-init pgsql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -n <replaceable>database-name</replaceable></userinput>
  423. </screen>
  424. Do not do this if you already created the tables in manually.
  425. <command>kea-admin</command> implements rudimentary checks:
  426. it will refuse to initialize a database that contains any
  427. existing tables. If you want to start from scratch, you
  428. must remove all data manually. (This process is a manual
  429. operation on purpose to avoid possibly irretrievable mistakes
  430. by <command>kea-admin</command>.)
  431. </para>
  432. </section>
  433. <section id="pgsql-upgrade">
  434. <title>Upgrading a PostgreSQL Database from an Earlier Version of Kea</title>
  435. <para>
  436. Currently, PostgreSQL only supports Kea schema version 1.0 so no upgrades
  437. are available. As upgrades become available, <command>kea-admin</command>
  438. will support them.
  439. </para>
  440. </section>
  441. </section> <!-- end of PostgreSQL sections -->
  442. <section>
  443. <title>CQL (Cassandra)</title>
  444. <para>
  445. The CQL database must be properly set up if you want Kea to store
  446. information in CQL. This section can be safely ignored if you chose to
  447. store the data in other backends.
  448. </para>
  449. <section id="cql-database-create">
  450. <title>First Time Creation of Kea Database</title>
  451. <para>
  452. If you are setting up the CQL database for the first time, you need to
  453. create the keyspace area within CQL. This needs to be done manually:
  454. <command>kea-admin</command> is not able to do this for you.
  455. </para>
  456. <para>
  457. To create the database:
  458. <orderedlist>
  459. <listitem>
  460. <para>
  461. Export CQLSH_HOST environemnt variable:
  462. <screen>
  463. $ <userinput>export CQLSH_HOST=localhost</userinput>
  464. </screen>
  465. </para>
  466. </listitem>
  467. <listitem>
  468. <para>
  469. Log into CQL:
  470. <screen>
  471. $ <userinput>cqlsh</userinput>
  472. cql>
  473. </screen>
  474. </para>
  475. </listitem>
  476. <listitem>
  477. <para>
  478. Create the CQL keyspace:
  479. <screen>
  480. cql> <userinput>CREATE KEYSPACE keyspace-name WITH replication = {'class' : 'SimpleStrategy','replication_factor' : 1};</userinput>
  481. </screen>
  482. (<replaceable>keyspace-name</replaceable> is the name you have
  483. chosen for the keyspace)
  484. </para>
  485. </listitem>
  486. <listitem>
  487. <para>
  488. At this point, you may elect to create the database tables.
  489. (Alternatively, you can exit CQL and create the tables using the
  490. <command>kea-admin</command> tool, as explained below) To do this:
  491. <screen>
  492. <userinput>cqslh -k <replaceable>keyspace-name</replaceable> -f <replaceable>path-to-kea</replaceable>/share/kea/scripts/cql/dhcpdb_create.cql</userinput>
  493. </screen>
  494. (<replaceable>path-to-kea</replaceable> is the location where you
  495. installed Kea)
  496. </para>
  497. </listitem>
  498. </orderedlist>
  499. </para>
  500. <para>
  501. If you elected not to create the tables in step 4, you can do
  502. so now by running the <command>kea-admin</command> tool:
  503. <screen>
  504. $ <userinput>kea-admin lease-init cql -n <replaceable>database-name</replaceable></userinput>
  505. </screen>
  506. (Do not do this if you did create the tables in step 4.)
  507. <command>kea-admin</command> implements rudimentary checks:
  508. it will refuse to initialize a database that contains any
  509. existing tables. If you want to start from scratch, you
  510. must remove all data manually. (This process is a manual
  511. operation on purpose to avoid possibly irretrievable mistakes
  512. by <command>kea-admin</command>)
  513. </para>
  514. </section>
  515. <section id="cql-upgrade">
  516. <title>Upgrading a CQL Database from an Earlier Version of Kea</title>
  517. <para>
  518. Sometimes a new Kea version may use newer database schema, so
  519. there will be a need to upgrade the existing database. This can
  520. be done using the <command>kea-admin lease-upgrade</command>
  521. command.
  522. </para>
  523. <para>
  524. To check the current version of the database, use the following command:
  525. <screen>
  526. $ <userinput>kea-admin lease-version cql -n <replaceable>database-name</replaceable></userinput>
  527. </screen>
  528. (See <xref linkend="kea-database-version"/> for a discussion
  529. about versioning) If the version does not match the minimum
  530. required for the new version of Kea (as described in the
  531. release notes), the database needs to be upgraded.
  532. </para>
  533. <para>
  534. Before upgrading, please make sure that the database is
  535. backed up. The upgrade process does not discard any data but,
  536. depending on the nature of the changes, it may be impossible
  537. to subsequently downgrade to an earlier version. To perform
  538. an upgrade, issue the following command:
  539. <screen>
  540. $ <userinput>kea-admin lease-upgrade cql -n <replaceable>database-name</replaceable></userinput>
  541. </screen>
  542. </para>
  543. </section>
  544. </section> <!-- end of CQL sections -->
  545. <section>
  546. <title>Limitations related to the use of the SQL databases</title>
  547. <para>
  548. The lease expiration time is stored in the SQL database for each lease
  549. as a timestamp value. Kea developers observed that MySQL database doesn't
  550. accept timestamps beyond 2147483647 seconds (maximum signed 32-bit number)
  551. from the beginning of the epoch. At the same time, some versions of PostgreSQL
  552. do accept greater values but the value is altered when it is read back.
  553. For this reason the lease database backends put the restriction for the
  554. maximum timestamp to be stored in the database, which is equal to the
  555. maximum signed 32-bit number. This effectively means that the current
  556. Kea version can't store the leases which expiration time is later than
  557. 2147483647 seconds since the beginning of the epoch (around year 2038).
  558. </para>
  559. </section>
  560. </section> <!-- End of Database sections -->
  561. </chapter>