#!/bin/bash
set -e
BASE_DIR=$(cd "$(dirname "$0")"; pwd); cd ${BASE_DIR}
SCRIPT_DIR=$BASE_DIR/scripts
RPM_DIR=$BASE_DIR/files
TMP_DIR=$BASE_DIR/tmp
SLEEP_SEC=10
######### Variable ##########
CURRENT_USER="$(id -un 2>/dev/null || true)"
BASH_C="bash -c"
######### Constant ##########
SUPPORT_DISTRO=(centos)
CENTOS_VER=(7.0 7.2)
# Error Message
ERR_ROOT_PRIVILEGE_REQUIRED=(10 "This install script need root privilege, please retry use 'sudo' or root user!")
ERR_NOT_SUPPORT_PLATFORM=(20 "Sorry, EPC only support x86_64 platform!")
ERR_NOT_SUPPORT_DISTRO=(21 "Sorry, EPC only support centos now!")
ERR_NOT_SUPPORT_DISTRO_VERSION=(22 "Sorry, EPC only support centos(>=7.0) now!")
ERR_FETCH_INST_PKG_FAILED=(60 "Fetch install package failed, please retry!")
ERR_UNTAR_PKG_FAILED=(62 "Untar install package failed!")
ERR_EXEC_INSTALL_FAILED=(70 "Install EPC failed!")
ERR_INSTALL_SERVICE_FAILED=(71 "Install service failed!")
ERR_UNKNOWN_MSG_TYPE=98
ERR_UNKNOWN=99
# Color Constant
RED=`tput setaf 1 || true`
GREEN=`tput setaf 2 || true`
YELLOW=`tput setaf 3 || true`
BLUE=`tput setaf 4 || true`
WHITE=`tput setaf 7 || true`
LIGHT=`tput bold || true`
RESET=`tput sgr0 || true`
######### Function Definition ##########
i_base() {
log info "Welcome to Install Baicells EPC...\n"
check_system
configure_system
install_common_deps
}
check_system() {
log info "1. check user"
check_user
log done "check user...done"
log info "2. check os platform"
check_os_platform
log done "check os platform...done"
#log info "3. check os distro"
#check_os_distro
#log done "check os distro...done"
}
check_user() {
if [[ "${CURRENT_USER}" != "root" ]];then
if (command_exist sudo);then
BASH_C="sudo -E bash -c"
else
log error "${ERR_ROOT_PRIVILEGE_REQUIRED[1]}" && exit ${ERR_ROOT_PRIVILEGE_REQUIRED[0]}
fi
log info "${WHITE}Hint: EPC installer need root privilege\n"
${BASH_C} "echo -n"
fi
}
check_os_platform() {
ARCH="$(uname -m)"
if [[ "${ARCH}" != "x86_64" ]];then
log error "${ERR_NOT_SUPPORT_PLATFORM[1]}" && exit ${ERR_NOT_SUPPORT_PLATFORM[0]}
fi
}
check_os_distro() {
#set -x
LSB_DISTRO=""; LSB_VER=""; LSB_CODE=""
if (command_exist lsb_release);then
LSB_DISTRO="$(lsb_release -si)"
LSB_VER="$(lsb_release -sr)"
LSB_CODE="$(lsb_release -sc)"
fi
if [[ -z "${LSB_DISTRO}" ]];then
if [[ -r /etc/lsb-release ]];then
LSB_DISTRO="$(. /etc/lsb-release && echo "${DISTRIB_ID}")"
LSB_VER="$(. /etc/lsb-release && echo "${DISTRIB_RELEASE}")"
LSB_CODE="$(. /etc/lsb-release && echo "${DISTRIB_CODENAME}")"
elif [[ -r /etc/fedora-release ]];then
LSB_DISTRO="fedora"
elif [[ -r /etc/debian_version ]];then
LSB_DISTRO="Debian"
LSB_VER="$(cat /etc/debian_version)"
elif [[ -r /etc/centos-release ]];then
LSB_DISTRO="CentOS"
LSB_VER="$(cat /etc/centos-release | cut -d' ' -f4)"
elif [[ -r /etc/os-release ]];then
LSB_DISTRO="$(. /etc/os-release && echo "$ID")"
LSB_VER="$(. /etc/os-release && echo "$VERSION_ID")"
fi
fi
LSB_DISTRO=$(echo "${LSB_DISTRO}" | tr '[:upper:]' '[:lower:]')
case "${LSB_DISTRO}" in
centos)
CVERSION=$( echo ${LSB_VER} | cut -d"." -f-2 )
if [[ "${LSB_DISTRO}" == "centos" ]]
then SUPPORT_VER_LIST="${CENTOS_VER[@]}";
else SUPPORT_VER_LIST="${FEDORA_VER[@]}";
fi
if (echo "${SUPPORT_VER_LIST}" | grep -qvw "${CVERSION}");then
log error "Baicells EPC support ${LSB_DISTRO}( ${SUPPORT_VER_LIST} ), but current is ${LSB_VER}"
exit ${ERR_NOT_SUPPORT_DISTRO_VERSION[0]}
fi
;;
*) if [[ ! -z ${LSB_DISTRO} ]];then echo -e -n "\nCurrent OS is '${LSB_DISTRO} ${LSB_VER}(${LSB_CODE})'";
else echo -e -n "\nCan not detect OS type"; fi
log error "${ERR_NOT_SUPPORT_DISTRO[1]}"
exit ${ERR_NOT_SUPPORT_DISTRO[0]}
;;
esac
}
configure_system() {
log info "4. configure system"
log info "disable NetworkManager"
# NetworkManager
systemctl stop NetworkManager && systemctl disable NetworkManager || true
log info "disable firewalld"
# firewall
systemctl stop firewalld && systemctl disable firewalld || true
log info "disable selinux"
# selinux
setenforce 0 || true
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
log info "enable ip forward"
# disable libvirtd
systemctl stop libvirtd 2>/dev/null && systemctl disable libvirtd 2>/dev/null || true
ip link delete virbr0-nic 2>/dev/null || true
ip link delete virbr0 2>/dev/null || true
# ip forward
echo 1 > /proc/sys/net/ipv4/ip_forward
log done "configure system...done"
}
yum_install() {
for pkg in $@; do
rpm -q $pkg > /dev/null || yum install -y -q $pkg || true
done
}
log_start() {
log info "install $1"
}
log_end() {
log done "install $1...done"
}
clean() {
rm -rf $TMP_DIR
}
start_service() {
systemctl enable $1 && systemctl start $1 && systemctl status $1 || true
}
command_exist() {
type "$@" > /dev/null 2>&1
}
log() {
case "$1" in
debug) echo -e "[${BLUE}DEBUG${RESET}] : $2\n";;
info) echo -e -n "${WHITE}$2${RESET}\n" ;;
warn) echo -e "[${YELLOW}WARN${RESET}] : $2\n" ;;
done|success) echo -e "${LIGHT}${GREEN}$2${RESET}\n\n" ;;
error|failure) echo -e "[${RED}ERROR${RESET}] : $2\n" ;;
esac
}
install_common_deps() {
log info "5. install common deps"
yum_install epel-release
yum_install gcc make automake autoconf libtool perl iptraf
yum_install dmidecode libxml2 openssl openssl-devel
yum_install iftop iperf htop vnc-server
yum_install wireshark wireshark-gnome
# curl https://bootstrap.pypa.io/get-pip.py|python && pip install pyaml netaddr || true
yum_install cronie
log done "install common deps...done"
}
gc() {
# generate configuration
rpm -q PyYAML > /dev/null || yum install -y -q python-yaml || true
yum_install python-netaddr
python ./gen_cfg.py
#sleep 1
MME_PORT=$(cat $TMP_DIR/meta | grep "MME_PORT" | awk -F: '{print $2}')
MME_IP=$(cat $TMP_DIR/meta | grep "MME_IP" | awk -F: '{print $2}')
OMC_IP=$(cat $TMP_DIR/meta | grep "OMC_IP" | awk -F: '{print $2}')
S1U_IP=$(cat $TMP_DIR/meta | grep "S1U_IP" | awk -F: '{print $2}')
SGI_IP=$(cat $TMP_DIR/meta | grep "SGI_IP" | awk -F: '{print $2}')
PLMN_ID=$(cat $TMP_DIR/meta | grep "PLMN_ID" | awk -F: '{print $2}')
TACC=$(cat $TMP_DIR/meta | grep "TAC" | awk -F: '{print $2}')
HA_ENABLED=$(cat $TMP_DIR/meta | grep "HA_ENABLED" | awk -F: '{print $2}')
APN=$(cat $TMP_DIR/meta | grep "APN" | awk -F: '{print $2}')
}
i_epc() {
log_start epc
source $SCRIPT_DIR/install_epc.sh || true
# configure epc
sed -i "s#IFNAME=.*#IFNAME=$MME_PORT#g" /usr/local/epc/nwconfig.sh
mysql -DMME -e"update MME_CONFIG set IP_ADDR='$MME_IP';"
mysql -DMME -e"update SDN_CONFIG set SDN_CTRL_ADDR='$MME_IP';"
mysql -DMME -e"update SDN_CONFIG set SDN_S1U_SGW_ADDR='$S1U_IP';"
mysql -DMME -e"update SDN_CONFIG set SDN_S5U_SGW_ADDR='$S1U_IP';"
mysql -DMME -e"update SDN_CONFIG set SDN_S5U_PGW_ADDR='$S1U_IP';"
mysql -DMME -e"update SDN_CONFIG set SDN_SGI_ADDR='$SGI_IP';"
mysql -DMME -e"update MME_SUPPORTED_TAI_LIST set TAC='$TACC' where RID=1;"
mysql -DMME -e"update SDN_TAC_GWUADDR_CONFIG set SDN_S1U_SGW_ADDR='$S1U_IP';"
mysql -DMME -e"update SDN_TAC_GWUADDR_CONFIG set SDN_S5U_SGW_ADDR='$S1U_IP';"
mysql -DMME -e"update SDN_TAC_GWUADDR_CONFIG set SDN_S5U_PGW_ADDR='$S1U_IP';"
mysql -DMME -e"update SDN_TAC_GWUADDR_CONFIG set SDN_SGI_ADDR='$SGI_IP';"
mysql -DMME -e"update SDN_TAC_GWUADDR_CONFIG set TAC='$TACC' where RID=1;"
mysql -DMME -e"update MME_FOR_TAI set PLMN_ID='$PLMN_ID';"
mysql -DMME -e"update MME_FOR_TAI set TAC='$TACC';"
mysql -DMME -e"update MME_FOR_TAI set IP_ADDR='$MME_IP';"
mysql -DMME -e"update GENERAL_CONFIG set PLMNID='$PLMN_ID';"
mysql -DMME -e"update REDIS_PROFILE set REDIS_SERVER_IP='127.0.0.1';"
mysql -DHSS -e"update REDIS_PROFILE set REDIS_SERVER_IP='127.0.0.1';"
mysql -DPCRF -e"update REDIS_PROFILE set REDIS_SERVER_IP='127.0.0.1';"
mysql -DPCRF -e"update DBP_PEER set IPADDR='172.16.7.27';"
mysql -DPCRF -e"update DBP_SERVER set IPADDR='172.16.7.29';"
mysql -DPCRF -e"update INTERFACE_CONFIG set SC_DPI_IP='$MME_IP';"
mysql -DPCRF -e"update INTERFACE_CONFIG set PCRF_DPI_IP='$MME_IP';"
# apn config
for al in $(echo $APN|tr ',' ' '); do
name=$(echo $al|cut -d\| -f1)
start_ipv4=$(echo $al|cut -d\| -f2)
end_ipv4=$(echo $al|cut -d\| -f3)
exist1=$(mysql -DMME -e"select *from APN_CONFIG where APN_NAME='$name';")
if [[ x$exist1 == x ]]; then
if [[ x$RID1 == x ]]; then
RID1=$(mysql -DMME -e"select count(*) from APN_CONFIG"|grep -v "count")
fi
RID1=$(awk -v rid=$RID1 'BEGIN{print rid + 1}')
mysql -DMME -e"insert into APN_CONFIG values ($RID1,'$name',0,'DISABLE','DYNAMIC','IPv4','192.168.9.7',1,25,'IPv4','114.114.114.114','IPv4','8.8.8.8',1,'1','/opt/tmp/','/opt/cdr/',60,10000,1800,20000,30000,'IPv4','172.16.7.28',3883,'IPv4','172.16.7.28',3883);"
fi
exist2=$(mysql -DMME -e"select *from PGW_APN_IP_POOL_CONFIG where APN_NAME='$name';")
if [[ x$exist2 == x ]]; then
if [[ x$RID2 == x ]]; then
RID2=$(mysql -DMME -e"select count(*) from PGW_APN_IP_POOL_CONFIG "|grep -v "count")
fi
RID2=$(awk -v rid=$RID2 'BEGIN{print rid + 1}')
mysql -DMME -e"insert into PGW_APN_IP_POOL_CONFIG values ($RID2,'$name','IPv4','$start_ipv4','$end_ipv4','48','2001:db8::ff0','2009:db8::d53:f');"
else
mysql -DMME -e"update PGW_APN_IP_POOL_CONFIG set UE_START_IPV4ADDR='$start_ipv4' where APN_NAME='$name';"
mysql -DMME -e"update PGW_APN_IP_POOL_CONFIG set UE_END_IPV4ADDR='$end_ipv4' where APN_NAME='$name';"
fi
done
# configure hssBossAPI
sed -i "/HSS/s/.*/ \"HSS\": {\"IP\": \"$MME_IP\", \"PORT\": \"12880\"},/" /usr/local/epc/BOSS_CFG
# configure omBossAPI
sed -i "s#<alarm_api>http://192.168.5.3#<alarm_api>http://$OMC_IP#g" /etc/nginx/cgibin/om_boss_interface_config.xml || true
start_service epc
start_service lmt
log_end epc
}
i_tomcat() {
log_start tomcat
source $SCRIPT_DIR/install_tomcat.sh || true
start_service tomcat
log_end tomcat
}
i_signaltrace() {
log_start signaltrace
source $SCRIPT_DIR/install_signaltrace.sh || true
sed -i "s#REMOTE_IP=.*#REMOTE_IP=$OMC_IP#g" /usr/local/traced/start.sh
# configure sniffer
sed -i "s#REMOTE_IP=.*#REMOTE_IP=$MME_IP#g" /usr/local/sniffer/start.sh
sed -i "s#LOCAL_IP=.*#LOCAL_IP=$MME_IP#g" /usr/local/sniffer/start.sh
start_service traced
start_service sniffer
log_end signaltrace
}
i_onos() {
log_start onos
source $SCRIPT_DIR/install_onos.sh || true
# configure onos
mv $TMP_DIR/config.xml /etc/ctl/config.xml || true
start_service onos
log_end onos
}
i_ovs() {
log_start ovs
source $SCRIPT_DIR/install_ovs.sh || true
# configure ovs
chmod +x $TMP_DIR/*.sh || true
mv $TMP_DIR/ovs-init.sh /usr/local/bin/ovs-init.sh || true
if [[ "${HA_ENABLED}" == "1" ]];then
mv $TMP_DIR/keepalived.conf ./scripts/ovs/keepalived.conf || true
mv $TMP_DIR/report_ha_state.py ./scripts/ovs/report_ha_state.py || true
mv $TMP_DIR/addip_sendarp.sh ./scripts/ovs/addip_sendarp.sh || true
mv $TMP_DIR/delip.sh ./scripts/ovs/delip.sh || true
fi
start_service openvswitch
start_service ovs-init
sleep 3
# change dpid in config.xml, then restart onos
br0_dpid=$(ovs-ofctl show br0 |grep dpid | awk -F: '{print $3}' | sed 's/\(..\)/\0:/g' | sed 's/.$//')
sed -i "s#{{ DPID }}#$br0_dpid#g" /etc/ctl/config.xml || true
systemctl restart onos || true
log_end ovs
}
i_all() {
i_base || true
log info "6. install"
(
i_epc
i_tomcat
i_signaltrace
i_onos
i_ovs
) | tee ./epc-install-`date +%Y-%m-%d-%H-%M`.log
log info "install...done"
}
usage() {
cat << EOF
NAME
install.sh - Install Baicells EPC
SYNOPSIS
$prog COMMAND [OPTIONS]
DESCRIPTION
A tool to install Baicells EPC, include components such as
epc, onos, ovs, tomcat, signaltrace.
OPTIONS
-h Show this help
-i Service to install (default: all)
EOF
exit 0
}
run() {
gc
$1
clean
}
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
ctrl_c() {
echo "** CTRL-C **"
exit 1
}
SERVICE=all
while getopts ":i:h" opt
do
case "$opt" in
h ) usage ;;
i ) SERVICE=${OPTARG} ;;
* ) usage ;;
esac
done
case "$SERVICE" in
base)
run i_base
;;
epc)
run i_epc
;;
tomcat)
run i_tomcat
;;
signaltrace)
run i_signaltrace
;;
onos)
run i_onos
;;
ovs)
run i_ovs
;;
all)
run i_all
;;
*)
usage
;;
esac
2018-04-28 EPC安裝腳本
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門兽泄,熙熙樓的掌柜王于貴愁眉苦臉地迎上來漓概,“玉大人,你說我怎么就攤上這事病梢∥刚洌” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵飘千,是天一觀的道長堂鲜。 經(jīng)常有香客問我栈雳,道長护奈,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任哥纫,我火速辦了婚禮霉旗,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘蛀骇。我一直安慰自己厌秒,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布擅憔。 她就那樣靜靜地躺著鸵闪,像睡著了一般。 火紅的嫁衣襯著肌膚如雪暑诸。 梳的紋絲不亂的頭發(fā)上蚌讼,一...
- 文/蒼蘭香墨 我猛地睜開眼械馆,長吁一口氣:“原來是場噩夢啊……” “哼胖眷!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起霹崎,我...
- 序言:老撾萬榮一對情侶失蹤珊搀,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后仿畸,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體食棕,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡朗和,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了簿晓。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片眶拉。...
- 正文 年R本政府宣布朝刊,位于F島的核電站,受9級特大地震影響蜈缤,放射性物質(zhì)發(fā)生泄漏拾氓。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一底哥、第九天 我趴在偏房一處隱蔽的房頂上張望咙鞍。 院中可真熱鬧,春花似錦趾徽、人聲如沸续滋。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽疲酌。三九已至,卻和暖如春了袁,著一層夾襖步出監(jiān)牢的瞬間朗恳,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓卢鹦,卻偏偏與公主長得像臀脏,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子冀自,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 【注意】 Jmeter必須在系統(tǒng)配置成功jdk后,才能進(jìn)行jmeter的安裝配置運(yùn)行操作熬粗。如果搀玖,系統(tǒng)中沒...
- 【為什么要安裝Gradle?】 如果,你需要在Ubuntu中使用Macaca框架驻呐。Macaca使用的環(huán)境中需要Gr...
- 1.前提:本機(jī)已安裝Android SDK和nodejs 未安裝Android SDK和nodejs灌诅,分別參考下文...
- 1.一鍵安裝Ant的shell腳本: 2.install_ant.sh文件地址: 3.用法: 3.1.wget下載...