Skip to content

Commit a07cab5

Browse files
Add files via upload
1 parent 9b2a8d7 commit a07cab5

File tree

2 files changed

+589
-0
lines changed

2 files changed

+589
-0
lines changed

autoinstall_script/README.md

Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
English | [中文](README_cn.md)
2+
# IvorySQL-AutoInstall — User Guide
3+
4+
5+
## 1. Project Introduction
6+
7+
IvorySQL-AutoInstall is a professional automated installation script designed to simplify the process of compiling and installing the IvorySQL database. With a simple configuration file, users can complete the entire workflow—from building from source to starting the service—with one command, without manually executing complex build commands and configuration steps.
8+
9+
### 1.1 Core Features
10+
- **Environment detection and validation**: Automatically detect the operating system type and version, and validate compatibility.
11+
- **Intelligent dependency management**: Automatically install build-time dependencies, supporting multiple platform package managers.
12+
- **Automated installation and configuration**: Automatically set permissions for the install directory, data directory, and log directory.
13+
- **Service integration**: Automatically create a systemd service (or a helper when systemd is absent) and configure environment variables.
14+
- **Comprehensive logging**: Record detailed installation steps to facilitate troubleshooting.
15+
- **Error handling and rollback**: Robust error detection and handling mechanisms.
16+
### 1.2 Supported Operating Systems
17+
| Family | Distribution/ID | Version Gate in Script | Notes |
18+
|---------------|------------------------------------------------------|---------------------------------------------------------|------------------------------|
19+
| RHEL Family | rhel / centos / almalinux / rocky / oracle | Explicitly **blocks 7**; code paths cover 8/9/10 | Oracle Linux has specifics |
20+
| Debian/Ubuntu | debian / ubuntu | Version validated; unsupported versions **fail fast** | Uses `apt` for dependencies |
21+
| SUSE Family | opensuse-leap / sles | openSUSE Leap **15**; SLES **12.5 / 15** | Uses `zypper` |
22+
| Arch | arch | Rolling release | Uses `pacman` |
23+
24+
> **Note**: CentOS 7 is **not** supported by this project.
25+
26+
---
27+
28+
## 2. Project Details
29+
30+
### 2.1 Configuration File Explained (`ivorysql.conf`)
31+
| Key | Required | Default | Description |
32+
|---------------|----------|---------|--------------------------------------------------------------|
33+
| INSTALL_DIR | Yes | None | Install directory for IvorySQL (absolute path required) |
34+
| DATA_DIR | Yes | None | Database data directory (absolute path required) |
35+
| LOG_DIR | Yes | None | Log directory (absolute path required) |
36+
| SERVICE_USER | Yes | None | Service user (must not be a reserved system account) |
37+
| SERVICE_GROUP | Yes | None | Service group (must not be a reserved system group) |
38+
39+
**Notes**
40+
- Paths must be absolute and contain no spaces.
41+
- User/group names must not be reserved names (e.g., `root`, `bin`, `daemon`).
42+
43+
**Example**
44+
```ini
45+
INSTALL_DIR=/usr/ivorysql
46+
DATA_DIR=/var/lib/ivorysql/data
47+
LOG_DIR=/var/log/ivorysql
48+
SERVICE_USER=ivorysql
49+
SERVICE_GROUP=ivorysql
50+
```
51+
52+
### 2.2 Dependency Management System
53+
54+
#### Core Dependencies (mandatory, installed automatically)
55+
- Toolchain: GCC, Make, Flex, Bison
56+
- Core libraries: readline, zlib, openssl
57+
- Perl environment: perl-core, perl-devel, perl-IPC-Run
58+
59+
#### Optional Dependencies (smart detection; feature disabled if missing)
60+
| Library | Probe Path(s) | Automatic Handling |
61+
|----------|----------------------------------------------------------|--------------------------------------------------|
62+
| ICU | `/usr/include/icu.h` or `/usr/include/unicode/utypes.h` | Add `--without-icu` if not detected |
63+
| libxml2 | `/usr/include/libxml2/libxml/parser.h` | Add `--without-libxml` if not detected |
64+
| Tcl | `/usr/include/tcl.h` | Add `--without-tcl` if not detected |
65+
| Perl dev | headers present | Add `--without-perl` if not detected |
66+
67+
#### OS-Specific Install Commands
68+
| OS | Commands |
69+
|-----------------------------|--------------------------------------------------------------------------|
70+
| CentOS/RHEL/Rocky/AlmaLinux/Oracle| `dnf group install "Development Tools"` <br> `dnf install readline-devel zlib-devel openssl-devel` |
71+
| Debian/Ubuntu | `apt-get install build-essential libreadline-dev zlib1g-dev libssl-dev` |
72+
| SUSE/SLES | `zypper install gcc make flex bison readline-devel zlib-devel libopenssl-devel` |
73+
| Arch Linux | `pacman -S base-devel readline zlib openssl` |
74+
75+
**Toolchain verification**
76+
```bash
77+
for cmd in gcc make flex bison; do
78+
command -v "$cmd" >/dev/null || echo "Warning: $cmd is not installed"
79+
done
80+
```
81+
82+
### 2.3 Build Process
83+
#### Configure
84+
```bash
85+
./configure --prefix="$INSTALL_DIR" --with-openssl --with-readline --without-icu \ # when ICU is not detected
86+
--without-libxml \ # when libxml2 is not detected
87+
--without-tcl \ # when Tcl is not detected
88+
--without-perl # when Perl dev env is not detected
89+
```
90+
91+
#### Parallel Compilation
92+
```bash
93+
make -j"$(nproc)"
94+
make install
95+
```
96+
97+
#### Post-Install
98+
- Ensure `$DATA_DIR` exists, `chmod 700`, and correct ownership.
99+
- Optionally append `$INSTALL_DIR/bin` to the service user's PATH.
100+
101+
### 2.4 Service Management System
102+
103+
#### **systemd Path**
104+
unit generated by the script
105+
```ini
106+
[Unit]
107+
Description=IvorySQL Database Server
108+
Documentation=https://www.ivorysql.org
109+
Requires=network.target local-fs.target
110+
After=network.target local-fs.target
111+
112+
[Service]
113+
Type=forking
114+
User=ivorysql
115+
Group=ivorysql
116+
Environment=PGDATA=/var/lib/ivorysql/data
117+
Environment=LD_LIBRARY_PATH=/usr/ivorysql/lib:/usr/ivorysql/lib/postgresql
118+
PIDFile=/var/lib/ivorysql/data/postmaster.pid
119+
OOMScoreAdjust=-1000
120+
ExecStart=/usr/ivorysql/bin/pg_ctl start -D ${PGDATA} -s -w -t 90
121+
ExecStop=/usr/ivorysql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
122+
ExecReload=/usr/ivorysql/bin/pg_ctl reload -D ${PGDATA}
123+
TimeoutSec=120
124+
Restart=on-failure
125+
RestartSec=5s
126+
127+
[Install]
128+
WantedBy=multi-user.target
129+
```
130+
131+
**Notes**
132+
- `PIDFile` is present in the generated unit.
133+
- `ExecStart` uses `-t 90` and `TimeoutSec` is **120** to match the script.
134+
- `OOMScoreAdjust=-1000` and `Type=forking` are configured.
135+
136+
#### **Non-systemd Path**
137+
- Helper script: `"$INSTALL_DIR/ivorysql-ctl"` (created by the script)
138+
- `start``pg_ctl start -D "$DATA_DIR" -s -w -t 90`
139+
- `stop``pg_ctl stop -D "$DATA_DIR" -s -m fast`
140+
- `reload``pg_ctl reload -D "$DATA_DIR"`
141+
- **Note**: The script also has an internal fallback `svc_start` path that uses `-t 60` when not leveraging the helper; the helper defaults to **90 seconds**.
142+
143+
### 2.5 Logging System
144+
145+
```
146+
/var/log/ivorysql/
147+
├── install_YYYYmmdd_HHMMSS.log # installer stdout
148+
├── error_YYYYmmdd_HHMMSS.log # installer stderr
149+
├── initdb_YYYYmmdd_HHMMSS.log # initdb logs
150+
└── postgresql.log # server runtime log
151+
```
152+
153+
- Ownership: `ivorysql:ivorysql`
154+
- Timestamped, step-tagged installer logs
155+
- PostgreSQL built-in runtime logging
156+
157+
**Runtime logging (PostgreSQL server)**:
158+
- On systemd-based distros, PostgreSQL **defaults to journald**. View logs via:
159+
```bash
160+
journalctl -u ivorysql -f
161+
```
162+
- To write logs to files, enable in `postgresql.conf`:
163+
```conf
164+
logging_collector = on
165+
log_directory = 'log'
166+
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
167+
```
168+
Then review `$DATA_DIR/log/` (you may symlink this path into `LOG_DIR` if desired).
169+
170+
---
171+
172+
## 3. User Guide
173+
174+
### 3.1 Preparation
175+
0. **Placement** (important):
176+
- This script **must reside inside the IvorySQL source repository**, typically at:
177+
```
178+
<repo-root>/IvorySQL-AutoInstaller/
179+
```
180+
- It **builds from the local source tree** already present on disk. The script **does not clone** sources.
181+
1. Switch to root:
182+
```bash
183+
su -
184+
# or
185+
sudo -i
186+
```
187+
188+
2. Enter the directory and add execute permission:
189+
```bash
190+
cd IvorySQL/IvorySQL-AutoInstaller
191+
```
192+
Add execute permission:
193+
```bash
194+
chmod +x AutoInstall.sh
195+
```
196+
197+
### 3.2 Configuration Changes (optional)
198+
1. Edit the configuration file:
199+
```bash
200+
nano ivorysql.conf
201+
```
202+
2. Reference (absolute paths only; `LOG_DIR` is required):
203+
```ini
204+
INSTALL_DIR=/usr/ivorysql
205+
DATA_DIR=/var/lib/ivorysql/data
206+
SERVICE_USER=ivorysql
207+
SERVICE_GROUP=ivorysql
208+
LOG_DIR=/var/log/ivorysql
209+
```
210+
211+
### 3.3 Start Installation
212+
```bash
213+
sudo bash AutoInstall.sh
214+
```
215+
216+
217+
### 3.4 Installation Verification (exact format from the script)
218+
```
219+
================ Installation succeeded ================
220+
221+
Install directory: /usr/ivorysql
222+
Data directory: /var/lib/ivorysql/data
223+
Log directory: /var/log/ivorysql
224+
Service: active
225+
Version: /usr/ivorysql/bin/postgres --version output
226+
227+
Useful commands:
228+
systemctl [start|stop|status] ivorysql
229+
journalctl -u ivorysql -f
230+
sudo -u ivorysql '/usr/ivorysql/bin/psql'
231+
232+
Install time: <date>
233+
Elapsed: <seconds>s
234+
Build: local-source Commit: N/A
235+
OS: <os_type> <os_version>
236+
```
237+
238+
### 3.5 Service Management Commands
239+
| Action | Command | Notes |
240+
|---|---|---|
241+
| Start | `systemctl start ivorysql` | Start the database service |
242+
| Stop | `systemctl stop ivorysql` | Stop the database service |
243+
| Status| `systemctl status ivorysql`| Inspect service state |
244+
| Logs | `journalctl -u ivorysql -f`| Follow service logs |
245+
| Reload| `systemctl reload ivorysql`| Reload configurations |
246+
| Connect | `sudo -u ivorysql /usr/ivorysql/bin/psql` | Connect to DB |
247+
| Version | `/usr/ivorysql/bin/postgres --version` | Show version |
248+
| Base Backup | `sudo -u ivorysql /usr/ivorysql/bin/pg_basebackup` | Create base backup |
249+
250+
---
251+
252+
## 4. Troubleshooting
253+
254+
### 4.1 Common Error Handling
255+
| Symptom | Likely Cause | Resolution |
256+
|---|---|---|
257+
| Configuration missing | Wrong file path | Ensure `ivorysql.conf` exists in the project directory |
258+
| Dependency install failed | Network or mirror issues | Check network; switch mirrors |
259+
| Build error | Unsupported environment | Check OS/version; inspect error log |
260+
| initdb failed | Ownership or permissions | `chown ivorysql:ivorysql /var/lib/ivorysql/data` |
261+
| Service failed | Port conflict or configuration | `ss -tulnp | grep 5432` |
262+
263+
### 4.2 Diagnostic Commands
264+
```bash
265+
systemctl status ivorysql -l --no-pager
266+
journalctl -u ivorysql --since "1 hour ago" --no-pager
267+
sudo -u ivorysql /usr/ivorysql/bin/postgres -D /var/lib/ivorysql/data -c logging_collector=on
268+
ls -l IvorySQL-AutoInstaller/ivorysql.conf
269+
cat IvorySQL-AutoInstaller/ivorysql.conf
270+
```
271+
272+
### 4.3 Log File Locations
273+
- Install logs: `/var/log/ivorysql/install_<timestamp>.log`
274+
- Error logs: `/var/log/ivorysql/error_<timestamp>.log`
275+
- initdb logs: `/var/log/ivorysql/initdb_<timestamp>.log`
276+
- DB logs: `$DATA_DIR/log/postgresql-*.log` (if logging_collector is enabled; you may symlink this directory into `LOG_DIR`)
277+
278+
### 4.4 Special Handling
279+
#### Rocky Linux 10 / Oracle Linux 10
280+
- Auto-enable CRB/Devel repositories for dev headers (e.g., `libxml2-devel`).
281+
- Fallback `--allowerasing` strategy when appropriate.
282+
- Check status:
283+
```bash
284+
grep "XML_SUPPORT" /var/log/ivorysql/install_*.log
285+
```
286+
287+
#### Perl Environment
288+
- Auto-check `FindBin`, `IPC::Run`. Install via package manager or CPAN if missing.
289+
```bash
290+
dnf install -y perl-IPC-Run
291+
PERL_MM_USE_DEFAULT=1 cpan -i IPC::Run FindBin
292+
perl -MFindBin -e 1
293+
perl -MIPC::Run -e 1
294+
```
295+
296+
---
297+
298+

0 commit comments

Comments
 (0)