进一步自动化Ubuntu-Nginx-WordPress服务器环境建立脚本?

进一步自动化Ubuntu-Nginx-WordPress服务器环境建立脚本?

使用以下脚本,我创建了一个基于 Ubuntu-Nginx-WordPress 的环境。我如何进一步自动化(从而缩短)该脚本中的代码量?

add-apt-repository ppa:certbot/certbot -y && apt-get update -y && apt-get upgrade -y
ufw enable && ufw allow 22/tcp 25/tcp 80/tcp 443/tcp 9000/tcp
apt-get install zip unzip tree unattended-upgrades sshguard postfix nginx python-certbot-nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
sed -i "s/# gzip_/gzip_/g" /etc/nginx/nginx.conf
sed -i "s/max_size = .M/max_size = 200M/g" /etc/php/*/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php/*/fpm/php.ini
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && mv wp-cli.phar /usr/local/bin/wp

笔记

  • 我愿意使用 Tasksel。
  • 我不想使用 Ansible 或 Salt,因为对于我想要实现的目标来说,这两者对我来说似乎太过复杂。

答案1

您可以curl直接写信给/usr/local/bin/wp

curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > /usr/local/bin/wp && chmod +x /usr/local/bin/wp

add-apt-repository在 17.04 及更新版本中有一个-u选项,允许您跳过显式的apt-get update

-u, --update After adding the repository, update the package cache with
             packages from this repository (avoids need to apt-get update)

您还可以结合apt-get upgradeinstall步骤:

apt-get upgrade zip unzip tree unattended-upgrades sshguard postfix nginx python-certbot-nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y

合并:

add-apt-repository ppa:certbot/certbot -yu
ufw enable && ufw allow 22/tcp 25/tcp 80/tcp 443/tcp 9000/tcp
apt-get upgrade zip unzip tree unattended-upgrades sshguard postfix nginx python-certbot-nginx mysql-server php-fpm php-mysql php-mbstring php-mcrypt -y
sed -i 's/# gzip_/gzip_/g' /etc/nginx/nginx.conf
sed -i 's/max_size = .M/max_size = 200M/g' /etc/php/*/fpm/php.ini
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/*/fpm/php.ini
curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar > /usr/local/bin/wp && chmod +x /usr/local/bin/wp

相关内容