• 极力推荐大佬的java项目的博客


     此次说明:这是我从码云上拉取下来的java项目,仅供试验说明,不做任何获利渠道,若是发现有人拿此做其他用处,需像码云上这位大佬说明,特此感谢!!!

    准备工作:

        安装 maven,jdk1.8,下载项目(DBlog),mysql,redis,git

    下载Maven 3安装包官网:http://maven.apache.org/download.cgi

          清华镜像:https://mirrors.tuna.tsinghua.edu.cn/apache/maven/

     

     老夫下载好的软件=====>>>>>链接:https://pan.baidu.com/s/1jHYfVGKOEM4WuU9OOaEvYQ      提取码:uutl

    安装Maven

    [root@localhost opt]#tar xf apache‐maven‐3.3.9‐bin.tar.gz
    [root@localhost opt]# mv apache-maven-3.3.9 /usr/local/maven
    

    编辑/etc/profile文件

    export PATH=/usr/local/maven/bin:$PATH
    source /etc/profile
    

    检查版本信息

    [root@localhost /]# mvn -v
    Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
    Maven home: /usr/local/maven
    Java version: 1.8.0_181, vendor: Oracle Corporation
    Java home: /usr/java/jdk1.8.0_181-amd64/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"
    

    安装jdk1.8版本(只要是1.8即可,随便那种方式安装都行)

    [root@localhost /]# rpm -ivh jdk-8u181-linux-x64.rpm
    warning: jdk-8u181-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:jdk1.8-2000:1.8.0_181-fcs        ################################# [100%]
    Unpacking JAR files...
            tools.jar...
            plugin.jar...
            javaws.jar...
            deploy.jar...
            rt.jar...
            jsse.jar...
            charsets.jar...
            localedata.jar...
    

     查看版本安装是否成功

    [root@localhost /]# java -version
    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode) 

    在码云上下载博客资源

    特别说明:获取资源链接地址,开始下载,有安装git的可以使用git clone+链接的方式下载,没有的话只能安装git因为链接资源是git文件,其他方式下载打不开的

    这里安装并设置下git,然后下载项目资源

    [root@localhost opt]#  yum -y install git
    [root@localhost opt]# git init     #初始化仓库,不过注意此仓库不要有其他文件
    [root@localhost opt]# git clone https://gitee.com/yadong.zhang/DBlog.git    #https这就是从码云上获取的链接
    Cloning into 'DBlog'...
    remote: Enumerating objects: 6356, done.
    remote: Counting objects: 100% (6356/6356), done.
    remote: Compressing objects: 100% (3022/3022), done.
    remote: Total 6356 (delta 3147), reused 4916 (delta 2417)
    Receiving objects: 100% (6356/6356), 6.87 MiB | 3.32 MiB/s, done.
    Resolving deltas: 100% (3147/3147), done.
    [root@localhost opt]# ls
    DBlog
    

    将下载地址换成阿里云

    原因:因为原地址是国外的,对于我们来说获取资源太慢,所以换成了国内的,比如阿里云

    [root@localhost opt]# cd /usr/local/maven/conf/
    [root@localhost conf]# ls
    logging  settings.xml  toolchains.xml
    [root@localhost conf]# cp settings.xml settings.xml.bak
    [root@localhost conf]# vim settings.xml          ####将下面这段代码复制到相应代码行即可
    <mirror> 
    <id>nexus-aliyun</id> 
    <mirrorOf>*</mirrorOf> 
    <name>Nexus aliyun</name> 
    <url>http://maven.aliyun.com/nexus/content/groups/public</url> 
    </mirror>
    

    安装mysql,redis并配置 

     先配置mysql

    [root@localhost opt]# mkdir /app
    将mysql二进制包放进来后解压
    [root@localhost app]# tar -xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
    改名
    [root@localhost app]# mv mysql-5.7.20-linux-glibc2.12-x86_64/ mysql
    设置变量
    [root@localhost app]# vim /etc/profile
    export PATH=/app/mysql/bin:$PATH
    激活变量
    [root@localhost app]# source /etc/profile
    查看版本,意味着变量设置成功
    [root@localhost app]# mysql -V
    mysql  Ver 14.14 Distrib 5.7.20, for linux-glibc2.12 (x86_64) using  EditLine wrapper
    

    添加mysql用户,设置授权目录并初始化

    [root@localhost app]# useradd mysql
    [root@localhost app]# mkdir /data/mysql -p
    [root@localhost app]# chown -R mysql.mysql /app/*
    [root@localhost app]# chown -R mysql.mysql /data/*
    [root@localhost app]# mysqld --initialize-insecure  --user=mysql --basedir=/app/mysql --datadir=/data/mysql
    2019-05-01T16:11:19.720627Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2019-05-01T16:11:23.737783Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2019-05-01T16:11:24.729527Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2019-05-01T16:11:24.842128Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c48c1c90-6c2b-11e9-9c15-000c291d19ad.
    2019-05-01T16:11:24.843849Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2019-05-01T16:11:24.846586Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    [root@localhost app]# cd /data/mysql/
    [root@localhost mysql]# ll
    total 110628
    -rw-r-----. 1 mysql mysql       56 May  2 00:11 auto.cnf
    -rw-r-----. 1 mysql mysql      419 May  2 00:11 ib_buffer_pool
    -rw-r-----. 1 mysql mysql 12582912 May  2 00:11 ibdata1
    -rw-r-----. 1 mysql mysql 50331648 May  2 00:11 ib_logfile0
    -rw-r-----. 1 mysql mysql 50331648 May  2 00:11 ib_logfile1
    drwxr-x---. 2 mysql mysql     4096 May  2 00:11 mysql
    drwxr-x---. 2 mysql mysql     8192 May  2 00:11 performance_schema
    drwxr-x---. 2 mysql mysql     8192 May  2 00:11 sys
    

     添加配置文件

    [root@localhost mysql]# vim /etc/my.cnf
    [root@localhost mysql]# mv /etc/my.cnf /opt/my.cnf.bak
    [root@localhost mysql]# vim /etc/my.cnf
    [mysqld]
    user=mysql
    basedir=/app/mysql
    datadir=/data/mysql
    server_id=6
    port=3306
    socket=/tmp/mysql.sock
    [mysql]
    socket=/tmp/mysql.sock
    prompt=3306 [\d]>
    [root@localhost mysql]# cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
    [root@localhost mysql]# service mysqld start|stop|restart    ###这里和上一步是为了使用service命令控制服务,
    [root@localhost mysql]# vim /etc/systemd/system/mysqld.service      ###如果上面的方式不爽,想用systemctl命令需要这样设置
     
    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    User=mysql
    Group=mysql
    ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    LimitNOFILE = 5000
    [root@localhost mysql]# mysqladmin -uroot -p password 123456
    Enter password:             ###这里直接回车,因为初始状态没设置密码
    mysqladmin: [Warning] Using a password on the command line interface can be insecure.
    Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
    在mysql中创建dblog库即可;    ##这里是项目需要dblog数据库
    3306 [(none)]>create database dblog charset utf8mb4;
    Query OK, 1 row affected (0.00 sec)
    3306 [(none)]>
    [root@localhost ~]# mysql -uroot -p123456 dblog < /opt/DBlog/docs/db/dblog.sql
    mysql: [Warning] Using a password on the command line interface can be insecure.
    [root@localhost ~]# mysql -uroot -p123456 dblog < /opt/DBlog/docs/db/init_data.sql
    mysql: [Warning] Using a password on the command line interface can be insecure. 

     安装配置redis

     yum -y install redis
    [root@localhost opt]# vim /etc/redis.conf   #编辑之前做好这个文件的备份,别问我为什么,这是运维的基本素养
    61 bind 192.168.171.144       ###这个61是行数,设置服务器的ip,不要使用127.0.0.1的地址
    479 equirepass 123456          ###479是行数,设置密码
    root@localhost opt]# systemctl restart redis
    [root@localhost opt]# ps -ef |grep redis
    redis     13042      1  0 00:52 ?        00:00:00 /usr/bin/redis-server 192.168.171.144:6379
    root      13047   2452  0 00:52 pts/1    00:00:00 grep --color=auto redis
    

     对项目开始动手了

    [root@localhost config]# pwd
    /opt/DBlog/blog-core/src/main/resources/config
    [root@localhost config]# ll
    total 12
    -rw-r--r--. 1 root root 855 May  1 23:44 application-center-dev.yml
    -rw-r--r--. 1 root root 855 May  1 23:44 application-center-test.yml
    -rw-r--r--. 1 root root 190 May  1 23:44 application-center.yml
    [root@localhost config]# vim application-center-dev.yml       #只需修改数据库的密码,redis的链接地址和密码即可
    [root@localhost config]# vim application-center-test.yml      #该文件和上面文件修改完全一样,只截一张图说明
    

     

    项目根目录下执行mvn -X clean package -Dmaven.test.skip=true -Ptest编译打包(注:-Ptest中的test为环境标识),然后cd到blog-web目录下执行java -jar target/blog-web.jar

    [root@localhost DBlog]# ll
    total 80
    drwxr-xr-x. 4 root root    64 May  2 01:08 blog-admin
    drwxr-xr-x. 4 root root    64 May  2 01:07 blog-core
    drwxr-xr-x. 4 root root    64 May  2 01:06 blog-file
    drwxr-xr-x. 4 root root    64 May  2 01:07 blog-web
    -rw-r--r--. 1 root root   138 May  1 23:44 build.sh
    -rw-r--r--. 1 root root  1341 May  1 23:44 contribution.md
    -rw-r--r--. 1 root root  1088 May  1 23:44 demo.md
    drwxr-xr-x. 4 root root    94 May  1 23:44 docs
    -rw-r--r--. 1 root root 35119 May  1 23:44 LICENSE
    -rw-r--r--. 1 root root  7064 May  1 23:44 pom.xml
    -rw-r--r--. 1 root root 10497 May  1 23:44 README.md
    -rw-r--r--. 1 root root  8962 May  1 23:44 update.md
    [root@localhost DBlog]# mvn -X clean package -Dmaven.test.skip=true -Ptest
    前面省略
    。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
    [DEBUG]   (f) outputDirectory = /opt/DBlog/blog-admin/target
    [DEBUG]   (f) project = MavenProject: com.zyd:blog-admin:2.2.1 @ /opt/DBlog/blog-admin/pom.xml
    [DEBUG]   (f) skip = false
    [DEBUG] -- end configuration --
    [INFO] Layout: JAR
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO]
    [INFO] blog ............................................... SUCCESS [  6.824 s]
    [INFO] blog-file .......................................... SUCCESS [ 53.569 s]
    [INFO] blog-core .......................................... SUCCESS [ 54.581 s]
    [INFO] blog-web ........................................... SUCCESS [ 27.854 s]
    [INFO] blog-admin ......................................... SUCCESS [  6.076 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 02:36 min
    [INFO] Finished at: 2019-05-02T01:08:16+08:00
    [INFO] Final Memory: 59M/212M
    [INFO] ------------------------------------------------------------------------
    

     开启项目的前端和后台

    [root@localhost DBlog]# cd blog-web/
    [root@localhost blog-web]# ls
    pom.xml  src  target
    [root@localhost blog-web]# ll
    total 4
    -rw-r--r--. 1 root root 1575 May  1 23:44 pom.xml
    drwxr-xr-x. 4 root root   30 May  1 23:44 src
    drwxr-xr-x. 6 root root  137 May  2 01:08 target 
    [root@localhost blog-web]# java -jar target/blog-web.jar  &     ###前端
    
    [root@localhost DBlog]# cd blog-admin/
    [root@localhost blog-admin]# ll
    total 4
    -rw-r--r--. 1 root root 1942 May  1 23:44 pom.xml
    drwxr-xr-x. 4 root root   30 May  1 23:44 src
    drwxr-xr-x. 6 root root  141 May  2 01:08 target
    [root@localhost blog-web]# java -jar target/blog-admin.jar &     ###后台
    

      测试环节:浏览器访问http://127.0.0.1:8443   这是前端

     浏览器检查:

           浏览器访问http://127.0.0.1:8443       这是后台

     

     浏览器检查(登录用户admin。密码123456)

     事实上,上面的命令仅能保证xshell不退出有效,一旦退出自动杀掉了进程,所以为了退出xhsell进程不杀死java进程,可以使用下面的命令。

    在主目录下使用下面两条命令,可以自定义访问端口,并且安全的放在后台
    nohup java -jar blog-web/target/blog-web.jar --server.port=8000  2>&1 &
    nohup java -jar blog-admin/target/blog-admin-2.2.1.jar  --server.port=8001  2>&1 &
    

    后话:当我们去点击无论是前端还是以后台时,服务器内部的日志信息会刷新,提示写入redis缓存当中,等等这些,大有搞头,小伙伴们有兴趣可以试试。

  • 相关阅读:
    剑指Offer:面试题17——合并两个排序的链表
    剑指Offer:面试题16——反转链表(java实现)
    剑指Offer:面试题15——链表中倒数第k个结点(java实现)
    Timer和TimerTask 定时器和定时任务
    Spring-WebSocket 教程
    单点登录原理与简单实现
    Python机器学习:泰坦尼克号获救预测一
    转 smarty学习笔记电子版整理
    转 nodejs socket.io初探
    html5新增的属性和废除的属性
  • 原文地址:https://www.cnblogs.com/nshgo/p/10800050.html
Copyright © 2020-2023  润新知