To automate the process, you must use styles.
The first category is paragraph styles. Among those, the Heading n (n=1 to 10) is intended to define the outline of your book: level 1 = chapter, level 2 = sub-chapter, etc. All you need to do is to assign the required style to the paragraph making the heading.
What this does is flagging the paragraphs so that Writer identifies them as members of the outline. A side-effect is the possibility to build automatically a table of contents and also to (cross-)reference the headings and their properties from elsewhere in the text.
Customizing Heading 1, you can alos add an automatic page break before the paragraph in setting the option in the Text Flow
tab of the style definition, so that your chapters always start on a new page. With advanced configuration, you can also constrain this page to always be a right page (odd-numbered).
The use of the Heading n family results in the definition of various fields. To get the chapter name in your header, Insert
>Field
>More Fields
. In the Document
tab, you find Type Chapter giving access to the outline properties. The Format list allows you to insert Chapter name, Chapter number or both. Level is the means to reference chapter (level 1), sub-chapter (level 2), etc.
The field insertion will impact all pages using the page style.
If you need pages with other information than chapter name, e.g. a specific header for TOC or no header at all for cover and back page, you must use other page styles for these pages.
I recommend you read the Writer Guide for an introduction about what can be done with styles and fields.
To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!
In case you need clarification, edit your question (not an answer which is reserved for solutions) or comment the relevant answer.