• 如何优雅的安装配置知识管理系统Xwiki


    XWiki是一个强大的Java开源的Wiki引擎。它支持一些受欢迎的特性如:

    • 内容管理(浏览/编辑/预览/保存)
    • 支持附件
    • 版本控制
    • 全文本搜索
    • 权限管理
    • 使用Hibernate进行数据存储
    • RSS输出与显示外部的RSS feeds
    • 多语言支持
    • 提供XML/RPC的API
    • WYSIWYG HTML编辑器
    • 导出为PDF
    • Groovy脚本支持等等

    前置条件

    环境要求

    • CentOS 7.6
    • Tomcat 9.0.31
    • Openjdk 1.8.0
    • Libreoffice
    • Mysql 5.7.28

    Tips:JDK必须使用openjdk,Oracle Jdk不兼容!

    关闭防火墙

    systemctl stop firewalld
    systemctl disable firewalld
    

    软件下载

    mkdir -p /opt/software
    cd /opt/software
    yum install wget -y
    
    wget http://download.mrlapulga.com/Linux/Xwiki/xwiki-platform-distribution-war-12.1.war
    wget http://download.mrlapulga.com/Linux/Xwiki/xwiki-platform-distribution-flavor-xip-12.1.xip
    wget http://download.mrlapulga.com/Linux/Xwiki/mysql-connector-java-5.1.47.jar
    
    wget http://download.mrlapulga.com/Linux/Mysql/software/generic/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
    wget https://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.31/bin/apache-tomcat-9.0.31.tar.gz
    wget http://download.mrlapulga.com/Linux/Nginx/source/nginx-1.16.1-installed-opt-dir.tar.gz
    

    安装基础环境

    安装Openjdk

    yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-headless.x86_64 -y
    

    安装office

    yum install libreoffice -y
    

    解压tomcat和mysql

    解压tomcat:

    cd /opt/software
    tar zxf apache-tomcat-9.0.31.tar.gz -C /opt
    mv /opt/apache-tomcat-9.0.31 /opt/tomcat9
    

    修改tomcat配置:

    vim /opt/tomcat9/conf/server.xml
    
    <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" 
                   URIEncoding="UTF-8" 
                   compression="on" 
                   compressionMinSize="2048" 
                   compressableMimeType="text/html,text/xml,text/css,text/javascript,application/x-javascript" />
    

    解压mysql:

    tar zxf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /opt
    ln -s /opt/mysql-5.7.28-linux-glibc2.12-x86_64 /opt/mysql
    

    配置mysql

    yum install libaio -y
    
    mkdir -p /data/mysql
    sed -i '46s#basedir=#basedir=/opt/mysql#' /opt/mysql/support-files/mysql.server
    sed -i '47s#datadir=#datadir=/data/mysql#' /opt/mysql/support-files/mysql.server
    cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
    chmod 755 /etc/init.d/mysqld
    groupadd mysql
    useradd -r -g mysql -s /bin/false mysql
    chown -R mysql.mysql /opt/mysql/
    chown -R mysql.mysql /data/
    ln -s /opt/mysql/bin/mysql /usr/bin/
    

    添加配置文件:

    cat >> /etc/my.cnf <<EOF
    [mysqld]
    datadir                             = /data/mysql
    basedir                             = /opt/mysql
    #tmpdir                              = /data/mysql/tmp_mysql
    port                                = 3306
    socket                              = /data/mysql/mysql.sock
    pid-file                            = /data/mysql/mysql.pid
    max_connections                     = 8000
    max_connect_errors                  = 100000
    max_user_connections                = 3000
    check_proxy_users                   = on
    mysql_native_password_proxy_users   = on
    local_infile                        = OFF
    symbolic-links                      = FALSE
    group_concat_max_len                = 4294967295
    max_join_size                       = 18446744073709551615
    max_execution_time                  = 20000
    lock_wait_timeout                   = 60
    autocommit                          = 1
    lower_case_table_names              = 1
    thread_cache_size                   = 64
    disabled_storage_engines            = "MyISAM,FEDERATED"
    character_set_server                = utf8mb4
    character-set-client-handshake      = FALSE
    collation_server                    = utf8mb4_general_ci
    init_connect                        = 'SET NAMES utf8mb4'
    transaction-isolation               = "READ-COMMITTED"
    skip_name_resolve                   = ON
    explicit_defaults_for_timestamp     = ON
    log_timestamps                      = SYSTEM
    local_infile                        = OFF
    event_scheduler                     = OFF
    query_cache_type                    = OFF
    query_cache_size                    = 0
    sql_mode                            = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO
    log_error                           = /data/mysql/mysql.err
    slow_query_log                      = ON
    slow_query_log_file                 = /data/mysql/slow.log
    long_query_time                     = 1
    general_log                         = OFF
    general_log_file                    = /data/mysql/general.log
    expire_logs_days                    = 99
    log-bin                             = /data/mysql/mysql-bin
    log-bin-index                       = /data/mysql/mysql-bin.index
    max_binlog_size                     = 500M
    binlog_format                       = mixed
    binlog_rows_query_log_events        = ON
    binlog_cache_size                   = 128k
    binlog_stmt_cache_size              = 128k
    log-bin-trust-function-creators     = 1
    max_binlog_cache_size               = 2G
    max_binlog_stmt_cache_size          = 2G
    relay_log                           = /data/mysql/relay
    relay_log_index                     = /data/mysql/relay.index
    max_relay_log_size                  = 500M
    relay_log_purge                     = ON
    relay_log_recovery                  = ON
    server_id                           = 1
    read_buffer_size                    = 1M
    read_rnd_buffer_size                = 2M
    sort_buffer_size                    = 64M
    join_buffer_size                    = 64M
    tmp_table_size                      = 64M
    max_allowed_packet                  = 128M
    max_heap_table_size                 = 64M
    connect_timeout                     = 43200
    wait_timeout                        = 43200
    back_log                            = 512
    interactive_timeout                 = 300
    net_read_timeout                    = 30
    net_write_timeout                   = 30
    skip_external_locking               = ON
    key_buffer_size                     = 16M
    bulk_insert_buffer_size             = 16M
    concurrent_insert                   = ALWAYS
    open_files_limit                    = 65000
    table_open_cache                    = 16000
    table_definition_cache              = 16000
    default_storage_engine              = InnoDB
    default_tmp_storage_engine          = InnoDB
    internal_tmp_disk_storage_engine    = InnoDB
    [client]
    socket                              = /data/mysql/mysql.sock
    default_character_set               = utf8mb4
    [mysql]
    default_character_set               = utf8mb4
    [ndatad default]
    TransactionDeadLockDetectionTimeOut = 20000
    EOF
    
     chown -R mysql.mysql /etc/my.cnf
    

    初始化:

    /opt/mysql/bin/mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/data/mysql
    

    修改密码:

    mysql_passwd=$(grep 'A temporary password is generated' /data/mysql/mysql.err |awk '{print $NF}')
    /etc/init.d/mysqld start
    /opt/mysql/bin/mysqladmin -uroot -p${mysql_passwd} password '123456'
    

    设置环境变量:

    echo "export PATH=$PATH:/opt/mysql/bin" | tee /etc/profile.d/mysql.sh
    source /etc/profile.d/mysql.sh
    

    安装Xwiki

    创建数据库及授予权限

    mysql -uroot -p'123456'
    mysql> create database xwiki default character set utf8mb4 collate utf8mb4_bin;
    mysql> grant all privileges on *.* to xwiki@127.0.0.1 identified by 'xwiki';
    mysql> flush privileges;
    

    安装xwiki

    rm -rf /opt/tomcat9/webapps/*
    mkdir -p /opt/tomcat9/webapps/xwiki
    cd /opt/software/
    unzip xwiki-platform-distribution-war-12.1.war -d /opt/tomcat9/webapps/xwiki/
    

    修改配置文件

    cd /opt/tomcat9/webapps/xwiki/WEB-INF/
    cp hibernate.cfg.xml{,.bak}
    cp xwiki.cfg{,.bak}
    cp xwiki.properties{,.bak}
    

    vim hibernate.cfg.xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD//EN"
      "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
    
        <property name="hibernate.show_sql">false</property>
        <property name="hibernate.use_outer_join">true</property>
        
        <property name="hibernate.jdbc.use_scrollable_resultset">false</property>
    
        <property name="hibernate.dbcp.defaultAutoCommit">false</property>
        <property name="hibernate.dbcp.maxTotal">50</property>
        <property name="hibernate.dbcp.maxIdle">5</property>
        <property name="hibernate.dbcp.maxWaitMillis">30000</property>
        <property name="hibernate.connection.provider_class">com.xpn.xwiki.store.DBCPConnectionProvider</property>
        
        <property name="hibernate.schema_update.unique_constraint_strategy">skip</property>
    
        <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1/xwiki?useSSL=false</property>
        <property name="hibernate.connection.username">xwiki</property>
        <property name="hibernate.connection.password">xwiki</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="hibernate.dbcp.poolPreparedStatements">true</property>
        <property name="hibernate.dbcp.maxOpenPreparedStatements">20</property>
    
        <property name="hibernate.connection.charSet">UTF-8</property>
        <property name="hibernate.connection.useUnicode">true</property>
        <property name="hibernate.connection.characterEncoding">utf8</property>
    
        <mapping resource="xwiki.hbm.xml"/>
        <mapping resource="feeds.hbm.xml"/>
        <mapping resource="instance.hbm.xml"/>
        <mapping resource="notification-filter-preferences.hbm.xml"/>
        <mapping resource="mailsender.hbm.xml"/>
        
      </session-factory>
    </hibernate-configuration>
    

    vim xwiki.cfg

    xwiki.encoding=UTF-8
    xwiki.section.edit=1
    xwiki.section.depth=2
    xwiki.backlinks=1
    xwiki.tags=1
    xwiki.store.migration=1
    xwiki.inactiveuser.allowedpages=
    xwiki.authentication.validationKey=totototototototototototototototo
    xwiki.authentication.encryptionKey=titititititititititititititititi
    xwiki.authentication.cookiedomains=
    xwiki.authentication.logoutpage=(/|/[^/]+/|/wiki/[^/]+/)logout/*
    xwiki.editcomment=1
    xwiki.editcomment.mandatory=0
    xwiki.defaultskin=flamingo
    xwiki.defaultbaseskin=flamingo
    xwiki.plugins=
      com.xpn.xwiki.monitor.api.MonitorPlugin,
      com.xpn.xwiki.plugin.skinx.JsSkinExtensionPlugin,
      com.xpn.xwiki.plugin.skinx.JsSkinFileExtensionPlugin,
      com.xpn.xwiki.plugin.skinx.JsResourceSkinExtensionPlugin,
      com.xpn.xwiki.plugin.skinx.CssSkinExtensionPlugin,
      com.xpn.xwiki.plugin.skinx.CssSkinFileExtensionPlugin,
      com.xpn.xwiki.plugin.skinx.CssResourceSkinExtensionPlugin,
      com.xpn.xwiki.plugin.skinx.LinkExtensionPlugin,
      com.xpn.xwiki.plugin.feed.FeedPlugin,
      com.xpn.xwiki.plugin.mail.MailPlugin,
      com.xpn.xwiki.plugin.packaging.PackagePlugin,
      com.xpn.xwiki.plugin.svg.SVGPlugin,
      com.xpn.xwiki.plugin.fileupload.FileUploadPlugin,
      com.xpn.xwiki.plugin.image.ImagePlugin,
      com.xpn.xwiki.plugin.diff.DiffPlugin,
      com.xpn.xwiki.plugin.rightsmanager.RightsManagerPlugin,
      com.xpn.xwiki.plugin.jodatime.JodaTimePlugin,
      com.xpn.xwiki.plugin.scheduler.SchedulerPlugin,
      com.xpn.xwiki.plugin.mailsender.MailSenderPlugin,
      com.xpn.xwiki.plugin.tag.TagPlugin,
      com.xpn.xwiki.plugin.zipexplorer.ZipExplorerPlugin
    xwiki.plugin.image.cache.capacity=30
    xwiki.stats.default=0
    

    vim xwiki.properties

    environment.permanentDirectory=/opt/xwiki/
    openoffice.autoStart=true
    openoffice.homePath=/usr/lib64/libreoffice
    extension.oldflavors=org.xwiki.enterprise:xwiki-enterprise-ui-mainwiki
    extension.oldflavors=org.xwiki.enterprise:xwiki-enterprise-ui-wiki
    extension.oldflavors=org.xwiki.manager:xwiki-manager-ui
    extension.oldflavors=org.xwiki.manager:xwiki-manager-wiki-administrator
    extension.oldflavors=org.xwiki.manager:xwiki-enterprise-manager-wiki-administrator
    extension.oldflavors=com.xpn.xwiki.products:xwiki-enterprise-manager-wiki-administrator
    extension.oldflavors=com.xpn.xwiki.products:xwiki-enterprise-wiki
    
    mkdir -p /opt/xwiki/extension/repository
    
    cd /opt/software
    unzip xwiki-platform-distribution-flavor-xip-12.1.xip -d /opt/xwiki/extension/repository/
    

    安装mysql驱动

    cp /opt/software/mysql-connector-java-5.1.47.jar /opt/tomcat9/webapps/xwiki/WEB-INF/lib/
    

    启动服务

    /opt/tomcat9/bin/startup.sh
    

    通过浏览器进行安装

    在浏览器输入地址:http://IP:8080/xwiki

    进行初始化:

    进行安装向导配置:

    创建管理员账号:

    安装flavor框架:

    安装完成:

    关闭向导:

    本地化配置:

    配置Nginx反向代理

    安装Nginx

    useradd nginx -s /usr/sbin/nologin
    cd /opt/software
    tar zxf nginx-1.16.1-installed-opt-dir.tar.gz -C /opt
    mkdir -p /opt/nginx/conf/conf.d
    

    创建配置文件

    vim /opt/nginx/conf/nginx.conf

    worker_processes  auto;
    worker_rlimit_nofile 65535;
    error_log  /opt/nginx/log/error.log warn;
    pid        /opt/nginx/nginx.pid;
    
    events {
        use epoll;
        worker_connections  8192;
    }
    
    http {
        include       /opt/nginx/conf/mime.types;
        default_type  application/octet-stream;
        client_max_body_size 5000M;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
        access_log  /opt/nginx/log/access.log  main;
        sendfile        on;
        tcp_nopush      on;
        tcp_nodelay     on;
        server_tokens   off;
        keepalive_timeout 3600;
        keepalive_requests   100000;
        client_header_timeout 180;
        client_body_timeout 180;
        reset_timedout_connection on;
        client_body_buffer_size 128m;
        proxy_connect_timeout   300s;
        proxy_send_timeout      900;
        proxy_read_timeout      900;
        proxy_buffers 4 128k;
        proxy_busy_buffers_size 256k;
        proxy_temp_file_write_size 256k;
        include /opt/nginx/conf/conf.d/*.conf;
    }
    

    vim /opt/nginx/conf/conf.d/xwiki.conf

    server {
        listen 80;
        server_name wiki.iuskye.com 192.168.1.235;
        rewrite ^ https://$server_name/xwiki$request_uri?permanent;
    }
    
    server {
        listen 443 ssl;
        server_name wiki.iuskye.com 192.168.1.235;
        ssl_certificate /opt/nginx/certs/certificate.pem;
        ssl_certificate_key /opt/nginx/certs/privatekey.pem;
        root  /opt/tomcat9/webapps/xwiki;
        access_log  /opt/nginx/log/access.log  main;
        error_log  /opt/nginx/log/error.log;
    
        location / {
            rewrite ^ $scheme://$server_name/xwiki$request_uri?permanent;
        }
    
        location ^~ /xwiki {
        proxy_pass http://127.0.0.1:8080/xwiki;
       }
    }
    

    启动Nginx

    /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
    

    开始体验wiki

    配置本地hosts

    打开Mac或者Windows的hosts文件,写入:

    192.168.1.235 wiki.iuskye.com
    

    保存!

    登录

    打开浏览器输入http://wiki.iuskye.com/xwiki

    输入创建的管理员账号进行登录:

    配置启停服务脚本

    启停状态检查脚本

    cd /opt
    vim xwiki-ctl
    
    #!/bin/bash
    # author: iuskye
    # email: iuskye@126.com
    
    check_info() {
    if [[ $2 == "0" ]];then
        echo -e "33[32m$1 is OK! 33[0m"
    elif [[ $2 == "1" ]];then
        echo -e "33[31m$1 is DOWN! 33[0m"
    fi
    }
    
    start_info() {
    echo -e "33[32mStart $1 ...33[0m"
    sleep 2
    }
    
    stop_info() {
    echo -e "33[31mStop $1 ...33[0m"
    sleep 2
    }
    
    status_info() {
    echo -e "33[36mCheck $1 Service ...33[0m"
    sleep 2
    }
    
    start_nginx() {
    start_info "Nginx"
    /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
    }
    
    start_mysql() {
    start_info "Mysql"
    /etc/init.d/mysqld start >/dev/null 2>&1
    }
    
    start_tomcat() {
    start_info "Tomcat"
    /opt/tomcat9/bin/startup.sh >/dev/null 2>&1
    }
    
    stop_nginx() {
    stop_info "Nginx"
    /opt/nginx/sbin/nginx -s stop
    nginx_code=$(ps -ef | grep nginx | grep -v grep >/dev/null 2>&1;echo $?)
    if [[ ${nginx_code} -eq 0 ]];then
        ps -ef | grep nginx | grep -v grep | awk -F' ' '{print $2}' | xargs kill -9 >/dev/null 2>&1
    fi
    }
    
    stop_mysql() {
    stop_info "Mysql"
    /etc/init.d/mysqld stop >/dev/null 2>&1
    mysql_code=$(ps -ef | grep mysqld | grep -v grep >/dev/null 2>&1;echo $?)
    if [[ ${mysql_code} -eq 0 ]];then
        ps -ef | grep mysqld | grep -v grep | awk -F' ' '{print $2}' | xargs kill -9 >/dev/null 2>&1
    fi
    }
    
    stop_tomcat() {
    stop_info "Tomcat"
    /opt/tomcat9/bin/shutdown.sh >/dev/null 2>&1
    sleep 3
    tomcat_code=$(ps -ef | grep tomcat | grep -v grep >/dev/null 2>&1;echo $?)
    if [[ ${tomcat_code} -eq 0 ]];then
        ps -ef | grep tomcat9 | grep -v grep | awk -F' ' '{print $2}' | xargs kill -9 >/dev/null 2>&1
    fi
    }
    
    status_nginx() {
    status_info "Nginx"
    local check_code=$(ps -C nginx --no-header >/dev/null 2>&1;echo $?)
    check_info "Nginx" "${check_code}"
    }
    
    status_mysql() {
    status_info "Mysql"
    local check_code=$(ps -ef | grep mysqld | grep -v grep >/dev/null 2>&1;echo $?)
    check_info "Mysql" "${check_code}"
    }
    
    status_tomcat() {
    status_info "Tomcat"
    local check_code=$(ps -ef | grep tomcat9 | grep -v grep >/dev/null 2>&1;echo $?)
    check_info "Tomcat" "${check_code}"
    }
    
    start() {
    if [[ $1 == "nginx" ]];then
        start_nginx
    fi
    if [[ $1 == "mysql" ]];then
        start_mysql
    fi
    if [[ $1 == "tomcat" ]];then
        start_tomcat
    fi
    if [[ $1 == "all" ]];then
        start_nginx
        sleep 1
        start_mysql
        sleep 1
        start_tomcat
    fi
    }
    
    stop() {
    if [[ $1 == "nginx" ]];then
        stop_nginx
    fi
    if [[ $1 == "mysql" ]];then
        stop_mysql
    fi
    if [[ $1 == "tomcat" ]];then
        stop_tomcat
    fi
    if [[ $1 == "all" ]];then
        stop_nginx
        sleep 1
        stop_mysql
        sleep 1
        stop_tomcat
    fi
    }
    
    status() {
    if [[ $1 == "nginx" ]];then
        status_nginx
    fi
    if [[ $1 == "mysql" ]];then
        status_mysql
    fi
    if [[ $1 == "tomcat" ]];then
        status_tomcat
    fi
    if [[ $1 == "all" ]];then
        status_nginx
        sleep 1
        status_mysql
        sleep 1
        status_tomcat
    fi
    }
    
    help_info() {
    echo "Usage: xwiki-ctl [start|stop|status] [nginx|mysql|tomcat|all]"
    echo
    echo "    xwiki-ctl start nginx      # start nginx service."
    echo "    xwiki-ctl start mysql      # start mysql service."
    echo "    xwiki-ctl start tomcat     # start tomcat service."
    echo "    xwiki-ctl start all        # start all service."
    echo "    xwiki-ctl stop nginx       # stop nginx service."
    echo "    xwiki-ctl stop mysql       # stop mysql service."
    echo "    xwiki-ctl stop tomcat      # stop tomcat service."
    echo "    xwiki-ctl stop all         # stop all service."
    echo "    xwiki-ctl status nginx     # check nginx service."
    echo "    xwiki-ctl status mysql     # check mysql service."
    echo "    xwiki-ctl status tomcat    # check tomcat service."
    echo "    xwiki-ctl status all       # check all service."
    }
    
    case $1 in
    start)
        start $2
        ;;
    stop)
        stop $2
        ;;
    status)
        status $2
        ;;
    -h|--help)
        help_info
        ;;
    *)
        if [[ -z $1 || -z $2 ]];then
            echo -e "33[31mxwiki-ctl --help or -h to show how to use.33[0m"
        fi
        ;;
    esac
    

    配置系统环境

    ln -s /opt/xwiki-ctl /usr/bin/xwiki-ctl
    

    配置开机自启

    chmod +x /etc/rc.d/rc.local
    echo "xwiki-ctl start all" | tee -a /etc/rc.d/rc.local
    
  • 相关阅读:
    HDU 2899 Strange fuction
    HDU 2899 Strange fuction
    HDU 2199 Can you solve this equation?
    HDU 2199 Can you solve this equation?
    Java实现 LeetCode 700 二叉搜索树中的搜索(遍历树)
    Java实现 LeetCode 700 二叉搜索树中的搜索(遍历树)
    Java实现 LeetCode 700 二叉搜索树中的搜索(遍历树)
    Java实现 LeetCode 699 掉落的方块(线段树?)
    Java实现 LeetCode 699 掉落的方块(线段树?)
    Java实现 LeetCode 699 掉落的方块(线段树?)
  • 原文地址:https://www.cnblogs.com/iuskye/p/xwiki-install.html
Copyright © 2020-2023  润新知