SHELL用法二(练习)

1、SHELL编程作业&剖析演练
1)SHELL编程Nginx虚拟主机脚本;
 安装Nginx WEB平台;
 配置虚拟主机(1个网站);
 重启&加载配置文件;
 配置hosts,虚拟主机访问测试;
v1.jfedu.net
v2.jfedu.net
#!/bin/bash
#2019年7月3日20:36:31
#auto config nginx vhosts.
#by author www.jfedu.net
########################
NGX_VER="$1"
NGX_VHOST="$2"
NGX_YUM="yum install -y"NGX_SRC="nginx-$NGX_VER"
NGX_DIR="/usr/local/nginx"
NGX_SOFT="nginx-${NGX_VER}.tar.gz"
NGX_ARGS="--user=www --group=www"
NGX_URL="http://nginx.org/download"
#Install Nginx WEB
$NGX_YUM wget make tar gzip
$NGX_YUM gcc pcre-devel zlib-devel
wget -c $NGX_URL/$NGX_SOFT
tar xzf $NGX_SOFT
cd $NGX_SRC
useradd -s /sbin/nologin www -M
./configure --prefix=$NGX_DIR $NGX_ARGS
make
make install
$NGX_DIR/sbin/nginx
ps -ef|grep nginx
netstat -tnlp|grep -w 80
setenforce 0
systemctl stop firewalld.service
#Config Nginx Virtual Hosts.
echo "worker_processes 1;
events {
worker_connections 1024;
}
http {
include
mime.types;
default_type application/octet-stream;
sendfile
on;
keepalive_timeout 65;
include domains/*;
}
">$NGX_DIR/conf/nginx.conf
mkdir -p $NGX_DIR/conf/domains/
cd $NGX_DIR/conf/domains/
echo "
server {
listen
80;
server_name ${NGX_VHOST};
access_log logs/${NGX_VHOST}.access.log;
location / {
root
html/${NGX_VHOST};
index index.html index.htm;}
}
">${NGX_VHOST}
mkdir -p $NGX_DIR/html/${NGX_VHOST}
cd $NGX_DIR/html/${NGX_VHOST}/
echo "
<html>
<h1>Hostname:$HOSTNAME $NGX_VHOST Test Pages.</h1>
<hr color=red>
</html>
">index.html
$NGX_DIR/sbin/nginx -s reload
2)SHELL编程LNMP一键部署脚本;(Nginx1.16+MYSQL5.6+PHP5.6)
 安装Nginx WEB服务;
 安装MYSQL数据库服务;
 安装PHP FPM模块服务;
 配置Nginx Server主机&整合PHP-FPM(9000);
 创建phpinfo测试页面,通过浏览器访问;
#!/bin/bash
#2019年7月3日18:24:43
#auto install lnmp web.
#by author www.jfedu.net
######################
#Install Nginx WEB.
wget -c http://nginx.org/download/nginx-1.16.0.tar.gz
tar zxf nginx-1.16.0.tar.gz
cd nginx-1.16.0
yum install -y pcre-devel gcc make
useradd -s /sbin/nologin www -M
./configure --user=www --group=www --prefix=/usr/local/nginx
make && make install
/usr/local/nginx/sbin/nginx
setenforce 0
systemctl stop firewalld.service#Install MYSQL Database.
cd ../
yum install cmake ncurses-devel ncurses -y
wget -c
http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43.tar.
gz
tar -xzf mysql-5.6.43.tar.gz
cd mysql-5.6.43
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql56/ 
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock 
-DMYSQL_DATADIR=/data/mysql 
-DSYSCONFDIR=/etc 
-DMYSQL_USER=mysql 
-DMYSQL_TCP_PORT=3306 
-DWITH_XTRADB_STORAGE_ENGINE=1 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_PARTITION_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DWITH_MYISAM_STORAGE_ENGINE=1 
-DWITH_READLINE=1 
-DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=1 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DEXTRA_CHARSETS=all 
-DWITH_BIG_TABLES=1 
-DWITH_DEBUG=0
make
make install
#Config MYSQL Set System Service
cd /usr/local/mysql56/
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 35 mysqld on
mkdir -p /data/mysql
useradd mysql
/usr/local/mysql56/scripts/mysql_install_db --user=mysql
--datadir=/data/mysql/ --basedir=/usr/local/mysql56/
ln -s /usr/local/mysql56/bin/* /usr/bin/
service mysqld restart
#Install PHP WEB 2018cd ../../
yum install libxml2 libxml2-devel -y
wget http://mirrors.sohu.com/php/php-5.6.28.tar.bz2
tar jxf php-5.6.28.tar.bz2
cd php-5.6.28
./configure --prefix=/usr/local/php5
--with-config-file-path=/usr/local/php5/etc
--with-mysql=/usr/local/mysql56/ --enable-fpm
make
make install
#Config LNMP WEB and Start Server.
cp php.ini-development
/usr/local/php5/etc/php.ini
cp /usr/local/php5/etc/php-fpm.conf.default
/usr/local/php5/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod o+x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
echo "
worker_processes 1;
events {
worker_connections 1024;}
http {
include
mime.types;
default_type application/octet-stream;
sendfile
on;
keepalive_timeout 65;
server {
listen
80;
server_name localhost;
location / {
root
html;
fastcgi_pass
127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include
fastcgi_params;
}
}
}" >/usr/local/nginx/conf/nginx.conf
echo "
<?phpphpinfo();
?>">/usr/local/nginx/html/index.php
/usr/local/nginx/sbin/nginx -s reload
原文地址:https://www.cnblogs.com/nshgo/p/12157032.html