案例3-ubuntu和centos中自动部署tomcat相关服务的脚本
涉及redis,mysql,xtrabackup, tomcat
1. ubuntu中
#!/bin/bash #first, change to root #出错立刻中断
set -e apt-get update
#useful tools
apt-get -y install build-essential libssl-dev libcurl4-openssl-dev unzip makepasswd lrzsz \
language-pack-zh-hans-base python-pip python-dev libxp6 libev-dev pwgen expect #. auto scp software from aliyun #/usr/bin/expect <<EOF SCP拷贝,这种方式老是传一半出错。
#set ip 47.52.136.86
#set pass 12345 #spawn ssh root@$ip
#spawn scp -r root@$ip:/root/UBUNTU .
#expect {
# "(yes/no)" {send "yes\r"; exp_continue}
# " password: " {send "$pass\r"}
#} #expect "*#" {send "df -h\r"}
#expect "*#" {send "exit\r"}
#expect eof #EOF #rsync支持断点续传
rsync -rP --rsh=ssh 47.52.136.86:/root/UBUNTU/ /root echo "nameserver 114.114.114.114" >> /etc/resolvconf/resolv.conf.d/base
resolvconf -u #. this script is for creating a new user
A_NAME=$(ls /home)
[ -z "A_NAME" ] && /usr/sbin/useradd axinfu
A_NAME=$(ls /home) su - $A_NAME -c "mkdir axinfu && cd axinfu && mkdir mgrfilepath cert accountfile config" #. this script is for JDK
JdkPath="/usr/lib/jvm" if [ ! -d "$JdkPath" ]; then
mkdir -p $JdkPath #attention here
fi tar xzvf jdk.tar.gz -C /usr/lib/jvm update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_80/bin/java"
update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_80/bin/javac"
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_80/bin/javaws" #set env for jdk
JAVA_HOME=/usr/lib/jvm/jdk1..0_80 (
cat << EOF
export JAVA_HOME=/usr/lib/jvm/jdk1..0_80
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
EOF
)>>/etc/profile #another way, this is better
#cat >> /etc/profile <<EOF
#LINE
#LINE
#EOF source /etc/profile #.for tomcat
tar xzvf apache-tomcat-7.0..tar.gz -C /home/"${A_NAME}"
mv /home/$A_NAME/apache-tomcat-7.0./webapps /home/$A_NAME
chown -R $A_NAME:$A_NAME /home/$A_NAME #copy setenv.sh for tomcat
cp /usr/lib/jvm/setenv.sh /home/$A_NAME/apache-tomcat-7.0./bin/ #change ownership of tomcat
/bin/chown -R $A_NAME:$A_NAME /home/$A_NAME/apache-tomcat-7.0./ #edit server.xml
sed -i -e '22 s/8005/-1/' -e '71 s/8080/8081/' -e '125 s#webapps#../webapps#' /home/$A_NAME/apache-tomcat-7.0./conf/server.xml
sed -i -e '93 s/</<!--/' -e '93 s/>/-->/' /home/$A_NAME/apache-tomcat-7.0./conf/server.xml sed -i -e '71 s#HTTP/1.1#org.apache.coyote.http11.Http11NioProtocol#' /home/$A_NAME/apache-tomcat-7.0./conf/server.xml #start tomcat
/bin/su -s /bin/sh - $A_NAME -c "cd /home/$A_NAME/apache-tomcat-7.0.81/bin/&&./startup.sh"
#上面这个命令可以简化为
#su - $A_NAME -c "cd apache-tomcat-7.0.81/bin/&&./startup.sh"
#-c command:变更为帐号为USER的使用者并执行指令后再变回原来使用者。command一般用双引号指定
#-s shell:指定要执行的shell,而且参数中必须是shell的完整的路径。如果没有,则默认为/bin/sh,所以这里也可以不写
#-或-l或--login:这个参数加了之后,就好像是重新login为该使用者一样,工作目录也会改变为该用户的家目录 cat tomcat > /etc/init.d/tomcat
/bin/chmod /etc/init.d/tomcat #add to startlist
update-rc.d tomcat defaults #. for crontab
(
cat << EOF
* * * python /root/mysql_back_up/main.py full
* * * * python /root/mysql_back_up/main.py inc
EOF
)>/var/spool/cron/crontabs/root
/bin/chmod +x /var/spool/cron/crontabs/root #. collect info
CPU=$(lscpu | sed -n '4p' | awk -F "[ ]+" '{print $2}')
BLK=$(lsblk | grep disk | awk -F "[ ]+" '{print $4}')
RAM=$(free -g | grep Mem | awk -F "[ ]+" '{print $2}')
PLATFORM=$(dmidecode -s system-product-name) (
cat << EOF
cpu:$CPU
disk:$BLK
ram:$RAM
platform:$PLATFORM EOF
)>INFO cat /proc/scsi/scsi | grep Vendor >> INFO
echo -e "\n" >> INFO
cat /proc/version >> INFO #create password
pwgen -Bs > secret.txt #. for mysql exist=$(dpkg -l | grep mysql) # 若没有返回,说明已完成卸载
if [ -n "$exist" ]; then
#uninstll mysql5.
apt-get autoremove --purge mysql-server-.*
apt-get remove mysql-common
dpkg -l |grep ^rc|awk '{print $2}' | xargs dpkg -P
fi #install mysql5. http://blog.csdn.net/u011304615/article/details/68942115
echo 'mysql-server-5.6 mysql-server/root_password password 123' | debconf-set-selections
echo 'mysql-server-5.6 mysql-server/root_password_again password 123' | debconf-set-selections
#apt-get install mysql-client-core-5.6 mysql-client-5.6 mysql-server-5.6 -y 这种安装方式修改字符集会启动不了mysql
apt-get install -y mysql-server-5.6 mysql-client-5.6 libmysqlclient-dev #在[mysqld]行后面加入内容,解决不同版本[mysqld]行数不同的问题
sed -ir "/[mysqld]/ a character_set_server=utf8 \nbinlog_format=row" /etc/mysql/my.cnf
service mysql restart mysql -uroot -p123 -e "GRANT RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'bak'@'localhost' IDENTIFIED BY 'axfchonga';FLUSH PRIVILEGES" mysql_secure_installation #. for backup wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.8/binary/debian/trusty/x86_64/percona-xtrabackup-24_2.4.8-1.trusty_amd64.deb
dpkg -i percona-xtrabackup-24_2.4.8-.trusty_amd64.deb #. this script is for REDIS
tar xzvf redis-stable.tar.gz
cd redis-stable
#yum -y groupinstall "Development Tools"
make
make install
cd utils
/usr/bin/expect <<EOF
spawn ./install_server.sh
expect "*6379*" {send "\r"}
expect "*conf*" {send "\r"}
expect "*log*" {send "\r"}
expect "*var/lib*" {send "\r"}
expect "*server*" {send "\r"}
expect "*ok*" {send "\r"}
expect eof EOF
2. centos中
#!/bin/bash #wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo #
yum update
yum install autoconf automake binutils bison flex gcc gcc-c++ gettext libtool make patch pkgconfig rpm-build yum-utils epel-release
yum-plugin-fastestmirror yum-plugin-downloadonly openssl-devel nc curl wget man nss vim system-config-network-tui bind-utils lokkit pciutils redhat-lsb-core libX11 libXp telnet #. for mysql
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el6/mysql57-community-release-el6-7.noarch.rpm
rpm -ivh mysql57-community-release-el6-.noarch.rpm
sed -ie '27 s/0/1/; 34 s/1/0/' /etc/yum.repos.d/mysql-community.repo #参数i必须在参数e前面,e表示可以有多个命令
yum install mysql-community-server mysql-community-devel mysql-community-client #sed -i -e '2 i character-set-server=uft8' -e '2 i binlog-format=row' /etc/my.cnf
sed -ir '/\[mysqld\]/a character-set-server=utf8 \nbinlog-format=row' /etc/my.cnf service mysqld start #. create user
A_NAME=$(ls /home)
[ -z "A_NAME" ] && /usr/sbin/useradd axinfu
A_NAME=$(ls /home) su - $A_NAME -c "mkdir axinfu && cd axinfu && mkdir mgrfilepath cert accountfile config"
#another way
#A_NAME=$(cat /etc/passwd | grep home | cut -d: -f ) #有的系统是500,所以取不到。
#[ -z "A_NAME" ] && /usr/sbin/useradd axinfu
#A_NAME=$(cat /etc/passwd | grep home | cut -d: -f ) #. for JDK
JdkPath="/usr/lib/jvm" if [ ! -d "$JdkPath" ]; then
mkdir -p $JdkPath #attention here
fi tar xzvf jdk.tar.gz -C /usr/lib/jvm update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_80/bin/java"
update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_80/bin/javac"
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_80/bin/javaws" #set env for jdk
JAVA_HOME=/usr/lib/jvm/jdk1..0_80 (
cat << EOF
export JAVA_HOME=/usr/lib/jvm/jdk1..0_80
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
EOF
)>>/etc/profile #another way, this is better
#cat >> /etc/profile <<EOF
#LINE
#LINE
#EOF
source /etc/profile #. for tomcat
tar xzvf apache-tomcat-7.0..tar.gz -C /home/"${A_NAME}"
mv /home/$A_NAME/apache-tomcat-7.0./webapps /home/$A_NAME
chown -R $A_NAME:$A_NAME /home/$A_NAME #copy setenv.sh for tomcat
cp /usr/lib/jvm/setenv.sh /home/$A_NAME/apache-tomcat-7.0./bin/ #change ownership of tomcat
/bin/chown -R $A_NAME:$A_NAME /home/$A_NAME/apache-tomcat-7.0./ #edit server.xml
sed -i -e '22 s/8005/-1/' -e '71 s/8080/8081/' -e '125 s#webapps#../webapps#' /home/$A_NAME/apache-tomcat-7.0./conf/server.xml
sed -i -e '93 s/</<!--/' -e '93 s/>/-->/' /home/$A_NAME/apache-tomcat-7.0./conf/server.xml
sed -i -e '71 s#HTTP/1.1#org.apache.coyote.http11.Http11NioProtocol#' /home/$A_NAME/apache-tomcat-7.0./conf/server.xml #start tomcat
/bin/su -s /bin/sh - $A_NAME -c "cd /home/$A_NAME/apache-tomcat-7.0.81/bin/&&./startup.sh"
#上面这个命令可以简化为
#su - $A_NAME -c "cd apache-tomcat-7.0.81/bin/&&./startup.sh"
#-c command:变更为帐号为USER的使用者并执行指令后再变回原来使用者。command一般用双引号指定
#-s shell:指定要执行的shell,而且参数中必须是shell的完整的路径。如果没有,则默认为/bin/sh,所以这里也可以不写
#-或-l或--login:这个参数加了之后,就好像是重新login为该使用者一样,工作目录也会改变为该用户的家目录
cat tomcat > /etc/init.d/tomcat
/bin/chmod /etc/init.d/tomcat chkconfig --add tomcat #. for mysql_crontab
(
cat << EOF
* * * python /root/mysql_back_up/main.py full
* * * * python /root/mysql_back_up/main.py inc
EOF
)>/var/spool/cron/root
/bin/chmod +x /var/spool/cron/root #. backup
wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.8/binary/redhat/6/x86_64/percona-xtrabackup-24-2.4.8-1.el6.x86_64.rpm
wget ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/libev-4.15-1.el6.rf.x86_64.rpm #依赖包
rpm -ivh libev-4.15-.el6.rf.x86_64.rpm
yum install perl-DBD-mysql #依赖包
yum -y install perl-Digest-MD5 #依赖包 rpm -ivh percona-xtrabackup--2.4.-.el6.x86_64.rpm #. for REDIS tar xzvf redis-stable.tar.gz
cd redis-stable
yum -y groupinstall "Development Tools"
make
make install
cd utils
./install_server.sh # download REDIS
#wget http://download.redis.io/redis-stable.tar.gz # download TOMCAT
#wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.79/bin/apache-tomcat-7.0.79.tar.gz
案例3-ubuntu和centos中自动部署tomcat相关服务的脚本的更多相关文章
- CentOS中自动加载802.1q模块
要想在CentOS中自动加载内核模块,需要在/etc/sysconfig/modules/目录中增加一个脚本,在此脚本中加载所需的模块. 下面是我所用的一个名为8021q.modules的脚本,用来在 ...
- Jenkins自动部署Tomcat项目
Jenkins自动部署Tomcat项目 1.安装jenkins 插件 启动Jenkins,进入系统管理-插件管理: 选择Deploy to container Plugin 插件安装:
- 使用Maven自动部署Tomcat 6和Tomcat 7下Web应用
使用Maven自动部署Tomcat 6和Tomcat 7下Web应用 开启Tomcat远程管理权限 在tomcat的config目录下的tomcat-users.xml文件, <role rol ...
- linux下实现自动部署tomcat的脚本
linux下实现自动部署tomcat的脚本 由于经常部署war到tomccat上,经常有一些重复的工作要做:停服务.备份war包.上传新的war包.启动服务.索性就写了一个自动部署的脚本. 脚本如下a ...
- 自动部署tomcat 脚本
自动部署tomcat 脚本 . /etc/init.d/functions #调用系统函数 yum -y install java >/dev/null TAR="apache-tom ...
- centos中如何查看tomcat的版本
centos中如何查看tomcat的版本 如果使用的rpm安装的tomcat,则使用如下命令查看 rpm -q tomcat 如果不是使用rpm安装的tomcat ./catalina.sh vers ...
- jekins自动部署tomcat注意事项、连接tomcat报错
jekins自动部署tomcat注意事项 千万不要用下面插件推送,报错很多, 要用脚本,一篇博客说的:“我们都是用的脚本,插件报错太多,也不完善” Deploy to container Plugin ...
- 单机部署tomcat的shell脚本
单机部署tomcat的shell脚本,来自网络,自己需要时要根据自己的需求改动. #!/bin/sh # ############################################### ...
- CI在CentOS中的部署与实践LNMP
1. 平台:lnmp CentOS6.4 (64bit) nginx1.2.4+php5.5.7配置过程中遇到的问题与处理方式: 1. 404错误: 原因:nginx中的配置请求路径的问题 2. 40 ...
随机推荐
- js使用浏览器的另存为下载文件
页面上的页面如下: 我需要根据返回的url下载文件: js: //判断浏览器类型 function myBrowser(){ var userAgent = navigator.userAgent; ...
- 学习h5(开始)
webstorm 下载地址:http://www.sdifenzhou.com/6176.html webstorm注册码: 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QT ...
- 集合_java集合框架
转载自http://blog.csdn.net/zsw101259/article/details/7570033 Java集合框架图 简化图: Java平台提供了一个全新的集合框架.“集合框架”主要 ...
- code1225 搭积木
题目分析:将当前层定义为第h层,共用了n块积木,本层积木数为m,f(h,n,m) 那么可以扩展数两种状态:f(h-1,n-m,m-1),f(h-1,n-m,m+1) 直接搜索可能的数据达到h^m,超时 ...
- C# 基础连接已经关闭: 发送时发生错误
在程序中获取某个https网址的源码,GetRespose()时 出现了“基础连接已经关闭: 发送时发生错误.”的错误提示. 翻了论坛后,有个仁兄说: //.net 4 ...
- 【转】Eclipse中10个最有用的快捷键组合
转载地址:http://blog.csdn.net/seebetpro/article/details/46227005 一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合. ...
- jQuary总结5:传递一个dom对象
1 传递一个dom对象 //html <div></div> <p id="p"></p> //js var p = documen ...
- Word 2010发布博客文章(修正)
目前大部分的博客作者在写博客这件事情上都会遇到以下3个痛点:1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.2.发布到博客或公众号平台 ...
- word上传博客教程
目前大部分的博客作者在写博客这件事情上都会遇到以下3个痛点:1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.2.发布到博客或公众号平台 ...
- css3的那些高级选择器二
在上个星期我介绍了css3的属性选择器,伪类选择器和结构伪类选择器,今天楼主继续把其它的css3选择器说完. 在css3中,共有11中UI状态伪类选择器,分别是E:hover,E:active,E:f ...