#!/bin/bash
#auth:wulei
#date:20210830
export IP=`hostname -I|awk '{print $1}'`
hostnamectl set-hostname $1
init(){
setenforce 0 && sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
systemctl stop firewalld && systemctl disable firewalld
mkdir -p /etc/yum.repos.d/bak && cp -rp /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/ && curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache && yum install net-tools vim git wget netstat ntpdate unzip -y
ntpdate ntp1.aliyun.com
rpm -ivh jdk-8u271-linux-x64.rpm
}
###################################################################################################################################
installConsul(){
unzip unzip consul_1.4.2_linux_amd64.zip && mv consul /usr/local/bin/ && chmod 777 /usr/local/bin/consul
echo "export CONSUL_HOME=/usr/local/bin/consul" >>/etc/profile
echo "export PATH=$PATH:CONSUL_HOME" >>/etc/profile
source /etc/profile
mkdir -p /etc/consul/consul.d && cp -rp config.json /etc/consul/ && sed -i "s#10.10.7.25#${IP}#g" /etc/consul/config.json
mkdir -p /var/run/consul && touch /var/run/consul/consul.pid && nohup /usr/local/bin/consul agent -config-file=/etc/consul/config.json -config-dir=/etc/consul/consul.d -pid-file=/var/run/consul/consul.pid > /var/log/consul.log &
consul kv import --http-addr=http://${IP}:8500 -token=687bd467-a93e-8558-1aaf-f7c4036c406b @kv.json
echo "nohup /usr/local/bin/consul agent -config-file=/etc/consul/config.json -config-dir=/etc/consul/consul.d -pid-file=/var/run/consul/consul.pid > /var/log/consul.log &" >> /etc/rc.local
netstat -lntup|grep 8500
if [ $? -eq 0 ];then
echo -e "\033[44;37m consul安装成功 \033[0m"
else
echo -e "\033[44;31m consul安装失败 \033[0m"
fi
}
#####################################################################################################################################
installDocker(){
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce docker-ce-cli containerd.io && systemctl start docker && systemctl enable docker
touch /etc/docker/daemon.json
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ogeydad1.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload && systemctl restart docker
docker info && docker run hello-world
if [ $? -eq 0 ];then
echo -e "\033[44;37m docker安装成功 \033[0m"
else
echo -e "\033[44;31m docker安装失败 \033[0m"
fi
}
#####################################################################################################################################
installJenkins(){
echo "install jenkins ansible jdk git"
}
installRabbitmq(){
yum install -y gcc gcc-c++ unixODBC-devel openssl-devel ncurses-devel socat-1.7.3.2-2.el7.x86_64
mkdir /usr/local/erlang && mv otp_src_20.0.tar.gz /usr/local/erlang/ && tar zxvf /usr/local/erlang/otp_src_20.0.tar.gz
cd /usr/local/erlang/otp_src_20.0 && ./configure --prefix=/usr/local/erlang/otp_src_20.0/ --with-ssl --enable-hipe --enable-threads --enable-smp-support --enable-kernel-poll --without-javac && make -j4 && make install
echo 'export PATH=$JAVA_HOME/bin/:$PATH:/usr/local/erlang/otp_src_20.0/bin:$PATH' >>/etc/profile && source /etc/profile
sed -i "s#{loopback_users, [<<”guest”>>]},#{loopback_users, []},#g" /usr/lib/rabbitmq/lib/rabbitmq_server-3.7.7/ebin/rabbit.app
systemctl start rabbitmq-server.service && systemctl enable rabbitmq-server.service && rabbitmqctl add_user bocloud bocloud && rabbitmqctl set_permissions bocloud ".*" ".*" ".*" && rabbitmqctl set_user_tags bocloud administrator
sleep 5
netstat -lntup|grep 15672
if [ $? -eq 0 ];then
echo -e "\033[44;37m rabbitmq安装成功 \033[0m"
else
echo -e "\033[44;31m rabbitmq安装失败 \033[0m"
fi
}
installMysql(){
rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
yum install mysql-community-server -y
mkdir /opt/mysqldate
sed -i "s#datadir=/var/lib/mysql#datadir=/opt/mysqldate#g" /etc/my.cnf && echo "character_set_server=utf8" >>/etc/my.cnf && echo "init_connect='SET NAMES utf8'" >>/etc/my.cnf
systemctl start mysqld && systemctl enable mysqld
echo -e "\033[44;37m mysql安装完成,密码请自行初始化:mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log) \033[0m"
}
installRedis(){
echo -e "\033[44;37m rabbitmq is install ok \033[0m"
}
installSonar(){
echo -e "\033[44;37m rabbitmq is install ok \033[0m"
}
installNexus(){
echo -e "\033[44;37m rabbitmq is install ok \033[0m"
}
installApollo(){
}
installNginx(){
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx -y
systemctl enable nginx && systemctl start nginx
}
installSupervisord(){
yum install epel-release -y && yum install -y supervisor
systemctl enable supervisord && systemctl start supervisord
cp -rp /etc/supervisord.conf /etc/supervisord.conf.bak
netstat -lntup|grep 9001
if [ $? -eq 0 ];then
echo -e "\033[44;37m supervisor安装成功 \033[0m"
else
echo -e "\033[44;31m supervisor安装失败 \033[0m"
fi
}
#####################################################################################################################
echo -e "\033[44;37m 请输入要安装的服务,如果安装consul就输入consul \033[0m"
echo -e "\033[43;37m 所有的服务如下
consul
init
docker
jenkins
rabbitmq
mysql
redis
sonar
nexus
apollo
nginx
supervisord
\033[0m"
read -p "请输入要安装的服务" num
case $num in
consul) installConsul
;;
init) init
;;
docker) installDocker
;;
jenkins) installJenkins
;;
rabbitmq) installRabbitmq
;;
mysql) installMysql
;;
redis) installRedis
;;
sonar) installSonar
;;
nexus) installNexus
;;
apollo) installApollo
;;
nginx) installNginx
;;
supervisord) installSupervisord
;;
*) echo -e "\033[41;37m error,非法的参数 \033[0m"
;;
esac
java快捷维护脚本
#startup.sh
#!/bin/bash
APP_NAME=java-test-devops
consul_host=10.10.10.10
acl_token=64fdddd7-a93e-8558-122af-f7c4036232ss6b
#检查程序是否在运行
is_exist(){
pid=`ps -ef | grep -w $APP_NAME |grep "java" | awk '{print $2}' `
#如果不存在返回1,存在返回0
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
is_exist
if [ $? -eq "0" ]; then
echo "kill ${pid} "
kill -9 $pid
else
echo "${APP_NAME} is not running"
fi
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is already running. pid=${pid} ."
else
nohup java -Dconsul_host=${consul_host} -Dconsul_token=${acl_token} -jar ${APP_NAME}.jar > /root/devops/java-test-devops/app.log 2>&1 &
#nohup java -Dconsul_host=${consul_host} -Dconsul_token=${acl_token} -jar ${APP_NAME}.jar > ./logs/applog.log 2>&1 &
echo "app run ok..."
fi
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is running. pid is ${pid} "
else
echo "${APP_NAME} is not running."
fi
#!/bin/bash
#auth:wulei
#date:20210830
export LogDir="/root/devops"
upms_run() {
while :
do
read -p "请选择停止该服务(stop),还是启动该服务(start),还是只看日志(log)" num
case $num in
stop)
kill -9 `ps -ef|grep upms-run.jar|grep java|awk '{print $2}'`
if [ $? -eq 0 ]; then
echo -e "\033[42;39m 停止成功 \033[0m"
else
echo -e "\033[41;39m 服务停止失败 \033[0m"
fi
;;
start)
sh ${LogDir}/upms-run/startup.sh
;;
log)
tail -f ${LogDir}/upms-run/logs/upms.log
;;
*)
echo -e "\033[44;31m 请输入stop或start或log \033[0m"
;;
esac
done
}
###################################################################################################################################
essence_keycloak() {
while :
do
read -p "请选择停止该服务(stop),还是启动该服务(start),还是只看日志(log)" num
case $num in
stop)
kill -9 `ps -ef|grep essence-keycloak-1.0.0-SNAPSHOT.jar|grep java|awk '{print $2}'`
if [ $? -eq 0 ]; then
echo -e "\033[42;39m 停止成功 \033[0m"
else
echo -e "\033[41;39m 服务停止失败 \033[0m"
fi
;;
start)
sh ${LogDir}/essence-keycloak/startup.sh
;;
log)
tail -f ${LogDir}/essence-keycloak/logs/essence.log
;;
*)
echo -e "\033[44;31m 请输入stop或start或log \033[0m"
;;
esac
done
}
#####################################################################################################################
echo -e "\033[44;37mi 请输入要执行的服务名称,如果是upms-keycloak-run就输入upms-keycloak-run \033[0m"
echo -e "******************所有的服务如下********************
*************************upms-run***************************
*************************essence-keycloak********************
\033[0m"
read -p "请开始选择服务" num
case $num in
upms-run) upms_run
;;
essence-keycloak) essence_keycloak
;;
*) echo -e "\033[41;37m error,非法的参数,请输入upms-run或者essence-keycloak \033[0m"
exit 1
;;
esac