简介
OneBlog 一个简洁美观、功能强大并且自适应的Java博客。使用springboot开发,前端使用Bootstrap。支持移动端自适应,配有完备的前台和后台管理功能
https://gitee.com/yadong.zhang/DBlog
准备工作
安装 JDK(1.8+)
安装 Maven (3.3.0+)
安装 Redis服务 (3.0+)
安装 MySQL (5.6+)
准备jdk
vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
准备maven
vim /etc/profile.d/maven.sh
export MAVEN_HOME=/usr/local/maven
export PATH="$MAVEN_HOME/bin:$PATH"
maven仓库配置
vim /usr/local/maven/conf/settings.xml
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
准备MySQL
create database dblog character set utf8mb4 collate utf8mb4_general_ci;
grant all on dblog.* to 'dblog'@'127.0.0.1' identified by '123456';
mysql -h 127.0.0.1 -udblog -p123456
导入数据
docs/db/dblog.sql
docs/db/init_data.sql
准备redis
yum install redis
systemctl start redis.service
下载项目
git clone https://gitee.com/yadong.zhang/DBlog.git
连接数据库文件
grep -r -l 'jdbc:mysql' *
blog-core/src/main/resources/config/application-center-test.yml
blog-core/src/main/resources/config/application-center-dev.yml
编译打包
项目根目录下执行
mvn -X clean package -Dmaven.test.skip=true -Ptest
启动前台
cd到blog-web目录下执行
nohup java -jar target/blog-web.jar &
启动后台
cd到blog-admin目录下执行
nohup java -jar target/blog-admin.jar &
后台账户
超级管理员: 账号:root 密码:123456
普通管理员: 账号:admin 密码:123456
jenkins-maven构建
Pre Steps
vim /server/scripts/pre_build.sh
#!/bin/bash
/usr/bin/cp /tmp/application-center-dev.yml blog-core/src/main/resources/config/application-center-dev.yml
/usr/bin/cp /tmp/application-center-test.yml blog-core/src/main/resources/config/application-center-test.yml
/bin/bash /server/scripts/pre_build.sh
Build
Root POM
pom.xml
Goals and options
-X clean package -Dmaven.test.skip=true -Ptest
Post Steps
cat /server/scripts/post_build.sh
#!/bin/bash
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib
DATE=$(date +%Y-%m-%d-%H-%M-%S)
tar zcf /opt/oneblog_${DATE}.tar.gz *
ssh root@192.168.0.156 "mkdir -p /opt/oneblog_${DATE}"
scp -rp /opt/oneblog_${DATE}.tar.gz /server/scripts/oneblog_start.sh root@192.168.0.156:/opt/oneblog_${DATE}/
ssh root@192.168.0.156 "cd /opt/oneblog_${DATE}/ && tar xf oneblog_${DATE}.tar.gz && rm /opt/oneblog -f && ln -s /opt/oneblog_${DATE} /opt/oneblog"
ssh root@192.168.0.156 "/usr/local/mysql/bin/mysql dblog -e 'source /opt/oneblog/docs/db/init_data.sql;'"
wait
ssh root@192.168.0.156 "cd /opt/oneblog_${DATE}/ && /bin/bash oneblog_start.sh"
/bin/bash /server/scripts/post_build.sh
cat /server/scripts/oneblog_start.sh
#!/bin/bash
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib
kill -9 $(jps |awk '/blog-web/{print $1}')
sleep 2
cd /opt/oneblog/blog-web
java -jar target/blog-web.jar &> /opt/oneblog/blog-web/oneblog.log &
修改代码测试自动部署
grep -rl "OneBlog开源博客" *
[root@web1 oneblog]# grep "OneBlog开源博客" blog-web/src/main/resources/templates/include/macros.ftl
<#macro header title="OneBlog开源博客" keywords="" description="" canonical="" hasEditor=false>
[root@web1 oneblog]# grep "OneBlog开源博客" docs/db/init_data.sql
INSERT INTO `dblog`.`sys_config`(`id`, `config_key`, `config_value`, `create_time`, `update_time`) VALUES (6, 'siteName', 'OneBlog开源博客', now(), now());
INSERT INTO `dblog`.`sys_notice` VALUES (1, 1, 'RELEASE', 'OneBlog开源博客', 'OneBlog开源博客,一款超好用的Java版开源博客', now(), now());
sed 's#OneBlog开源博客#linux61#g' docs/db/init_data.sql -i
Jenkinsfile
pipeline{
agent any
stages{
stage("get code"){
steps{
echo "get code"
}
}
stage("Pre Steps"){
steps{
sh '/bin/bash /server/scripts/pre_build.sh'
}
}
stage("Build"){
steps{
sh '/usr/local/maven/bin/mvn -X clean package -Dmaven.test.skip=true -Ptest'
}
}
stage("Post Steps"){
steps{
sh '/bin/bash /server/scripts/post_build.sh'
}
}
}
}