1.基础准备
项目:ZrLog个人博客
项目介绍:
ZrLog是使用 Java 开发的博客/CMS程序,具有简约,易用,组件化,内存占用低等特点。自带 Markdown 编辑器,让更多的精力放在写作上。
github地址:https://github.com/94fzb/zrlog
所需软件:
nginx tomcat mysql(mariadb) oraclejdk
[root@zrlog ZrLog]# pwd
/root/ZrLog
[root@zrlog ZrLog]# ll
total 208112
-rw-r--r--. 1 root root 9904915 Mar 16 20:26 apache-tomcat-9.0.11.tar.gz
-rw-r--r--. 1 root root 191757099 Mar 16 20:28 jdk-8u192-linux-x64.tar.gz
-rw-r--r--. 1 root root 1061461 Aug 30 20:23 nginx-1.20.1.tar.gz
-rw-r--r--. 1 root root 10373409 Mar 16 20:26 ROOT.war #项目文件
系统:centos8
已配置清华源
关闭防火墙及selinux
[root@zrlog ~]# systemctl stop firewalld
[root@zrlog ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@zrlog ~]# getenforce
Enforcing
[root@zrlog ~]# setenforce 0
[root@zrlog ~]# sed -i "s/enforcing/permissive/g" /etc/selinux/config
2.博客搭建
一.mariadb
[root@zrlog ZrLog]# dnf -y install mariadb mariadb-server #安装mariadb数据库
[root@zrlog ZrLog]# systemctl start mariadb
[root@zrlog ZrLog]# systemctl enable mariadb #mariadb开机自启
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@zrlog ZrLog]# mysql_secure_installation #初始化数据库
...
[root@zrlog ZrLog]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.28-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> MariaDB [(none)]> create user 'zrlog'@'%' identified by 'password';
Query OK, 0 rows affected (0.000 sec) #创建用户
MariaDB [(none)]> create database zrlog;
Query OK, 1 row affected (0.000 sec) #创建zrlog库
MariaDB [(none)]> grant all on zrlog.* to 'zrlog'@'%' identified by 'password';
Query OK, 0 rows affected (0.000 sec) #给用户赋权
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec) #生效权限
MariaDB [(none)]> quit
Bye
二.nginx
[root@zrlog ZrLog]# tar -zxvf nginx-1.20.1.tar.gz #解压缩包
[root@zrlog ZrLog]# cd nginx-1.20.1/
[root@zrlog nginx-1.20.1]# yum -y install pcre-devel zlib-devel openssl-devel #安装依赖包
[root@zrlog nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module && make && make install #编译安装
[root@zrlog conf]# useradd www
[root@zrlog conf]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
[root@zrlog ~]# cd /usr/local/nginx/conf/
[root@zrlog conf]# vim nginx.conf #更改nginx配置文件
server {
listen 80;
server_name 127.0.0.1;
root /usr/local/tomcat/webapps/zrlog/ROOT;
location ~ \.(html|css|js|png|jpg|jpeg)$ { #静态资源交由nginx处理
}
location / { #其余转发到后端tomcat
proxy_pass http://172.20.246.221:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
保存退出
[root@zrlog conf]# nginx -t #检查配置未见未发现异常
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@zrlog conf]# nginx #启动nginx
[root@zrlog conf]# ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=26403,fd=8),("nginx",pid=26402,fd=8))
三.oraclejdk
[root@zrlog ZrLog]# tar -zxvf jdk-8u192-linux-x64.tar.gz #解压缩包
[root@zrlog ZrLog]# mkdir /usr/local/java
[root@zrlog ZrLog]# mv jdk1.8.0_192/* /usr/local/java/
[root@zrlog ZrLog]# echo "PATH=/usr/local/java/bin:$PATH" >> /etc/profile #配置java环境变量
[root@zrlog ZrLog]# source /etc/profile #生效配置
四.tomcat
[root@zrlog ZrLog]# tar -zxvf apache-tomcat-9.0.11.tar.gz #解压缩包
[root@zrlog ZrLog]# mkdir /usr/local/tomcat
[root@zrlog ~]# cd /usr/local/tomcat/webapps/
[root@zrlog webapps]# mkdir zrlog
[root@zrlog webapps]# cd zrlog/
[root@zrlog zrlog]# cp /root/ZrLog/ROOT.war ./
[root@zrlog ZrLog]# mv apache-tomcat-9.0.11/* /usr/local/tomcat/
[root@zrlog ZrLog]# cd /usr/local/tomcat/conf/
[root@zrlog zrlog]# chown -R www:www /usr/local/tomcat/webapps/
[root@zrlog conf]# vim server.xml
搜索Host,在最后一个Host下添加如下内容
<Host name="172.20.246.221" appBase="webapps/zrlog">
</Host>
保存退出
[root@zrlog conf]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
3.测试服务
访问页面:
进入浏览器输入ip:172.20.246.221
输入mariadb的用户名以及密码
用户名:zrlog
密码:password
此处信息皆可自己选择填写
例:
点击下一步完成安装
重新返回浏览器输入ip
进入管理页面
输入用户名和密码
点击文章撰写即可开始记录个人博客