您的位置:首页 > 运维架构 > Linux

一键解决Linux安装ArcGIS Server系统环境准备问题

2011-12-22 17:19 651 查看
英文版

#!/bin/sh
#Scripts to check the prerequisites to install ArcGIS Server. author:Qintong

# Make sure this is being run as root.
tmp_account=`id | cut -f2 -d\( | cut -f1 -d\)`
if [ "$tmp_account" != "root" ]
then
echo " "
echo "*** ERROR: This script must be run as root."
echo " "
exit 1
fi

#Start to check the hostname
hostname=`cat /etc/sysconfig/network|grep HOSTNAME|cut -d = -f2|sed 's/ //g'`
if [ $hostname == "localhost.localdomain" ]
then echo -e "The host name of this machine is localhost, which is not capable of ArcGIS Server. Please enter a new name:\n"
read newHostName
hostname $newHostName
sed -i 's/HOSTNAME=localhost.localdomain/HOSTNAME='$newHostName'/g' /etc/sysconfig/network
fi

#Check the network
ethNum=0
ethAddrs=""
ethAddrs=`ls /etc/sysconfig/network-scripts|grep ifcfg-eth|cut -c 7-`
ethNum=`ls /etc/sysconfig/network-scripts|grep ifcfg-eth|wc -l`
if [ $ethNum == 1 ]
then
ipAddr=`cat /etc/sysconfig/network-scripts/ifcfg-eth* |grep IPADDR |cut -d = -f2`
if [[ $ipAddr == "" ]]
then
echo "IP ADDRESS IS NOT PROPERLY SET. You must assign a static IP to a ethernet card!"
exit 1
else
echo -e "Please enter the domain name of this machine, eg. "$hostname".localdomain, to skip this enter 'skip'"
read domainName
[[ $domainName == "skip" ]] && break
domainFlag=`$domainName | cut -d . -f2`
[[ $domainFlag != "" ]] && sed -i -e 's/^127.0.0.1/#127.0.0.1/g' -e '$a\\'$ipAddr''$domainName' '$newHostName'' /etc/hosts || ([ $domainName != "skip" ] && echo "Wrong input, check the format")
fi
fi
[[ $ethNum == 0 ]] && echo "No ethernet card." && exit 1
[[ $ethNum > 1 ]] && echo -e "You have multiple ethernet cards:\n" && echo $ethAddrs

#Start to check the rpm dependency
packsRequired="compat-libf2c-34 compat-libstdc++-33 compat-libstdc++-296 compat-openldap libXp openldap openssl gmp openmotif22 xorg-x11-fonts-base chkfontpath libFS libXfont libXmu libfontenc ttmkfdir xorg-x11-font-utils xorg-x11-xfs libidn"

packs32Required="compat-libf2c-34 compat-libstdc++-33 compat-libstdc++-296 compat-openldap libXp openldap openssl openmotif22"

packsAbsent=`rpm -q $packsRequired | grep "not installed" | cut -f2 -d\ |cut -f1 -d\ `

[ -n "$packsAbsent" ] && echo -e "The following rpms are completely absent on this system:\n" && echo "$packsAbsent"

#Go ahead to check to 32bit availability
for var in $packs32Required
do
i386flag=`rpm -ql $var | grep /lib/`
[ -z "$i386flag" ] && echo -e "The i386 edition of $var is not available on this system, please install them manually from the operating system disc.\n" || echo -e "Fine! No problem with rpm dependency of $var.\n"
done

#Check the status of Firewall and SELinux
firewallFlag=`service iptables status | grep stopped`
SELinuxFlag=`getenforce`

if [ "$firewallFlag" != "" ]
then echo -e "Fine! $firewallFlag\n"
else
echo -e "The firewall is yet to be shuted down and disabled. Would you like to perform this? (y or Y)\n"
read
if [ "$REPLY" != "y" ] && [ "$REPLY" != "Y" ] && [ "$REPLY" != "" ]
then
exit 1
else
service iptables stop
chkconfig iptables off
fi
fi

if [ "$SELinuxFlag"=="Disabled" ]
then echo -e "Fine! The SELinux is disabled.\n"
else
echo -e "The SELinux policy is started and should be disabled. Would you like to squash it? (y or Y)\n"
read
if [ "$REPLY" != "y" ] && [ "$REPLY" != "Y" ] && [ "$REPLY" != "" ]
then
exit 1
else
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
fi

#Check the users
userNum=0
users=""
userNum=`cat /etc/passwd | awk -F: '$3>=500 && $3<1000' | cut -f 1 -d :|wc -l`
users=`cat /etc/passwd | awk -F: '$3>=500 && $3<1000' | cut -f 1 -d :`
echo -e "There are $userNum defined users in current system: \n$users\n\nIt is strongly recommended to add an OS user(REQUIRED for distributed deployment and caching) manually to manange ArcGIS Server. Would you like to add it now? (y or Y)"
read
if [ "$REPLY" != "y" ] && [ "$REPLY" != "Y" ] && [ "$REPLY" != "" ]
then
exit 1
else
password1=1
password2=2
echo "Please input the user name: "
read username
until [[ $password1 == $password2 ]]
do
echo "Please input the password: "
stty -echo
read password1
stty echo
echo "Please retype your password: "
stty -echo
read password2
stty echo
if [[ $password1 != $password2 ]]
then
echo "Passwords not match!"
continue
else break
fi
done
useradd $username -p $password1
fi

echo "Congratulations! You are ready to setup ArcGIS Server now."


中文版

#!/bin/sh
#ArcGIS Server的安装先决条件检查和设置. 作者:秦桐

# 确定以root身份登录
tmp_account=`id | cut -f2 -d\( | cut -f1 -d\)`
if [ "$tmp_account" != "root" ]
then
echo " "
echo "错误: 必须以root身份运行该脚本"
echo " "
exit 1
fi

#开始检测主机名,如果是localhost要求替换
hostname=`cat /etc/sysconfig/network|grep HOSTNAME|cut -d = -f2|sed 's/ //g'`
if [ $hostname == "localhost.localdomain" ]
then echo -e "主机名是localhost,请修改为其他名称:\n"
read newHostName
hostname $newHostName
sed -i 's/HOSTNAME=localhost.localdomain/HOSTNAME='$newHostName'/g' /etc/sysconfig/network
fi

#检测网络状况,检查当前系统中网卡数量,如果网卡正常,要求输入域名
ethNum=0
ethAddrs=""
ethAddrs=`ls /etc/sysconfig/network-scripts|grep ifcfg-eth|cut -c 7-`
ethNum=`ls /etc/sysconfig/network-scripts|grep ifcfg-eth|wc -l`
if [ $ethNum == 1 ]
then
ipAddr=`cat /etc/sysconfig/network-scripts/ifcfg-eth* |grep IPADDR |cut -d = -f2`
if [[ $ipAddr == "" ]]
then
echo "IP地址不存在,您必须为网卡指定一个静态IP"
exit 1
else
echo -e "请输入本机域名,例如 "$hostname".localdomain ,要跳过此步骤,请输入“skip”"
read domainName
domainFlag=`echo $domainName | cut -d . -f2`
[[ $domainFlag != "" ]] && sed -i -e 's/^127.0.0.1/#127.0.0.1/g' -e '$a\\'$ipAddr''$domainName' '$newHostName'' /etc/hosts || ([ $domainName != "skip" ] && echo "输入错误,注意格式!")
fi
fi
[[ $ethNum == 0 ]] && echo "没有网卡!" && exit 1
[[ $ethNum > 1 ]] && echo -e "您拥有多块网卡\n" && echo $ethAddrs

#开始检测包依赖性
packsRequired="compat-libf2c-34 compat-libstdc++-33 compat-libstdc++-296 compat-openldap libXp openldap openssl gmp openmotif22 xorg-x11-fonts-base chkfontpath libFS libXfont libXmu libfontenc ttmkfdir xorg-x11-font-utils xorg-x11-xfs libidn"

packs32Required="compat-libf2c-34 compat-libstdc++-33 compat-libstdc++-296 compat-openldap libXp openldap openssl openmotif22"

packsAbsent=`rpm -q $packsRequired | grep "not installed" | cut -f2 -d\ |cut -f1 -d\ `

[ -n "$packsAbsent" ] && echo -e "以下依赖包完全没有安装(64位和32位):\n" && echo "$packsAbsent"

#继续检查32位包可用性
for var in $packs32Required
do
i386flag=`rpm -ql $var | grep /lib/`
[ -z "$i386flag" ] && echo -e "i386版本的 $var 在当前系统上未安装,请手动从操作系统光盘中安装。\n" || echo -e "$var 已安装,没有问题。\n"
done

#检测防火墙和SELinux状况并辅助解决
firewallFlag=`service iptables status | grep 已停`
SELinuxFlag=`getenforce`

if [ "$firewallFlag" != "" ]
then echo -e "正常 $firewallFlag\n"
else
echo -e "防火墙没有被禁用和关闭,是否现在禁用? (y or Y)\n"
read
if [ "$REPLY" != "y" ] && [ "$REPLY" != "Y" ] && [ "$REPLY" != "" ]
then
exit 1
else
service iptables stop
chkconfig iptables off
fi
fi

if [ "$SELinuxFlag"=="Disabled" ]
then echo -e "正常。SELinux已禁用\n"
else
echo -e "SELinux未被禁用,是否现在禁用? (y or Y)\n"
read
if [ "$REPLY" != "y" ] && [ "$REPLY" != "Y" ] && [ "$REPLY" != "" ]
then
exit 1
else
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
fi

#检测ArcGIS Server安装所有者用户
userNum=0
users=""
userNum=`cat /etc/passwd | awk -F: '$3>=500 && $3<1000' | cut -f 1 -d :|wc -l`
users=`cat /etc/passwd | awk -F: '$3>=500 && $3<1000' | cut -f 1 -d :`
echo -e "当前系统中有 $userNum 已定义的用户: \n$users\n\n强烈建议创建操作系统级别的所有者用户(在分布式部署和创建缓存切片时是必须的),是否现在创建? (y or Y)"
read
if [ "$REPLY" != "y" ] && [ "$REPLY" != "Y" ] && [ "$REPLY" != "" ]
then
exit 1
else
password1=1
password2=2
echo "请输入用户名: "
read username
until [[ $password1 == $password2 ]]
do
echo "请输入密码 "
stty -echo
read password1
stty echo
echo "请再次输入密码 "
stty -echo
read password2
stty echo
if [[ $password1 != $password2 ]]
then
echo "密码不匹配,重新输入"
continue
else break
fi
done
useradd $username -p $password1
fi

echo "恭喜!满足安装条件,可以安装ArcGIS Server!"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐