C/C++教程

Centos7安装halo博客

本文主要是介绍Centos7安装halo博客,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Centos7安装halo博客

halo配置

#=============================拉取配置文件=============================
# 创建工作目录
mkdir -p /home/halo

#===========================先创建数据库====================================
docker exec -it 容器名/容器id bash
mysql -uroot -pyangzaigang123
# 字符集(Character Set):utf8mb4
# 排序规则(Collate):utf8mb4_bin
create database halodb character set utf8mb4 collate utf8mb4_bin;

#============================使用的配置===================================== 
mkdir -p /home/halo/conf/
cat > /home/halo/conf/application.yaml << 'EOF'
server:
  port: 8090
  forward-headers-strategy: native
  error:
    include-message: always
spring:
  devtools:
    restart:
      eanbled: false
  mvc:
    pathmatch:
      use-suffix-pattern: true
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
  output:
    ansi:
      enabled: always
  datasource:
    type: com.zaxxer.hikari.HikariDataSource

    # H2 database configuration.
    # 修改为mysql存储
    #driver-class-name: org.h2.Driver
    #url: jdbc:h2:file:${halo.work-dir}/db/halo
    #username: admin
    #password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
    username: root
    password: yangzaigang123
  jpa:
    hibernate:
      ddl-auto: update
    open-in-view: false
  flyway:
    enabled: false
  servlet:
    multipart:
      max-file-size: 10240MB
      max-request-size: 10240MB
      resolve-lazily: true
  freemarker:
    suffix: .ftl
    settings:
      auto_import: /common/macro/global_macro.ftl as global
    template-loader-path:
      - file:///${halo.work-dir}/templates/
      - classpath:/templates/
    expose-spring-macro-helpers: false
management:
  endpoints:
    web:
      base-path: /api/admin/actuator
      exposure:
        include: [ 'httptrace', 'metrics', 'env', 'logfile', 'health' ]
logging:
  level:
    run.halo.app: INFO
    org.eclipse.jetty.server.HttpChannel: ERROR
  file:
    path: ${halo.work-dir}/logs

springfox:
  documentation:
    enabled: false

halo:
  download-timeout: 5m
  cache: memory
  work-dir: ${user.home}/.halo/
EOF

#==========================启动服务====================================================
docker rm -f halo
docker run -it -d \
--name halo \
-p 8090:8090 \
--restart=always \
--privileged=true \
-v /home/halo/conf/application.yaml:/application/BOOT-INF/classes/application.yaml
halohub/halo:latest

#=============================nginx反向代理==============================================
upstream halo {
  server 127.0.0.1:8090;
}
server {
  listen 80;
  listen [::]:80;
  #server_name www.youdomain.com;

  location / {
    proxy_pass http://halo;
    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

mysql配置

#====================下载镜像================================
docker pull mysql:5.7.34

#================复制配置文件到宿主机,主从都适用=================
docker rm -f mysql5.7
docker run -d --name mysql5.7 --net host -e MYSQL_ROOT_PASSWORD=yangzaigang123 mysql:5.7.34

#docker exec -it mysql5.7_master /bin/bash

mkdir -p /home/mysql/conf
mkdir -p /home/mysql/log
mkdir -p /home/mysql/data
rm -rf /home/mysql/conf/*
rm -rf /home/mysql/log/* 
rm -rf /home/mysql/data/*

# 复制配置文件到宿主机
docker cp mysql5.7:/etc/mysql /home/mysql/conf 
docker cp mysql5.7:/var/log /home/mysql/log 
docker cp mysql5.7:/var/lib /home/mysql/data

#======================宿主机=======================
# 查看挂载目录
[root@yangzaigang mysql]# ll
total 16
drwxr-xr-x 2 root root 4096 Apr 20 02:57 conf.d
lrwxrwxrwx 1 root root   24 Apr 20 02:57 my.cnf -> /etc/alternatives/my.cnf
-rw-r--r-- 1 root root  839 Aug  3  2016 my.cnf.fallback
-rw-r--r-- 1 root root 1200 Mar 26 15:10 mysql.cnf
drwxr-xr-x 2 root root 4096 Apr 20 02:57 mysql.conf.d
# 宿主机
[root@yangzaigang mysql]# ll /etc/alternatives/my.cnf
-rw-r--r-- 1 root root 0 May 11 16:22 /etc/alternatives/my.cnf

#====================容器内==============================
root@b28cf0d21007:/etc/mysql# ls -l
total 16
drwxr-xr-x 2 root root 4096 Apr 19 18:57 conf.d
lrwxrwxrwx 1 root root   24 Apr 19 18:57 my.cnf -> /etc/alternatives/my.cnf
-rw-r--r-- 1 root root  839 Aug  3  2016 my.cnf.fallback
-rw-r--r-- 1 root root 1200 Mar 26 07:10 mysql.cnf
drwxr-xr-x 2 root root 4096 Apr 19 18:57 mysql.conf.d

root@b28cf0d21007:/etc/mysql# ls -l /etc/alternatives/my.cnf
lrwxrwxrwx 1 root root 20 Apr 19 18:57 /etc/alternatives/my.cnf -> /etc/mysql/mysql.cnf

#======================宿主机=======================
rm -rf /etc/alternatives/my.cnf
#vi cat tee 登向my.cnf写入内容,就会产生/etc/alternatives/my.cnf 这个文件

# 删除容器
docker rm -f mysql5.7_master  

#====================主=============================
# 清空配置文件,别删除这个配置文件
> /home/mysql/conf/mysql/my.cnf 
#============
cat > /home/mysql/conf/mysql/mysql.cnf << 'EOF'
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8mb4 
collation-server=utf8mb4_general_ci
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
EOF
#==============
cat > /home/mysql/conf/mysql/mysql.conf.d/mysqld.cnf << 'EOF'
[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
datadir		= /var/lib/mysql
#log-error	= /var/log/mysql/error.log
symbolic-links=0
bind-address = 0.0.0.0
#server-id=5
#log-bin=mysql-bin
#binlog-ignore-db = mysql
#binlog_ignore_db = information_schema
#binlog_ignore_db = performation_schema
#binlog_ignore_db = sys
EOF

cat /home/mysql/conf/mysql/mysql.conf.d/mysqld.cnf


docker rm -f mysql5.7_master
docker run -d \
--name mysql5.7_master \
--net=host \
-e MYSQL_ROOT_PASSWORD=yangzaigang123 \
-v /home/mysql/conf/mysql:/etc/mysql \
-v /home/mysql/log/mysql:/var/log/mysql \
-v /home/mysql/data/mysql:/var/lib/mysql \
mysql:5.7 \
--lower_case_table_names=1

docker-compose

cat > /root/docker-compose.yml << 'EOF'
version: "3.8"
services:
  mysql:
    image: mysql:5.7.34
    container_name: mysql5.7
    network_mode: host
    restart: always
    privileged: true
    environment:
      - MYSQL_ROOT_PASSWORD=yangzaigang123
      - TZ=Asia/shanghai
    volumes:
      - /home/mysql/conf/mysql:/etc/mysql
      - /home/mysql/log/mysql:/var/log/mysql
      - /home/mysql/data/mysql:/var/lib/mysql
    command: 
      --default-authentication-plugin=mysql_native_password
      --lower_case_table_names=1 
      
  halo:  
    image: halohub/halo:latest
    container_name: halo
    network_mode: host
    restart: always
    privileged: true
    depends_on:
      - mysql
    environment:
      - TZ=Asia/shanghai
    volumes:
      - /home/halo/conf/application.yaml:/application/BOOT-INF/classes/application.yaml
EOF
chmod +x /root/docker-compose.yml 
docker-compose stop && docker-compose rm -f 
docker-compose up -d && docker-compose logs -f --tail=500
这篇关于Centos7安装halo博客的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!