Update/rewrite unattended.iredmail.installation.html.

This commit is contained in:
Zhang Huangbin 2020-04-16 09:44:58 +08:00
parent 5a68c724f2
commit 8eea81bdfd
2 changed files with 79 additions and 270 deletions

View File

@ -1,154 +1,57 @@
# Perform silent/unattended iRedMail installation
iRedMail will store configrations in file iRedMail-x.y.z/config during
installation, and ask you whether to use it for installation directly
or create a new one.
[TOC]
You can create a sample config file by executing iRedMail installer:
## Summary
iRedMail installer stores its own configrations in file named `config` during
installation. For example, if you downloaded iRedMail-1.2 under `/root`, then
then file path is `/root/iRedMail-1.2/config`.
While launching the iRedMail installer, it detects whether there's an existing
config file, and asks for your confirmation to use it if found one. You can use
this procedure to perform unattended iRedMail installation.
## Generate a sample config file
To generate a sample config file, just run the installer:
```bash
# bash iRedMail.sh
bash iRedMail.sh
```
After config wizard dialogs, you will find file `config` under iRedMail root
directory. For example, `/root/iRedMail-0.8.7/config`. it will ask whether to
start installation or not, you can cancel it if you want.
After finished the configuration dialog, iRedMail installer prints your
configuration and ask for your confirmation to perform the actual installation.
You should abort it here since you just want to generate a sample config file.
You can copy this config file to deploy as many servers as you want, change
the hard-coded passwords in it if you want.
Feel free to open this `config` file, change the settings to match your real
deployment if you want.
How to deploy a new server with sample config file:
## Deploy a new server with a prepared config file
* Copy sample config file to new server, e.g. `/root/iRedMail-0.8.7/config`.
* Execute iRedMail installer with shell variables:
To deploy a new server with a prepared config file:
* Download iRedMail installer from website: [Download](https://www.iredmail.org/download.html).
* Upload iRedMail installer to new server and uncompress it. We assume the
uncompress directory is `/root/iRedMail-1.2/`.
* Upload the prepared config file to `/root/iRedMail-1.2/config` on new server.
* Now launch iRedMail installer with some environment variables:
```bash
# AUTO_USE_EXISTING_CONFIG_FILE=y \
AUTO_USE_EXISTING_CONFIG_FILE=y \
AUTO_INSTALL_WITHOUT_CONFIRM=y \
AUTO_CLEANUP_REMOVE_SENDMAIL=y \
AUTO_CLEANUP_REMOVE_MOD_PYTHON=y \
AUTO_CLEANUP_REPLACE_FIREWALL_RULES=y \
AUTO_CLEANUP_RESTART_IPTABLES=y \
AUTO_CLEANUP_RESTART_FIREWALL=y \
AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y \
AUTO_CLEANUP_RESTART_POSTFIX=n \
bash iRedMail.sh
```
## Sample Deployment
It's easy to understand what the variable names are used for:
Here's how i preform iRedMail tests every day with VMware Fusion on Mac OS X,
all are completed automatically with a shell command.
* Install a clean, basic/minimal OS (Debian/CentOS/OpenBSD/FreeBSD, etc), set
proper hostname, configure network, then shut down this server and create a
VMware snapshot named `Latest`. The snapshot name will be used in my shell
script, it needs a snapshot name to reverse VM to the clean OS.
* Revert VM to the latest snapshot (a clean, basic, minimal OS) with VMware
command line tool `vmrun`.
* Start this VM with `vmrun`, sleep 30 (or 60) seconds waiting for OS start up.
* Detect network connection to this VM, if it's up, upload required files with `scp`:
* the latest development edition of iRedMail
* source tarballs required by iRedMail (Roundcube, iRedAdmin, iRedAPD, etc)
* downloaded RHEL/CentOS/Debian/Ubuntu/OpenBSD binary packages, FreeBSD
distfiles etc. The most important one is a prepared iRedMail config file: iRedMail-x.y.z/config.
* Create/Update iRedMail installation status file: iRedMail-x.y.z/.status
to skip downloading source tarballs, etc.
* Perform installation via ssh like this:
```shell
ssh root@[SERVER] "cd /root/iRedMail/ && IREDMAIL_DEBUG='NO' AUTO_USE_EXISTING_CONFIG_FILE=y AUTO_INSTALL_WITHOUT_CONFIRM=y AUTO_CLEANUP_REMOVE_SENDMAIL=y AUTO_CLEANUP_REMOVE_MOD_PYTHON=y AUTO_CLEANUP_REPLACE_FIREWALL_RULES=y AUTO_CLEANUP_RESTART_IPTABLES=y AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y AUTO_CLEANUP_RESTART_POSTFIX=n bash iRedMail.sh"
```
* Reboot server.
It should complete in 2-3 minutes (uploading binary packages takes most time),
then i got a working iRedMail server. I do this many times every day.
I have 5 prepared iRedMail config files for different backends: OpenLDAP,
MySQL, MariaDB, PostgreSQL, ldapd (OpenBSD only). i run my script with an
option to install iRedMail with specified backend like below, the script will
upload proper config file to server:
```shell
# bash auto.centos7.sh ldap
# bash auto.centos7.sh mysql
# bash auto.centos7.sh pgsql
# bash auto.ubuntu14.sh mariadb
# bash auto.openbsd55.sh ldapd
```
Below is file of `auto.centos7.sh` mentioned above, it prepares VMware virtual
machine, then execute another script `c7.sh` to perform the real installation.
```shell
#!/usr/bin/env bash
# File: auto.centos7.sh
[ X"$#" != X'1' ] && echo 'No backend? ldap, mysql, pgsql' && exit 255
export backend="${1}"
export VMRUN='vmrun -T fusion'
export VM_USER_ROOT='root'
export VM_HOSTNAME='c7'
export VM="/Users/zhb/vm.packages/vm/CentOS-7-x86_64.vmwarevm/CentOS-7-x86_64.vmx"
echo "* Revert to the latest snapshot."
${VMRUN} revertToSnapshot ${VM} Latest
echo "* Start VM."
${VMRUN} start ${VM}
echo "* Sleep 30 seconds to wait VM start up."
sleep 30
echo "* Detect network status with ssh."
while :; do
ssh ${VM_USER_ROOT}@${VM_HOSTNAME} "exit"
if [ X"$?" == X'0' ]; then
break
else
sleep 5
fi
done
echo "* Start testing iRedMail."
sh ${VM_HOSTNAME}.sh ${backend}
```
```shell
#!/usr/bin/env bash
# File: c7.sh
[ X"$#" != X'1' ] && echo 'No backend?' && exit 255
backend="${1}"
# hostname of your VMware virtual machine set in Mac OS X /etc/hosts.
HOST="c7"
echo 'copying iRedMail ...'
scp -r ~/projects/iredmail/iRedMail root@${HOST}:~ >/dev/null
echo 'copying pkgs/misc ...'
scp -r misc root@${HOST}:~/iRedMail/pkgs/ >/dev/null
scp -r config.${backend} root@${HOST}:~/iRedMail/config >/dev/null
echo 'copying archives ...'
scp -r rhel/7/yum root@${HOST}:/var/cache/ >/dev/null
echo 'updating .status ...'
ssh root@${HOST} "echo export status_check_new_iredmail='DONE' > /root/iRedMail/.status"
ssh root@${HOST} "echo export status_fetch_pkgs='DONE' >> /root/iRedMail/.status"
ssh root@${HOST} "echo export status_fetch_misc='DONE' >> /root/iRedMail/.status"
ssh root@${HOST} "echo export status_cleanup_update_clamav_signatures='DONE' >> /root/iRedMail/.status"
ssh root@${HOST} "cd /root/iRedMail/ && yum clean metadata && AUTO_USE_EXISTING_CONFIG_FILE=y AUTO_INSTALL_WITHOUT_CONFIRM=y AUTO_CLEANUP_REMOVE_SENDMAIL=y AUTO_CLEANUP_REMOVE_MOD_PYTHON=y AUTO_CLEANUP_REPLACE_FIREWALL_RULES=y AUTO_CLEANUP_RESTART_IPTABLES=y AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y AUTO_CLEANUP_RESTART_POSTFIX=n bash iRedMail.sh"
ssh root@${HOST} "/usr/bin/systemctl stop firewalld"
#ssh root@${HOST} "mkdir /root/pro && cp /var/www/iredadmin/settings.py /root/pro/"
#scp -r clamav/* root@${HOST}:/var/lib/clamav/
#ssh root@${HOST} "chown clamupdate:clamupdate /var/lib/clamav/*"
ssh root@${HOST} "echo 'reboot'; reboot"
```
* `AUTO_USE_EXISTING_CONFIG_FILE=y`: Use existing `config` file without asking for confirmation.
* `AUTO_INSTALL_WITHOUT_CONFIRM=y`: Start the installation without asking for confirmation.
* `AUTO_CLEANUP_REMOVE_SENDMAIL=y`: Remove `sendmail` package without asking for confirmation.
* `AUTO_CLEANUP_REPLACE_FIREWALL_RULES=y`: Copy and use the firewall rules shipped in iRedMail installer.
* `AUTO_CLEANUP_RESTART_FIREWALL=y`: Restart firewall service without asking for confirmation.
* `AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y`: Copy and use the MySQL (server) config file shipped in iRedMail installer.

View File

@ -16,154 +16,60 @@
<span>iRedMail</span>
</a>
&nbsp;&nbsp;//&nbsp;&nbsp;<a href="./index.html">Document Index</a></div><h1 id="perform-silentunattended-iredmail-installation">Perform silent/unattended iRedMail installation</h1>
<p>iRedMail will store configrations in file iRedMail-x.y.z/config during
installation, and ask you whether to use it for installation directly
or create a new one.</p>
<p>You can create a sample config file by executing iRedMail installer:</p>
<pre><code class="bash"># bash iRedMail.sh
<div class="toc">
<ul>
<li><a href="#perform-silentunattended-iredmail-installation">Perform silent/unattended iRedMail installation</a><ul>
<li><a href="#summary">Summary</a></li>
<li><a href="#generate-a-sample-config-file">Generate a sample config file</a></li>
<li><a href="#deploy-a-new-server-with-a-prepared-config-file">Deploy a new server with a prepared config file</a></li>
</ul>
</li>
</ul>
</div>
<h2 id="summary">Summary</h2>
<p>iRedMail installer stores its own configrations in file named <code>config</code> during
installation. For example, if you downloaded iRedMail-1.2 under <code>/root</code>, then
then file path is <code>/root/iRedMail-1.2/config</code>.</p>
<p>While launching the iRedMail installer, it detects whether there's an existing
config file, and asks for your confirmation to use it if found one. You can use
this procedure to perform unattended iRedMail installation.</p>
<h2 id="generate-a-sample-config-file">Generate a sample config file</h2>
<p>To generate a sample config file, just run the installer:</p>
<pre><code class="bash">bash iRedMail.sh
</code></pre>
<p>After config wizard dialogs, you will find file <code>config</code> under iRedMail root
directory. For example, <code>/root/iRedMail-0.8.7/config</code>. it will ask whether to
start installation or not, you can cancel it if you want.</p>
<p>You can copy this config file to deploy as many servers as you want, change
the hard-coded passwords in it if you want.</p>
<p>How to deploy a new server with sample config file:</p>
<p>After finished the configuration dialog, iRedMail installer prints your
configuration and ask for your confirmation to perform the actual installation.
You should abort it here since you just want to generate a sample config file.</p>
<p>Feel free to open this <code>config</code> file, change the settings to match your real
deployment if you want.</p>
<h2 id="deploy-a-new-server-with-a-prepared-config-file">Deploy a new server with a prepared config file</h2>
<p>To deploy a new server with a prepared config file:</p>
<ul>
<li>Copy sample config file to new server, e.g. <code>/root/iRedMail-0.8.7/config</code>.</li>
<li>Execute iRedMail installer with shell variables:</li>
<li>Download iRedMail installer from website: <a href="https://www.iredmail.org/download.html">Download</a>.</li>
<li>Upload iRedMail installer to new server and uncompress it. We assume the
uncompress directory is <code>/root/iRedMail-1.2/</code>.</li>
<li>Upload the prepared config file to <code>/root/iRedMail-1.2/config</code> on new server.</li>
<li>Now launch iRedMail installer with some environment variables:</li>
</ul>
<pre><code class="bash"># AUTO_USE_EXISTING_CONFIG_FILE=y \
<pre><code class="bash">AUTO_USE_EXISTING_CONFIG_FILE=y \
AUTO_INSTALL_WITHOUT_CONFIRM=y \
AUTO_CLEANUP_REMOVE_SENDMAIL=y \
AUTO_CLEANUP_REMOVE_MOD_PYTHON=y \
AUTO_CLEANUP_REPLACE_FIREWALL_RULES=y \
AUTO_CLEANUP_RESTART_IPTABLES=y \
AUTO_CLEANUP_RESTART_FIREWALL=y \
AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y \
AUTO_CLEANUP_RESTART_POSTFIX=n \
bash iRedMail.sh
</code></pre>
<h2 id="sample-deployment">Sample Deployment</h2>
<p>Here's how i preform iRedMail tests every day with VMware Fusion on Mac OS X,
all are completed automatically with a shell command.</p>
<p>It's easy to understand what the variable names are used for:</p>
<ul>
<li>
<p>Install a clean, basic/minimal OS (Debian/CentOS/OpenBSD/FreeBSD, etc), set
proper hostname, configure network, then shut down this server and create a
VMware snapshot named <code>Latest</code>. The snapshot name will be used in my shell
script, it needs a snapshot name to reverse VM to the clean OS.</p>
</li>
<li>
<p>Revert VM to the latest snapshot (a clean, basic, minimal OS) with VMware
command line tool <code>vmrun</code>.</p>
</li>
<li>
<p>Start this VM with <code>vmrun</code>, sleep 30 (or 60) seconds waiting for OS start up.</p>
</li>
<li>
<p>Detect network connection to this VM, if it's up, upload required files with <code>scp</code>:</p>
</li>
<li>the latest development edition of iRedMail</li>
<li>source tarballs required by iRedMail (Roundcube, iRedAdmin, iRedAPD, etc)</li>
<li>
<p>downloaded RHEL/CentOS/Debian/Ubuntu/OpenBSD binary packages, FreeBSD
distfiles etc. The most important one is a prepared iRedMail config file: iRedMail-x.y.z/config.</p>
</li>
<li>
<p>Create/Update iRedMail installation status file: iRedMail-x.y.z/.status
to skip downloading source tarballs, etc.</p>
</li>
<li>
<p>Perform installation via ssh like this:</p>
</li>
</ul>
<pre><code class="shell">ssh root@[SERVER] &quot;cd /root/iRedMail/ &amp;&amp; IREDMAIL_DEBUG='NO' AUTO_USE_EXISTING_CONFIG_FILE=y AUTO_INSTALL_WITHOUT_CONFIRM=y AUTO_CLEANUP_REMOVE_SENDMAIL=y AUTO_CLEANUP_REMOVE_MOD_PYTHON=y AUTO_CLEANUP_REPLACE_FIREWALL_RULES=y AUTO_CLEANUP_RESTART_IPTABLES=y AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y AUTO_CLEANUP_RESTART_POSTFIX=n bash iRedMail.sh&quot;
</code></pre>
<ul>
<li>Reboot server.</li>
</ul>
<p>It should complete in 2-3 minutes (uploading binary packages takes most time),
then i got a working iRedMail server. I do this many times every day.</p>
<p>I have 5 prepared iRedMail config files for different backends: OpenLDAP,
MySQL, MariaDB, PostgreSQL, ldapd (OpenBSD only). i run my script with an
option to install iRedMail with specified backend like below, the script will
upload proper config file to server:</p>
<pre><code class="shell"># bash auto.centos7.sh ldap
# bash auto.centos7.sh mysql
# bash auto.centos7.sh pgsql
# bash auto.ubuntu14.sh mariadb
# bash auto.openbsd55.sh ldapd
</code></pre>
<p>Below is file of <code>auto.centos7.sh</code> mentioned above, it prepares VMware virtual
machine, then execute another script <code>c7.sh</code> to perform the real installation.</p>
<pre><code class="shell">#!/usr/bin/env bash
# File: auto.centos7.sh
[ X&quot;$#&quot; != X'1' ] &amp;&amp; echo 'No backend? ldap, mysql, pgsql' &amp;&amp; exit 255
export backend=&quot;${1}&quot;
export VMRUN='vmrun -T fusion'
export VM_USER_ROOT='root'
export VM_HOSTNAME='c7'
export VM=&quot;/Users/zhb/vm.packages/vm/CentOS-7-x86_64.vmwarevm/CentOS-7-x86_64.vmx&quot;
echo &quot;* Revert to the latest snapshot.&quot;
${VMRUN} revertToSnapshot ${VM} Latest
echo &quot;* Start VM.&quot;
${VMRUN} start ${VM}
echo &quot;* Sleep 30 seconds to wait VM start up.&quot;
sleep 30
echo &quot;* Detect network status with ssh.&quot;
while :; do
ssh ${VM_USER_ROOT}@${VM_HOSTNAME} &quot;exit&quot;
if [ X&quot;$?&quot; == X'0' ]; then
break
else
sleep 5
fi
done
echo &quot;* Start testing iRedMail.&quot;
sh ${VM_HOSTNAME}.sh ${backend}
</code></pre>
<pre><code class="shell">#!/usr/bin/env bash
# File: c7.sh
[ X&quot;$#&quot; != X'1' ] &amp;&amp; echo 'No backend?' &amp;&amp; exit 255
backend=&quot;${1}&quot;
# hostname of your VMware virtual machine set in Mac OS X /etc/hosts.
HOST=&quot;c7&quot;
echo 'copying iRedMail ...'
scp -r ~/projects/iredmail/iRedMail root@${HOST}:~ &gt;/dev/null
echo 'copying pkgs/misc ...'
scp -r misc root@${HOST}:~/iRedMail/pkgs/ &gt;/dev/null
scp -r config.${backend} root@${HOST}:~/iRedMail/config &gt;/dev/null
echo 'copying archives ...'
scp -r rhel/7/yum root@${HOST}:/var/cache/ &gt;/dev/null
echo 'updating .status ...'
ssh root@${HOST} &quot;echo export status_check_new_iredmail='DONE' &gt; /root/iRedMail/.status&quot;
ssh root@${HOST} &quot;echo export status_fetch_pkgs='DONE' &gt;&gt; /root/iRedMail/.status&quot;
ssh root@${HOST} &quot;echo export status_fetch_misc='DONE' &gt;&gt; /root/iRedMail/.status&quot;
ssh root@${HOST} &quot;echo export status_cleanup_update_clamav_signatures='DONE' &gt;&gt; /root/iRedMail/.status&quot;
ssh root@${HOST} &quot;cd /root/iRedMail/ &amp;&amp; yum clean metadata &amp;&amp; AUTO_USE_EXISTING_CONFIG_FILE=y AUTO_INSTALL_WITHOUT_CONFIRM=y AUTO_CLEANUP_REMOVE_SENDMAIL=y AUTO_CLEANUP_REMOVE_MOD_PYTHON=y AUTO_CLEANUP_REPLACE_FIREWALL_RULES=y AUTO_CLEANUP_RESTART_IPTABLES=y AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y AUTO_CLEANUP_RESTART_POSTFIX=n bash iRedMail.sh&quot;
ssh root@${HOST} &quot;/usr/bin/systemctl stop firewalld&quot;
#ssh root@${HOST} &quot;mkdir /root/pro &amp;&amp; cp /var/www/iredadmin/settings.py /root/pro/&quot;
#scp -r clamav/* root@${HOST}:/var/lib/clamav/
#ssh root@${HOST} &quot;chown clamupdate:clamupdate /var/lib/clamav/*&quot;
ssh root@${HOST} &quot;echo 'reboot'; reboot&quot;
</code></pre><div class="footer">
<li><code>AUTO_USE_EXISTING_CONFIG_FILE=y</code>: Use existing <code>config</code> file without asking for confirmation.</li>
<li><code>AUTO_INSTALL_WITHOUT_CONFIRM=y</code>: Start the installation without asking for confirmation.</li>
<li><code>AUTO_CLEANUP_REMOVE_SENDMAIL=y</code>: Remove <code>sendmail</code> package without asking for confirmation.</li>
<li><code>AUTO_CLEANUP_REPLACE_FIREWALL_RULES=y</code>: Copy and use the firewall rules shipped in iRedMail installer.</li>
<li><code>AUTO_CLEANUP_RESTART_FIREWALL=y</code>: Restart firewall service without asking for confirmation.</li>
<li><code>AUTO_CLEANUP_REPLACE_MYSQL_CONFIG=y</code>: Copy and use the MySQL (server) config file shipped in iRedMail installer.</li>
</ul><div class="footer">
<p style="text-align: center; color: grey;">All documents are available in <a href="https://github.com/iredmail/docs/">GitHub repository</a>, and published under <a href="http://creativecommons.org/licenses/by-nd/3.0/us/" target="_blank">Creative Commons</a> license. You can <a href="https://github.com/iredmail/docs/archive/master.zip">download the latest version</a> for offline reading. If you found something wrong, please do <a href="https://www.iredmail.org/contact.html">contact us</a> to fix it.</p>
</div>
<!-- Global site tag (gtag.js) - Google Analytics -->