admin.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. </itemizedlist>
  83. <command>backend</command> specifies the backend type. Currently
  84. supported types are:
  85. <itemizedlist>
  86. <listitem>
  87. <simpara>
  88. <command>memfile</command> &mdash; Lease information is
  89. stored on disk in a text file.
  90. </simpara>
  91. </listitem>
  92. <listitem>
  93. <simpara>
  94. <command>mysql</command> &mdash;
  95. Lease information is stored in a MySQL relational
  96. database.
  97. </simpara>
  98. </listitem>
  99. <listitem>
  100. <simpara>
  101. <command>pgsql</command> &mdash;
  102. Lease information is stored in a PostgreSQL relational
  103. database.
  104. </simpara>
  105. </listitem>
  106. </itemizedlist>
  107. Additional parameters may be needed, depending on your setup
  108. and specific operation: username, password and database name or
  109. the directory where specific files are located. See appropriate
  110. manual page for details (<command>man 8 kea-admin</command>).
  111. </para>
  112. </section>
  113. <section>
  114. <title>Supported Databases</title>
  115. <section>
  116. <title>memfile</title>
  117. <para>
  118. There are no special initialization steps necessary
  119. for the memfile backend. During the first run, both
  120. <command>kea-dhcp4</command> and <command>kea-dhcp6</command>
  121. will create an empty lease file if one is not
  122. present. Necessary disk write permission is required.
  123. </para>
  124. <!-- @todo: document lease file upgrades once they are implemented in kea-admin -->
  125. </section>
  126. <section>
  127. <title>MySQL</title>
  128. <para>
  129. The MySQL database must be properly set up if you want Kea to
  130. store information in MySQL. This section can be safely ignored
  131. if you chose to store the data in other backends.
  132. </para>
  133. <section id="mysql-database-create">
  134. <title>First Time Creation of Kea Database</title>
  135. <para>
  136. If you are setting the MySQL database for the first time,
  137. you need to create the database area within MySQL and set up
  138. the MySQL user ID under which Kea will access the database.
  139. This needs to be done manually: <command>kea-admin</command>
  140. is not able to do this for you.
  141. </para>
  142. <para>
  143. To create the database:
  144. <orderedlist>
  145. <listitem>
  146. <para>
  147. Log into MySQL as "root":
  148. <screen>
  149. $ <userinput>mysql -u root -p</userinput>
  150. Enter password:
  151. mysql>
  152. </screen>
  153. </para>
  154. </listitem>
  155. <listitem>
  156. <para>
  157. Create the MySQL database:
  158. <screen>
  159. mysql> <userinput>CREATE DATABASE <replaceable>database-name</replaceable>;</userinput>
  160. </screen>
  161. (<replaceable>database-name</replaceable> is the name
  162. you have chosen for the database.)
  163. </para>
  164. </listitem>
  165. <listitem>
  166. <para>
  167. Create the user under which Kea will access the database
  168. (and give it a password), then grant it access to the
  169. database tables:
  170. <screen>
  171. mysql> <userinput>CREATE USER '<replaceable>user-name</replaceable>'@'localhost' IDENTIFIED BY '<replaceable>password</replaceable>';</userinput>
  172. mysql> <userinput>GRANT ALL ON <replaceable>database-name</replaceable>.* TO '<replaceable>user-name</replaceable>'@'localhost';</userinput>
  173. </screen>
  174. (<replaceable>user-name</replaceable> and
  175. <replaceable>password</replaceable> are the user ID
  176. and password you are using to allow Keas access to the
  177. MySQL instance. All apostrophes in the command lines
  178. above are required.)
  179. </para>
  180. </listitem>
  181. <listitem>
  182. <para>
  183. At this point, you may elect to create the database
  184. tables. (Alternatively, you can exit MySQL and create
  185. the tables using the <command>kea-admin</command> tool,
  186. as explained below.) To do this:
  187. <screen>
  188. mysql> <userinput>CONNECT <replaceable>database-name</replaceable>;</userinput>
  189. mysql> <userinput>SOURCE <replaceable>path-to-kea</replaceable>/share/kea/scripts/mysql/dhcpdb_create.mysql</userinput>
  190. </screen>
  191. (<replaceable>path-to-kea</replaceable> is the
  192. location where you installed Kea.)
  193. </para>
  194. </listitem>
  195. <listitem>
  196. <para>
  197. Exit MySQL:
  198. <screen>
  199. mysql> <userinput>quit</userinput>
  200. Bye
  201. $
  202. </screen>
  203. </para>
  204. </listitem>
  205. </orderedlist>
  206. </para>
  207. <para>
  208. If you elected not to create the tables in step 4, you can do
  209. so now by running the <command>kea-admin</command> tool:
  210. <screen>
  211. $ <userinput>kea-admin lease-init mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -d <replaceable>database-name</replaceable></userinput>
  212. </screen>
  213. (Do not do this if you did create the tables in step 4.)
  214. <command>kea-admin</command> implements rudimentary checks:
  215. it will refuse to initialize a database that contains any
  216. existing tables. If you want to start from scratch, you
  217. must remove all data manually. (This process is a manual
  218. operation on purpose to avoid possibly irretrievable mistakes
  219. by <command>kea-admin</command>.)
  220. </para>
  221. </section>
  222. <section id="mysql-upgrade">
  223. <title>Upgrading a MySQL Database from an Earlier Version of Kea</title>
  224. <para>
  225. Sometimes a new Kea version may use newer database schema, so
  226. there will be a need to upgrade the existing database. This can
  227. be done using the <command>kea-admin lease-upgrade</command>
  228. command.
  229. </para>
  230. <para>
  231. To check the current version of the database, use the following command:
  232. <screen>
  233. $ <userinput>kea-admin lease-version mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -d <replaceable>database-name</replaceable></userinput>
  234. </screen>
  235. (See <xref linkend="kea-database-version"/> for a discussion
  236. about versioning.) If the version does not match the minimum
  237. required for the new version of Kea (as described in the
  238. release notes), the database needs to be upgraded.
  239. </para>
  240. <para>
  241. Before upgrading, please make sure that the database is
  242. backed up. The upgrade process does not discard any data but,
  243. depending on the nature of the changes, it may be impossible
  244. to subsequently downgrade to an earlier version. To perform
  245. an upgrade, issue the following command:
  246. <screen>
  247. $ <userinput>kea-admin lease-upgrade mysql -u <replaceable>database-user</replaceable> -p <replaceable>database-password</replaceable> -d <replaceable>database-name</replaceable></userinput>
  248. </screen>
  249. </para>
  250. </section>
  251. </section> <!-- end of MySQL sections -->
  252. <section>
  253. <title>PostgreSQL</title>
  254. <para>
  255. A PostgreSQL database must be set up if you want Kea to store
  256. lease and other information in PostgreSQL. This step can be
  257. safely ignored if you are using other database backends.
  258. </para>
  259. <section id="pgsql-database-create">
  260. <title>Manually Create the PostgreSQL Database and the Kea User</title>
  261. <para>
  262. The first task is to create both the lease database and the
  263. user under which the servers will access it. A number of steps
  264. are required:
  265. <orderedlist>
  266. <listitem>
  267. <para>
  268. Log into PostgreSQL as "root":
  269. <screen>
  270. $ <userinput>sudo -u postgres psql postgres</userinput>
  271. Enter password:
  272. postgres=#
  273. </screen>
  274. </para>
  275. </listitem>
  276. <listitem>
  277. <para>
  278. Create the database:
  279. <screen>
  280. postgres=#<userinput> CREATE DATABASE <replaceable>database-name</replaceable>;</userinput>
  281. CREATE DATABASE
  282. postgres=#
  283. </screen>
  284. (<replaceable>database-name</replaceable> is the name
  285. you have chosen for the database.)
  286. </para>
  287. </listitem>
  288. <listitem>
  289. <para>
  290. Create the user under which Kea will access the database
  291. (and give it a password), then grant it access to the
  292. database:
  293. <screen>
  294. postgres=#<userinput> CREATE USER <replaceable>user-name</replaceable> WITH PASSWORD '<replaceable>password</replaceable>';</userinput>
  295. CREATE ROLE
  296. postgres=#
  297. postgres=#<userinput> GRANT ALL PRIVILEGES ON DATABASE <replaceable>database-name</replaceable> TO <replaceable>user-name</replaceable>;</userinput>
  298. GRANT
  299. postgres=#
  300. </screen>
  301. </para>
  302. </listitem>
  303. <listitem>
  304. <para>
  305. Exit PostgreSQL:
  306. <screen>
  307. postgres=# <userinput>\q</userinput>
  308. Bye
  309. $
  310. </screen>
  311. </para>
  312. </listitem>
  313. <listitem>
  314. <para>
  315. Create the database tables using the new user's
  316. credentials and the dhcpdb_create.pgsql script supplied
  317. with Kea. After entering the following command, you
  318. will be prompted for the new user's password. When the
  319. command completes you will be returned to the shell
  320. prompt. You should see output similar to following:
  321. <screen>
  322. $ <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>
  323. Password for user <replaceable>user-name</replaceable>:
  324. CREATE TABLE
  325. CREATE INDEX
  326. CREATE INDEX
  327. CREATE TABLE
  328. CREATE INDEX
  329. CREATE TABLE
  330. START TRANSACTION
  331. INSERT 0 1
  332. INSERT 0 1
  333. INSERT 0 1
  334. COMMIT
  335. CREATE TABLE
  336. START TRANSACTION
  337. INSERT 0 1
  338. COMMIT
  339. $
  340. </screen>
  341. (<replaceable>path-to-kea</replaceable> is the location
  342. where you installed Kea.)
  343. </para>
  344. <para>
  345. If instead you encounter an error like:
  346. <screen>
  347. psql: FATAL: no pg_hba.conf entry for host "[local]", user "<replaceable>user-name</replaceable>", database "<replaceable>database-name</replaceable>", SSL off
  348. </screen>
  349. ... you will need to alter the PostgreSQL configuration.
  350. Kea uses password authentication when connecting to
  351. the database and must have the appropriate entries
  352. added to PostgreSQL's pg_hba.conf file. This file is
  353. normally located in the primary data directory for your
  354. PostgreSQL server. The precise path may vary but the
  355. default location for PostgreSQL 9.3 on Centos 6.5 is:
  356. <filename>/var/lib/pgsql/9.3/data/pg_hba.conf</filename>.
  357. </para>
  358. <para>
  359. Assuming Kea is running on the same host as PostgreSQL,
  360. adding lines similar to following should be sufficient to
  361. provide password-authenticated access to Kea's database:
  362. <screen>
  363. local <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> password
  364. host <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> 127.0.0.1/32 password
  365. host <replaceable>database-name</replaceable> <replaceable>user-name</replaceable> ::1/128 password
  366. </screen>
  367. </para>
  368. <para>
  369. Please consult your PostgreSQL user manual before making
  370. these changes as they may expose your other databases
  371. that you run on the same system.
  372. </para>
  373. </listitem>
  374. </orderedlist>
  375. </para>
  376. </section>
  377. <section>
  378. <title>Initialize the PostgreSQL Database Using kea-admin</title>
  379. <para>
  380. Support for PostgreSQL in <command>kea-admin</command> is
  381. currently not implemented.
  382. </para>
  383. <!-- @todo: document PgSQL upgrade once they are implemented in kea-admin -->
  384. </section>
  385. </section> <!-- end of PostgreSQL sections -->
  386. </section> <!-- End of Database sections -->
  387. </chapter>