代理主机的配置
systemctl stop mariadb-server mariadb
yum remove mariadb-server mariadb
rm -fr /var/log/mariadb
systemctl stop nginx
yum remove nginx
yum remove nginx-release-centos-7-0.el7.ngx.noarch
rm -fr /etc/nginx
systemctl stop httpd
yum remove httpd
rm -fr /etc/httpd/
systemctl stop keepalived
yum remove keepalived
rm -fr /etc/keepalived
t8.sh
#!/bin/bash
#function:install mariadb-server、mariadb、php、nginx、keepalived
echo -e "\033[32m 正在启动数据库的安装.....\033[0m"
source ./t13.sh
echo "mariadb安装成功!"
sleep 5
echo -e "\033[32m 正在启动php的安装和配置....\033[0m"
source ./t12.sh
echo "php安装成功!"
sleep 5
echo -e "\033[32m 正在启动安装nginx.......\033[0m"
source ./t9.sh
echo -e "\033[32m nginx安装成功!\033[0m"
sleep 5
echo -e "\033[32m 代理主机正在安装keepalived....请稍后\033[0m"
source ./t10.sh
echo -e "\033[32m keepalived安装成功!\033[0m"
sleep 5
if [[ $? -eq 0 ]];then
echo -e "\033[32m 子机安装成功!\033[0m"
fi
echo -e "\033[32m 退出安装,谢谢!\033[0m"
t9.sh
#!/bin/bash
#echo -e "\033[32m 正在禁止firewall开机启动...\033[0m"
#`systemctl disable firewalld.service`
#echo -e "\033[32m firewall已禁止\033[0m"
#echo -e "\033[32m 正在打开selinux配置文件...\033[0m"
#`sudo vim /etc/selinux/config`
#改SELINUX=disable
#SELINUXTYPE=targeted #注释
NGINXRPM=nginx-release-centos-7-0.el7.ngx.noarch.rpm
NGINXDIR=/opt/nginx-release-centos-7-0.el7.ngx.noarch.rpm
NGINXDIR=/etc/nginx/conf.d/default.conf
MYNGINXDIR=/etc/nginx/conf.d/tomcats.conf
MYCONF=tomcats.conf
CONTENT=index index.html index.htm
DIR=/etc/nginx/conf.d/tomcats.conf
echo -e "\033[32m 开始安装nginx...\033[0m"
echo -e "\033[32m 正在下载...\033[0m"
wget http://nginx.org/packages/centos/7/noarch/RPMS/$NGINXRPM
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在解压...\033[0m"
rpm -ivh $NGINXRPM
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在yum源下载...\033[0m"
yum -y install nginx
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 安装成功!正在重启...\033[0m"
systemctl restart nginx
echo -e "\033[32m 清除残余文件...\033[0m"
rm -fr $NGINXRPM
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 显示nginx状态...\033[0m"
systemctl status nginx
fi
echo -e "\033[32m 启动修改nginx的配置...\033[0m"
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在添加tomcats.conf文件...\033[0m"
touch $DIR
fi
if [[ $? -eq 0 ]];then
echo "
upstream javaservers {
ip_hash;
server 39.106.50.206:8080;
}" > $DIR
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在添加php代理设置....请稍后...\033[0m"
echo "server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass http://javaservers/;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
proxy_pass http://192.168.235.131:81;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
" > $NGINXDIR
echo -e "\033[32m 配置成功!\033[0m"
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在重新加载nginx...\033[0m"
systemctl restart nginx
echo -e "\033[32m 正在修改临时权限...\033[0m"
setenforce 0
echo -e "\033[32m nginx全部配置完毕,请到浏览器访问...\033[0m"
fi
t10.sh
#!/bin/bash
#function:安装并修改keepalived主机
KEEPDIR=/etc/keepalived/keepalived.conf
if [[ $? -eq 0 ]];then
echo -e "\033[32m 开始下载keepalived...."
yum -y install keepalived
echo -e "\033[32m keepalived下载成功...、033[0m"
fi
#修改配置
if [[ $? -eq 0 ]];then
sleep 5
echo -e "\033[32m 正在修改代理主机keepalived的配置....\033[0m"
> KEEPDIR
echo -e "\033[32m 添加.....\033[0m"
echo "! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eno16777736
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.235.150
}
}" > $KEEPDIR
sleep 5
echo -e "\033[32m 修改成功!请稍后...\033[0m"
echo -e "\033[32m 重新加载keepalived....请稍后....\033[0m"
systemctl restart keepalived
systemctl restart nginx
setenforce 0
echo -e "\033[32m 安装成功,谢谢!\033[0m"
fi
t11.sh
#!/bin/bash
#function:keepalived从机配置
KEEPDIR=/etc/keepalived/keepalived.conf
if [[ $? -eq 0 ]];then
echo -e "\033[32m 开始下载keepalived...."
yum -y install keepalived
echo -e "\033[32m keepalived下载成功...、033[0m"
fi
#修改配置
if [[ $? -eq 0 ]];then
sleep 5
echo -e "\033[32m 正在修改代理主机keepalived的配置....\033[0m"
> KEEPDIR
echo -e "\033[32m 添加.....\033[0m"
echo "! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL1
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777736
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.235.150
}
}" > $KEEPDIR
sleep 5
echo -e "\033[32m 修改成功!请稍后...\033[0m"
echo -e "\033[32m 重新加载keepalived....请稍后....\033[0m"
systemctl restart keepalived
systemctl restart nginx
setenforce 0
echo -e "\033[32m 安装成功,谢谢!\033[0m"
fi
t12.sh
#!/bin/bash
#function:安装配置php
echo "这是shell脚本自动化安装php环境"
DIR=/etctpd
if [ ! -d $DIR ];then
echo "开始安装Apache"
yum -y install httpd
echo "安装Apache完毕,正在启动Apache..."
systemctl restart httpd
echo "启动完毕!正在设置开机启动..."
systemctl enable httpd
echo "设置完毕!"
echo "正在建立测试页"
touch /var/www/html/homework.php
echo "" > /var/www/html/homework.php
echo "建立测试页成功!"
echo "开始安装PHP"
yum -y install php
echo "安装完毕!为避免与nginx产生冲突正在修改httpd端口...."
sed -i 's/Listen 80/Listen 81/g' /etc/httpd/conf/httpd.conf
echo "正在重新加载hpptd..."
systemctl restart httpd
echo "请前往浏览器测试php安装:"
echo "(提示:在浏览器中输入:192.168.xxx.xxx/homework.php )"
else
echo "目标已存在"
fi
t13.sh
#!/bin/bash
#function: 安装MariaDB
echo -e "\033[32m 这是shell脚本自动化安装MariaDB\033[0m"
DIR=/mydata/data
if [[ ! -d $DIR ]];then
echo "开始安装MariaDB"
yum -y install mariadb-server mariadb
echo "安装MariaDB完毕,正在启动MariaDB..."
systemctl restart mariadb
echo "启动完毕!正在设置开机启动..."
systemctl enable mariadb
echo "对mariaDB进行简单配置"
mysql_secure_installation
echo "设置完毕!"
else
echo "目标已存在!"
fi
另一台代理子机的安装
t8.sh
#!/bin/bash
#function:install mariadb-server、mariadb、php、nginx、keepalived
echo -e "\033[32m 正在启动安装nginx.......\033[0m"
source ./t9.sh
sleep 5
echo -e "\033[32m nginx安装成功!\033[0m"
echo -e "\033[32m 代理子机正在安装keepalived....请稍后\033[0m"
source ./t11.sh
echo -e "\033[32m keepalived安装成功!\033[0m"
sleep 5
if [[ $? -eq 0 ]];then
echo -e "\033[32m 子机安装成功!\033[0m"
fi
t9.sh
#!/bin/bash
#echo -e "\033[32m 正在禁止firewall开机启动...\033[0m"
#`systemctl disable firewalld.service`
#echo -e "\033[32m firewall已禁止\033[0m"
#echo -e "\033[32m 正在打开selinux配置文件...\033[0m"
#`sudo vim /etc/selinux/config`
#改SELINUX=disable
#SELINUXTYPE=targeted #注释
NGINXRPM=nginx-release-centos-7-0.el7.ngx.noarch.rpm
NGINXDIR=/opt/nginx-release-centos-7-0.el7.ngx.noarch.rpm
NGINXDIR=/etc/nginx/conf.d/default.conf
MYNGINXDIR=/etc/nginx/conf.d/tomcats.conf
MYCONF=tomcats.conf
CONTENT=index index.html index.htm
DIR=/etc/nginx/conf.d/tomcats.conf
echo -e "\033[32m 开始安装nginx...\033[0m"
echo -e "\033[32m 正在下载...\033[0m"
wget http://nginx.org/packages/centos/7/noarch/RPMS/$NGINXRPM
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在解压...\033[0m"
rpm -ivh $NGINXRPM
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在yum源下载...\033[0m"
yum -y install nginx
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 安装成功!正在重启...\033[0m"
systemctl restart nginx
echo -e "\033[32m 清除残余文件...\033[0m"
rm -fr $NGINXRPM
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 显示nginx状态...\033[0m"
systemctl status nginx
fi
echo -e "\033[32m 启动修改nginx的配置...\033[0m"
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在添加tomcats.conf文件...\033[0m"
touch $DIR
fi
if [[ $? -eq 0 ]];then
echo "
upstream javaservers {
ip_hash;
server 39.106.50.206:8080;
}" > $DIR
fi
if [[ $? -eq 0 ]];then
echo "server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass http://javaservers/;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
proxy_pass http://192.168.235.131:81;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
" > $NGINXDIR
echo -e "\033[32m 配置成功!\033[0m"
fi
if [[ $? -eq 0 ]];then
echo -e "\033[32m 正在重新加载nginx...\033[0m"
systemctl restart nginx
echo -e "\033[32m 正在修改临时权限...\033[0m"
setenforce 0
echo -e "\033[32m nginx全部配置完毕,请到浏览器访问...\033[0m"
fi
t11.sh
#!/bin/bash
#function:keepalived从机配置
KEEPDIR=/etc/keepalived/keepalived.conf
if [[ $? -eq 0 ]];then
echo -e "\033[32m 开始下载keepalived...."
yum -y install keepalived
echo -e "\033[32m keepalived下载成功...、033[0m"
fi
#修改配置
if [[ $? -eq 0 ]];then
sleep 5
echo -e "\033[32m 正在修改代理主机keepalived的配置....\033[0m"
> KEEPDIR
echo -e "\033[32m 添加.....\033[0m"
echo "! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL1
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777736
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.235.150
}
}" > $KEEPDIR
sleep 5
echo -e "\033[32m 修改成功!请稍后...\033[0m"
echo -e "\033[32m 重新加载keepalived....请稍后....\033[0m"
systemctl restart keepalived
systemctl restart nginx
setenforce 0
echo -e "\033[32m 安装成功,谢谢!\033[0m"
fi