码迷,mamicode.com
首页 > Web开发 > 详细

apache,squid,shell脚本

时间:2016-12-16 01:57:28      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:music   网页   定向   

网页重写
把所有80端口的请求重定向由https来处理
[root@web conf.d]# vim music.conf
<Virtualhost *:80>
        ServerName music.westos.com
        RewriteEngine on
        RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
<Directory "/var/www/virtual/music/html">
        Require all granted
</Directory>
<Virtualhost *:443>
        ServerName music.westos.com
        DocumentRoot /var/www/virtual/music/html
        Customlog logs/news-443.log     combined
        SSLEngine on
        SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
        SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</Virtualhost>
测试成功,浏览器输入http://music.westos.com 自动跳转https://music.westos.com
技术分享

apache支持的语言测试,可安装http-manual参考测试方法,可下载中文版手册
php语言测试
[root@web conf.d]# yum install php -y
[root@web conf.d]# cd /var/www/html/
[root@web html]# ls
file1.html  index.html
[root@web html]# rm -fr file1.html
[root@web html]# vim index.php
 <?php
phpinfo ();
?>
[root@web html]# systemctl restart httpd.service
输入www.westos.com进行测试
技术分享

cgi脚本测试
[root@web html]# mkdir cgi
[root@web html]# ls
cgi  index.php
[root@web html]# cd cgi/ ##编辑如下
[root@web cgi]# vim index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
[root@web cgi]# perl index.cgi             ###测试脚本是否成功
[root@web cgi]# chmod +x index.cgi
[root@web conf.d]# vim default.conf  #编辑如下
<Virtualhost _default_:80>
        DocumentRoot /var/www/html
        Customlog logs/default.log      combined
</Virtualhost>
<Directory "/var/www/html/cgi">
        Options +ExecCGI
        AddHandler cgi-script .cgi
</Directory>
浏览器输入172.25.254.16/cgi/inde 测试
显示时间,刷新网页时间随之刷新
技术分享

##搭建论坛
[root@web conf.d]# systemctl start mariadb         ###启动数据库服务,并查看状态
[root@web conf.d]# systemctl status mariadb.service
[root@web conf.d]# netstat -antlpe | grep mysql   ###查看数据库开放端口,27端口已关闭无需设定,若端口打开状态 。vim /etc/my.cnf 添加skip-networking=1
(也可用软件XAMPP(Apache+MySQL+PHP+PERL)代替以上环境,进行论坛的下一步搭建
在网络上下载discuz
(Crossday Discuz! Board 简称 Discuz!是一套通用的社区论坛软件系统,用户可以在不需要任何编程的基础上,通过简单的设置和安装,在互联网上搭建起具备完善功能、很强负载能力和可高度定制的论坛服务
[root@web discuz3.2]# cp -p upload discuz-3.2 -r
[root@web discuz3.2]# ls
discuz-3.2  Discuz_X3.2_SC_GBK.zip  readme  upload  utility
[root@web discuz3.2]# mv discuz-3.2 /var/www/html/
浏览器输入http://172.25.254.16/discuz-3.2/install/进行安装
结果如下,出现乱码
技术分享

可能是下载版本不对。此版本为简体中文GBK,改换简体中文UTF8重复以上步骤尝试
问题解决
技术分享

提示不可写,给discuz目录及其子文件下放权限
技术分享

[root@web html]# chmod 777 discuz-3.2
[root@web html]# chmod 777 discuz-3.2 -R
安装成功,结果如下
技术分享

#############squid代理服务器
[root@foundation37 ~]# yum install squid -y
[root@foundation37 ~]# vim /etc/squid/squid.conf
 56 http_access allow all
 62 cache_dir ufs /var/spool/squid 100 16 256
[root@foundation37 ~]# cd /var/spool/
[root@foundation37 spool]# ls
abrt-upload  at    cups  mail      postfix  squid
anacron      cron  lpd   plymouth  rhsm     up2date
[root@foundation37 spool]# cd squid/
[root@foundation37 squid]# ls
[root@foundation37 squid]# systemctl start squid
[root@foundation37 squid]# ls              ###启动squid服务后自动生成目录
00  01  02  03  04  05  06  07  08  09  0A  0B  0C  0D  0E  0F  swap.state
[root@foundation37 squid]# netstat -antlpe | grep squid
tcp6       0      0 :::3128                 :::*                    LISTEN      0          74443      8240/(squid-1)      
[root@web ~]# firefox &        ###打开浏览器,设置代理服务器ip
 (Edit--Preferences--Advanced--Network--Settings..Manual proxy configuration
  输入squid服务器ip,及开放端口3128 。如下

技术分享

技术分享



用虚拟机连接网络成功
[root@web ~]# ping www.baidu.com
ping: unknown host www.baidu.com
 (ping不通,但是可以连接网络
###反向代理
[root@web ~]# yum remove httpd -y
[root@web ~]# rpm -ql httpd
package httpd is not installed
[root@web ~]# yum install squid -y
[root@parent ~]# cat /var/www/html/index.html
This page shows 172.25.254.116‘s information
[root@parent ~]# systemctl restart httpd.service   ##创建父级服务器环境
[root@web ~]# vim /etc/squid/squid.conf   ##配置反向代理服务器ip
 56 http_access allow all
 57
 58 # Squid normally listens to port 3128
 59 http_port 80 vhost vport
 60 cache_peer 172.25.254.116  parent 80 0 no-query
 61 # Uncomment and adjust the following to add a disk cache directory.
 62 cache_dir ufs /var/spool/squid 100 16 256
[root@web Desktop]# systemctl restart squid.service
在foundation37主机(第客户端主机)中输入使用反向代理服务的主机ip,获得父级服务器共享内容

技术分享

##轮询
[root@web Desktop]# vim /etc/squid/squid.conf   ##
 60 cache_peer 172.25.254.116  parent 80 0 no-query originserver round-robin name=web1
 在下行编辑,加入另一父级服务器ip及名称即可
每次刷新,跳转不同的ip,以减缓服务器压力
########shell脚本
[root@shell ~]# a=date
[root@shell ~]# echo a
a
[root@shell ~]# echo $a
date
[root@shell ~]# a=`date`
[root@shell ~]# echo $a
Wed Dec 14 22:47:41 EST 2016
[root@shell ~]# b=2
[root@shell ~]# echo $bc

[root@shell ~]# echo ${b}c
2c
[root@shell ~]# c=3
[root@shell ~]# echo ${bc}

[root@shell ~]# echo ${b,c}
2
[root@shell ~]# echo ${b}${c}
23
[root@shell ~]# bc=5
[root@shell ~]# echo ${bc}
5
[root@shell ~]# echo ‘‘‘‘

[root@shell ~]# echo "‘‘"
‘‘
[root@shell ~]# i=1
[root@shell ~]# echo $[i++]
1
[root@shell ~]# echo $[i++]
2
[root@shell ~]# echo $[i++]
3
[root@shell ~]# echo $[1+2]
3
[root@shell ~]# echo $[1%2]
1
[root@shell ~]# echo $[1*2]
2
[root@shell ~]# echo $[3/2]
1
[root@shell ~]# let a=3+3
[root@shell ~]# echo $a
6
[root@shell ~]# ((a=7+2))
[root@shell ~]# echo $a
9
[root@shell ~]# for X in 1 2 3;do echo x=$X;done
x=1
x=2
x=3
[root@shell ~]# for ((i=1;i<5;i++)); do echo $i; done
1
2
3
4
[root@shell ~]# for ((i=5;i>0;i--)); do echo $i; done
5
4
3
2
1
[root@shell ~]# for ((i=1;i<10;i++)); do ((k+=i)); echo $k; done
1
3
6
10
15
21
28
36
45
[root@shell ~]# [ "1" = "1" ]
[root@shell ~]# echo $?
0                                  ###0为肯定,1为否定
[root@shell ~]# [ "1" = "2" ]
[root@shell ~]# echo $?
1
[root@shell ~]# while [ "1" = "1" ]; do echo yes; break; done
yes
#ping脚本
[root@shell shell]# for a in {1..5}; do ping -c1 -w1 172.25.254.$a &> /dev/null && echo 172.25.254.$a is up || echo 172.25.254.$a is down; done
172.25.254.1 is down
172.25.254.2 is down
172.25.254.3 is down
172.25.254.4 is down
172.25.254.5 is down
[root@shell shell]# read -p "Please input the ip address which you want to check: " IP; ping -c1 -w1 $IP &> /dev/null && echo $IP is up || echo $IP is down
Please input the ip address which you want to check: 172.25.254.16
172.25.254.16 is up
[root@shell shell]# test "$a" = "$b" && echo yes || echo no
yes
[root@shell shell]# test "1" = "2" && echo yes || echo no
no
[root@shell shell]# b=0
[root@shell shell]# [ -z "$b" ] && echo yes || echo no
no
[root@shell shell]# echo $c

[root@shell shell]# [ -z "$c" ] && echo yes || echo no
yes
[root@shell shell]# vim filestyle.sh
#!/bin/bash
if
[ -e "$1" ]
then
[ -f "$1" -a ! -L "$1" ] && echo $1 is a file
[ -b "$1" ] && echo $1 is a block
[ -c "$1" ] && echo $1 is a c block
else
[ -n "$1" ] && echo $1 is not exist || echo "Please input the filename to check: "
fi
[root@shell shell]# chmod +x filestyle.sh
[root@shell shell]# sh filestyle.sh /mnt/lkjl
/mnt/lkjl is not exist
[root@shell useradd]# vim userfile                ##根据文件自动创建用户
[root@shell useradd]# vim passfile
[root@shell useradd]# cat userfile
westos1
westos2
westos3
[root@shell useradd]# cat userfile
westos1
westos2
westos3
[root@shell useradd]# vim useradd.sh
[root@shell useradd]# chmod +x useradd.sh
[root@shell useradd]# sh useradd.sh
ERROR: Please input userfile and password file after command !!
#!/bin/bash
if
[ -n "$1" -a -n "$2" ]
then
        if
        [ -e "$1" -a -e "$2" ]
        then
        MAXUSER=`wc -l $1 | cut -d ‘ ‘-f 1`
        MAXPASS=`wc -l $2 | cut -d ‘ ‘-f 1`
                [ "$MAXUSER" -eq "$MAXPASS" ]&&(
                for NUM in $( seq 1 $MAXUSER )
                do
                USERNAME=`sed -n ${NUM}p $1`
                PASSWORD=`sed -n ${NUM}p $2`
                CKUSER=`getent passwd $USERNAME`
                [ -z "$CKUSER" ]&&(
                useradd $USERNAME
                echo $PASSWORD |passwd --stdin $USERNAME
                )||echo "$USERNAME exist !!"
                done
                )||(
                echo $1 and $2 have different lines
                )
        elif
        [ ! -e "$1" ]
        then
        echo "ERROR:$1 is not exsit"
        else
        echo "ERROR:$2 is not exsit"
        fi
else
echo "ERROR: Please input userfile and password file after command !!"
fi
[root@shell useradd]# vim case.sh                ##case语句
#!/bin/bash
[ "$1" = "$2" ]
case $? in
        0)
        echo $1=$2
        ;;
        1)
        echo $1!=$2
        ;;
        *)
        echo what?
esac
[root@shell useradd]# sh case.sh 1 1
1=1
[root@shell useradd]# sh case.sh 1 2
1!=2
[root@shell /]# yum install expect -y              ####expect自动应答
[root@shell shell]# vim ask.sh
#!/bin/bash
read -p "what‘s your name: " NAME
read -p "How old are you: "  AGE
read -p "What is your class: " CLASS
echo $NAME is $AGE\‘s old,in $CLASS class.
[root@shell shell]# sh ask.sh
what‘s your name: liu
How old are you: 20
What is your class: 19
liu is 20‘s old,in 19 class.
[root@shell shell]# vim expect.exp
spawn /root/Desktop/shell/ask.sh
        expect "name:"
        send "liu\r"
        expect "old"
        send "17\r"
        expect "class"
        send "8\r"
expect eof

[root@shell shell]# /root/Desktop/shell/expect.exp
spawn /root/Desktop/shell/ask.sh
what‘s your name: liu
How old are you: 17
What is your class: 8
[root@shell shell]# vim pingcheck.sh
#!/bin/bash
for NUM in {15..20}
do
ping -c1 -w1 172.25.254.$NUM &> /dev/null && (
        /mnt/ssh.exp 172.25.254.$NUM redhat hostname | grep -E "The|ECDSA|connecting|Warning|password|spawn" -v|sed "s/Permission\ denied\,\ please\ try\ again\./172.25.254.$NUM password is error/g"
)
done
[root@shell mnt]# vim ssh.exp
#!/usr/bin/expect
set timeout 3
set IP [lindex $argv 0]
set PASS [lindex $argv 1]
set COMM [lindex $argv 2]
spawn ssh root@$IP $COMM
expect {
        "yes/no"
        {send "yes/r";exp_continue}
        "password:"
        {send "$PASS\r"}
        }
expect eof
[root@shell shell]# chmod 777 pingcheck.sh
[root@shell shell]# chmod 777 /mnt/ssh.exp
[root@shell mnt]# ping 172.25.254.16








apache,squid,shell脚本

标签:music   网页   定向   

原文地址:http://12107647.blog.51cto.com/12097647/1883165

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!