• 第三章 Mccann-DBH生产环境部署


    一、系统优化

    # 编写系统优化脚本
    [ec2-user@172-31-10-33 ~]$ sudo su -
    [root@172-31-10-33 ~]$ vi linux_opt.sh
    #!/usr/bin/bash
    # Author:jh
    # Time:2020-12-11  09:03:19
    # Name:linux_opt.sh
    # Version: 1.0
    # Discription: To  
    
    local_IP=`ifconfig |awk -F ' ' 'NR==2{print $2}'`
    local_hostname=`hostname`
    base_yum="CentOS-Base.repo"
    epel_yum="epel.repo"
    yum_dir="/etc/yum.repos.d/"
    cron_dir="/var/spool/cron/root"
    ssh_dir="/etc/ssh/sshd_config"
    
    linux_comm_software=(net-tools vim tree htop iftop gcc gcc-c++ glibc iotop lrzsz sl wget unzip telnet nmap nc psmisc dos2unix bash-completion bash-completion-extra sysstat rsync nfs-utils httpd-tools expect ntpdate)
    
    #1.修改主机名
    source /etc/init.d/functions
    if [ $# -ne 1 ];then
        echo "/bin/sh $0 New hostname"
        exit 1
    fi
    
    hostnamectl set-hostname $1
    if [ $? -eq 0 ];then
        action "hostname update is" /usr/bin/true
    else
        action "hostname update is" /usr/bin/false
    fi
    
    #2.配置ssh连接成功显示
    platform=`uname -i`
    if [ $platform != "x86_64" ];then 
        echo "this script is only for 64bit Operating System !"
        exit 1
    fi
    echo "the platform is ok"
    cat << EOF
    +---------------------------------------+
    | your system is CentOS 7 x86_64 |
    | start optimizing....... |
    +---------------------------------------
    EOF
    
    #3.配置yum仓库
    mv $yum_dir$base_yum  $yum_dir${base_yum}.bak
    mv $yum_dir$epel_yum  $yum_dir${epel_yum}.bak
    curl -o $yum_dir$base_yum http://mirrors.aliyun.com/repo/Centos-7.repo
    curl -o $yum_dir$epel_yum http://mirrors.aliyun.com/repo/epel-7.repo
    yum clean all
    yum makecache
    
    #4.安装基础软件包
    for i in ${linux_comm_software[*]}
    do
        rpm -q $i &>/dev/null
        if [ $? -eq 0 ];then
            echo "$i is installed" 
        else
            yum -y install $i  &>/dev/null                                     
            action "$i is installing"  /usr/bin/true
        fi     
    done
    
    #5.关闭防火墙firewalld
    #systemctl disable firewalld
    #systemctl stop firewalld
    
    #6.关闭selinux
    #sed 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
    
    #7.修改本地解析
    echo "$local_IP $local_hostname" >> /etc/hosts
    
    #8.设置时间同步
    timedatectl set-timezone Asia/Shanghai
    /usr/sbin/ntpdate time1.aliyun.com
    echo '#Timing synchronization time' >> $cron_dir
    echo "* 4 * * * /usr/sbin/ntpdate time1.aliyun.com > /dev/null 2>&1" >> $cron_dir
    systemctl restart crond.service
    
    #9.ssh参数优化
    #sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/g' $ssh_dir
    #sed -i 's/#UseDNS yes/UseDNS no/g' $ssh_dir
    #sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' $ssh_dir
    #sed -i 's/#port 22/poort 520/g' $ssh_dir
    
    #10.加大文件描述符
    tail -1 /etc/security/limits.conf &>/dev/null
    [ $? -eq 0 ] && echo "文件描述符以加大" || echo '*               -       nofile          65535 ' >>/etc/security/limits.conf 
    
    #11.环境变量及别名优化
    cat>>/etc/profile.d/color.sh<<EOF
    alias ll='ls -l --color=auto --time-style=long-iso'
    PS1="[e[37;40m][[e[32;1m]u[e[37;40m]@h [e[36;40m]w[e[0m]][e[32;1m]\$ [e[0m]"
    export HISTTIMEFORMAT='%F-%T '
    EOF
    
    source  /etc/profile
    
    #12.内核优化
    cat >>/etc/sysctl.conf<<EOF
    net.ipv4.tcp_fin_timeout = 2
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_keepalive_time = 600
    net.ipv4.ip_local_port_range = 4000    65000
    net.ipv4.tcp_max_syn_backlog = 16384
    net.ipv4.tcp_max_tw_buckets = 36000
    net.ipv4.route.gc_timeout = 100
    net.ipv4.tcp_syn_retries = 1
    net.ipv4.tcp_synack_retries = 1
    net.core.somaxconn = 16384
    net.core.netdev_max_backlog = 16384
    net.ipv4.tcp_max_orphans = 16384
    net.ipv4.ip_forward = 1
    net.ipv4.icmp_echo_ignore_all=1
    EOF
    
    sysctl  -p
    
    #13.关闭NetworkManager
    #systemctl  stop  NetworkManager
    #systemctl  disable  NetworkManager
    
    #14.更新软件
    yum -y update && > /dev/null
    
    #15.设置中文字符集
    localectl set-locale LANG=zh_CN.UTF-8
    
    #16.备份显示系统版本和内核的文件
    cp /etc/issue{,.bak}
    cp /etc/issue.net{,.bak}
    
    > /etc/issue
    > /etc/issue.net
    
    #17.优化完成    
    cat << EOF
    +-------------------------------------------------+
    | 优 化 已 完 成                                  |
    | 请 重启 这台服务器 !                            |
    +-------------------------------------------------+
    EOF
    
    sleep 5
    
    # 添加执行权限
    [root@172-31-10-33 ~]$ chmod +x linux_opt.sh
    
    # 执行脚本
    [root@172-31-10-33 ~]$ sh linux_opt.sh mccann-dbh
    
    
    [root@mccann-dbh ~]$
    

    二、JDK安装

    JDK官网下载:https://www.oracle.com
    

    1.创建软件存放目录

    [root@mccann-dbh  ~]# mkdir /data/software/
    [root@mccann-dbh  ~]# cd /data/software/
    

    2.上传JDK安装包

    [root@mccann-dbh  /data/software]# rz
    [root@mccann-dbh  /data/software]# ll
    total 206884
    -rw-r--r--. 1 root root 185540433 2021-07-12 09:42 jdk-8u131-linux-x64.tar.gz
    

    3.解压安装包

    [root@mccann-dbh  /data/software]# tar xf jdk-8u131-linux-x64.tar.gz  -C /opt
    [root@mccann-dbh  /data/software]# cd /opt/
    [root@hadooop100 ~]# ll
    total 0
    drwxr-xr-x. 8   10  143 255 2021-03-15 16:35 jdk1.8.0_131
    

    4.做软连接

    [root@hadooop100 ~]# ln -s jdk1.8.0_131 jdk
    [root@hadooop100 ~]# ll
    total 0
    lrwxrwxrwx. 1 root root  12 2021-07-12 09:43 jdk -> jdk1.8.0_131
    drwxr-xr-x. 8   10  143 255 2021-03-15 16:35 jdk1.8.0_131
    

    5.配置环境变量

    [root@hadooop100 ~]# vim /etc/profile.d/java.sh 
    export JAVA_HOME=/opt/jdk
    export PATH=$PATH:$JAVA_HOME/bin  
    

    6.刷新环境变量

    [root@hadooop100 ~]# source /etc/profile.d/java.sh 
    

    7.验证JDK

    [root@mccann-dbh  /opt]# java -versionjava version "1.8.0_131"Java(TM) SE Runtime Environment (build 1.8.0_131-b11)Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
    

    三、Mysql-8.0.24安装

    1.安装依赖

    # MySQL依赖于libaio库
    [root@mccann-dbh ~]$ yum search libaio
    [root@mccann-dbh ~]$ yum install libaio -y
    

    2.下载Mysql新版本

    [root@mccann-dbh ~]$ cd /data/software
    [root@mccann-dbh /data/software]$ wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz
    

    3.新建用户和用户组

    # 不指定用户组时,默认生成一个同名用户组并加入 -r,指定为系统用户 -s,指定登录shell
    [root@mccann-dbh /data/software]$ groupadd mysql
    [root@mccann-dbh /data/software]$ useradd -r -g mysql -s /bin/false mysql
    

    4.解压Mysql安装包

    [root@mccann-dbh /usr/local]$ mv mysql-8.0.24-linux-glibc2.12-x86_64  mysql# 解压安装包到/usr/local目录下
    [root@mccann-dbh /data/software]$ tar -xvf mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz  -C /usr/local
    
    # 进入/usr/local目录
    [root@mccann-dbh /data/software]$ cd /usr/local/
    
    # 查看安装包
    [root@mccann-dbh /usr/local]$ ll
    总用量 8
    drwxr-xr-x. 9 root root 129 2021-09-02 17:04 mysql-8.0.24-linux-glibc2.12-x86_64
    
    # 重命名
    [root@mccann-dbh /usr/local]$ mv mysql-8.0.24-linux-glibc2.12-x86_64  mysql
    

    5.新建Mysql存放目录

    # Mysql配置文件目录[root@mccann-dbh /usr/local]$ mkdir /usr/local/mysql/etc -p# Mysql数据目录[root@mccann-dbh /usr/local]$ mkdir /usr/local/mysql/data -pps:数据目录不需要建立,配置文件指定时会自动创建数据目录。# Mysql日志目录[root@mccann-dbh /usr/local]$ mkdir /usr/local/mysql/log -p# 授权目录用户[root@mccann-dbh /usr/local]$ chown -R mysql:mysql /usr/local/mysql
    

    6.配置mysql配置文件

    [root@mccann-dbh /usr/local]$ cd /usr/local/mysql/etc/
    
    [root@mccann-dbh /usr/local/mysql/etc]$ vim my.cnf
    [client]
    port    = 3306
    socket = /usr/local/mysql/data/mysql.sock
    
    [mysql]
    prompt="u@h R:m:s [d]> "
    no-auto-rehash
    
    [mysqld]
    user    = mysql
    port    = 3306
    admin_address = 127.0.0.1
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    socket    = /usr/local/mysql/data/mysql.sock
    pid-file = /usr/local/mysql/data/mysqld.pid
    character-set-server = utf8mb4
    skip_name_resolve = 1
    #这个就是用之前的身份认证插件
    default-authentication-plugin = mysql_native_password
    #保证日志的时间正确
    log_timestamps = SYSTEM
    
    #replicate-wild-ignore-table=mysql.%
    replicate-wild-ignore-table=test.%
    replicate-wild-ignore-table=information_schema.%
    
    # Two-Master configure
    #server-1
    #auto-increment-offset = 1
    #auto-increment-increment = 2
    
    #server-2
    #auto-increment-offset = 2
    #auto-increment-increment = 2
    
    sql_mode=NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO
    
    # semi sync replication settings #
    #plugin_dir = /usr/local/mysql/lib/mysql/plugin
    #plugin_load = "validate_password.so;rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
    plugin_dir =/usr/local/mysql/lib/plugin #官方版本的路径
    plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" #官方版本的路径
    
    slave_parallel_workers = 4
    slave_parallel_type = LOGICAL_CLOCK
    
    open_files_limit    = 65535
    back_log = 1024
    max_connections = 1024
    max_connect_errors = 1000000
    table_open_cache = 1024
    table_definition_cache = 1024
    table_open_cache_instances = 64
    thread_stack = 512K
    external-locking = FALSE
    max_allowed_packet = 32M
    sort_buffer_size = 4M
    join_buffer_size = 4M
    thread_cache_size = 1536
    interactive_timeout = 600
    wait_timeout = 600
    tmp_table_size = 32M
    max_heap_table_size = 32M
    slow_query_log = 1
    log_timestamps = SYSTEM
    slow_query_log_file = /usr/local/mysql/log/slow.log
    log-error = /usr/local/mysql/log/error.log
    long_query_time = 0.1
    log_queries_not_using_indexes =1
    log_throttle_queries_not_using_indexes = 60
    min_examined_row_limit = 100
    log_slow_admin_statements = 1
    log_slow_slave_statements = 1
    server-id = 3306
    log-bin = mysql-bin
    sync_binlog = 1
    binlog_cache_size = 4M
    max_binlog_cache_size = 2G
    max_binlog_size = 1G
    binlog_expire_logs_seconds=2592000
    master_info_repository = TABLE
    relay_log_info_repository = TABLE
    gtid_mode = on
    enforce_gtid_consistency = 1
    log_slave_updates
    slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
    binlog_format = row
    binlog_row_image=FULL
    binlog_checksum = 1
    relay_log_recovery = 1
    relay-log-purge = 1
    key_buffer_size = 32M
    read_buffer_size = 8M
    read_rnd_buffer_size = 4M
    bulk_insert_buffer_size = 64M
    myisam_sort_buffer_size = 128M
    myisam_max_sort_file_size = 10G
    myisam_repair_threads = 1
    lock_wait_timeout = 3600
    explicit_defaults_for_timestamp = 1
    innodb_thread_concurrency = 0
    innodb_sync_spin_loops = 100
    innodb_spin_wait_delay = 30
    
    #transaction_isolation = REPEATABLE-READ
    transaction_isolation = READ-COMMITTED
    #innodb_additional_mem_pool_size = 16M
    innodb_buffer_pool_size = 2867M
    innodb_buffer_pool_instances = 4
    innodb_buffer_pool_load_at_startup = 1
    innodb_buffer_pool_dump_at_shutdown = 1
    innodb_data_file_path = ibdata1:1G:autoextend
    innodb_flush_log_at_trx_commit = 1
    innodb_log_buffer_size = 32M
    innodb_log_file_size = 2G
    innodb_log_files_in_group = 3
    innodb_max_undo_log_size = 4G
    # innodb_undo_directory = /usr/local/mysql/log/undolog
    innodb_undo_tablespaces = 95
    
    # 根据您的服务器IOPS能力适当调整
    # 一般配普通SSD盘的话,可以调整到 10000 - 20000
    # 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
    innodb_io_capacity = 4000
    innodb_io_capacity_max = 8000
    innodb_flush_sync = 0
    innodb_flush_neighbors = 0
    innodb_write_io_threads = 8
    innodb_read_io_threads = 8
    innodb_purge_threads = 4
    innodb_page_cleaners = 4
    innodb_open_files = 65535
    innodb_max_dirty_pages_pct = 50
    innodb_flush_method = O_DIRECT
    innodb_lru_scan_depth = 4000
    innodb_checksum_algorithm = crc32
    innodb_lock_wait_timeout = 10
    innodb_rollback_on_timeout = 1
    innodb_print_all_deadlocks = 1
    innodb_file_per_table = 1
    innodb_online_alter_log_max_size = 4G
    innodb_stats_on_metadata = 0
    
    # some var for MySQL 8
    log_error_verbosity = 3
    innodb_print_ddl_logs = 1
    binlog_expire_logs_seconds = 2592000
    #innodb_dedicated_server = 0
    
    innodb_status_file = 1
    # 注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快
    innodb_status_output = 0
    innodb_status_output_locks = 0
    
    #performance_schema
    performance_schema = 1
    performance_schema_instrument = '%memory%=on'
    performance_schema_instrument = '%lock%=on'
    
    #innodb monitor
    innodb_monitor_enable="module_innodb"
    innodb_monitor_enable="module_server"
    innodb_monitor_enable="module_dml"
    innodb_monitor_enable="module_ddl"
    innodb_monitor_enable="module_trx"
    innodb_monitor_enable="module_os"
    innodb_monitor_enable="module_purge"
    innodb_monitor_enable="module_log"
    innodb_monitor_enable="module_lock"
    innodb_monitor_enable="module_buffer"
    innodb_monitor_enable="module_index"
    innodb_monitor_enable="module_ibuf_system"
    innodb_monitor_enable="module_buffer_page"
    innodb_monitor_enable="module_adaptive_hash"
    #validate_password_policy=LOW
    
    [mysqldump]
    quick
    max_allowed_packet = 32M
    
    [mysqld_safe]
    #malloc-lib=/usr/local/mysql/lib/jmalloc.so
    nice=-19
    open-files-limit=65535
    

    7.初始化数据库

    [root@mccann-dbh /usr/local/mysql/etc]$ cd /usr/local/mysql/bin/
    [root@mccann-dbh /usr/local/mysql/bin]$ ./mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    

    8.启动数据库

    #1.配置system启动
    [root@mccann-dbh /usr/local/mysql/bin]$ vim /usr/lib/systemd/system/mysqld.service
    [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=/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf
    LimitNOFILE = 5000
    #Restart=on-failure
    #RestartPreventExitStatus=1
    #PrivateTmp=false
    
    #2.重新加载启动文件列表
    [root@dxg-ml bin]# systemctl daemon-reload
    
    #3.启动数据库
    [root@mccann-dbh /usr/local/mysql/bin]$ systemctl start mysqld.service 
    
    #4.查看数据库状态
    [root@mccann-dbh /usr/local/mysql/bin]$ systemctl status mysqld.service
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
       Active: active (running) since Thu 2021-09-02 17:31:43 CST; 23s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
     Main PID: 18405 (mysqld_safe)
       CGroup: /system.slice/mysqld.service
               ├─18405 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf
               └─20037 /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/lo...
    
    Sep 02 17:31:43 mccann-dbh systemd[1]: Started MySQL Server.
    Sep 02 17:31:43 mccann-dbh mysqld_safe[18405]: 2021-09-02T09:31:43.946861Z mysqld_safe Logging to '/usr/local/mysql/log/error.log'.
    Sep 02 17:31:43 mccann-dbh mysqld_safe[18405]: 2021-09-02T09:31:43.970580Z mysqld_safe Starting mysqld daemon with databases fro...ql/data
    Hint: Some lines were ellipsized, use -l to show in full.
    
    #5.验证服务状态
    [root@mccann-dbh /usr/local/mysql/bin]$ ps -ef |grep 3306
    mysql    20037 18405  0 17:31 ?        00:00:01 /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/log/error.log --open-files-limit=65535 --pid-file=/usr/local/mysql/data/mysqld.pid --socket=/usr/local/mysql/data/mysql.sock --port=3306
    root     20109 17631  0 17:34 pts/2    00:00:00 grep --color=auto 3306
    
    [root@mccann-dbh /usr/local/mysql/bin]$ netstat  -lntp |grep 3306
    tcp        0      0 127.0.0.1:33062         0.0.0.0:*               LISTEN      20037/mysqld        
    tcp6       0      0 :::33060                :::*                    LISTEN      20037/mysqld        
    tcp6       0      0 :::3306                 :::*                    LISTEN      20037/mysqld   
    

    9.配置环境变量

    #配置环境变量
    [root@mccann-dbh /usr/local/mysql/bin]$ cat /etc/profile.d/mysqld.sh 
    PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
    
    #重载环境变量
    [root@mccann-dbh /usr/local/mysql/bin]$ source  /etc/profile
    

    10.登录数据库

    #1.登录并配置远程登录
    [root@mccann-dbh ~]$ mysql -P 3306 -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 10
    Server version: 8.0.24
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    root@localhost 17:39:  [(none)]> 
    
    #2.查看数据库提示你必须重置你的密码
    root@localhost 17:39:  [(none)]> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    
    #3.修改数据库密码
    root@localhost 17:44:  [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY '**********';
    Query OK, 0 rows affected (0.00 sec)
    
    #4.再次查看数据库
    root@localhost 17:45:  [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.00 sec)
    
    #5.使用数据库
    root@localhost 17:46:  [(none)]> use mysql;
    Database changed
    
    #6.创建一个远程用户登录
    root@localhost 17:46:  [mysql]> create user 'root'@'%' identified by '*********';
    Query OK, 0 rows affected (0.01 sec)
    
    root@localhost 17:47:  [mysql]>  grant all privileges on *.* to 'root'@'%' with grant option;
    Query OK, 0 rows affected (0.00 sec)
    
    root@localhost 17:47:  [mysql]> select host, user, authentication_string, plugin from user;
    +-----------+------------------+------------------------------------------------------------------------+-----------------------+
    | host      | user             | authentication_string                                                  | plugin                |
    +-----------+------------------+------------------------------------------------------------------------+-----------------------+
    | %         | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B                              | mysql_native_password |
    | localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
    | localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
    | localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
    | localhost | root             | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B                              | mysql_native_password |
    +-----------+------------------+------------------------------------------------------------------------+-----------------------+
    5 rows in set (0.00 sec)
    
    #退出数据库
    root@localhost 17:47:  [mysql]> quit
    Bye
    

    四、迁移数据库目录

    1.停止数据库

    #1.停止数据库
    [root@mccann-dbh ~]$ systemctl stop  mysqld.service 
    
    #2.查看数据库状态
    [root@mccann-dbh ~]$ systemctl status  mysqld.service 
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
       Active: inactive (dead)
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
    
    Sep 02 17:31:43 mccann-dbh systemd[1]: Started MySQL Server.
    Sep 02 17:31:43 mccann-dbh mysqld_safe[18405]: 2021-09-02T09:31:43.946861Z mysqld_safe Logging to '/usr/local/mysql/log/error.log'.
    Sep 02 17:31:43 mccann-dbh mysqld_safe[18405]: 2021-09-02T09:31:43.970580Z mysqld_safe Starting mysqld daemon with databases fro...ql/data
    Sep 02 17:50:41 mccann-dbh systemd[1]: Stopping MySQL Server...
    Sep 02 17:50:42 mccann-dbh systemd[1]: Stopped MySQL Server.
    Hint: Some lines were ellipsized, use -l to show in full.
    

    2.新建数据库存放目录

    [root@mccann-dbh ~]$ mkdir /data/mysql-8.0.24
    [root@mccann-dbh ~]$ cd /data/mysql-8.0.24/
    

    3.移动相关数据目录

    [root@mccann-dbh /data/mysql-8.0.24]$ mv /usr/local/mysql/data ./
    [root@mccann-dbh /data/mysql-8.0.24]$ mv /usr/local/mysql/etc ./
    [root@mccann-dbh /data/mysql-8.0.24]$ mv /usr/local/mysql/log ./
    

    4.配置数据库软连接

    #1.做软连接
    [root@mccann-dbh /data/mysql-8.0.24]$ ln -s /data/mysql-8.0.24/data /usr/local/mysql/
    [root@mccann-dbh /data/mysql-8.0.24]$ ln -s /data/mysql-8.0.24/log /usr/local/mysql/
    [root@mccann-dbh /data/mysql-8.0.24]$ ln -s /data/mysql-8.0.24/etc /usr/local/mysql/
    
    #2.查看相关软连接
    [root@mccann-dbh /data/mysql-8.0.24]$ cd /usr/local/mysql/
    [root@mccann-dbh /usr/local/mysql]$ ll
    total 284
    drwxr-xr-x.  2 mysql mysql   4096 2021-03-26 03:42 bin
    lrwxrwxrwx.  1 root  root      23 2021-09-02 17:54 data -> /data/mysql-8.0.24/data
    drwxr-xr-x.  2 mysql mysql     55 2021-03-26 03:42 docs
    lrwxrwxrwx.  1 root  root      22 2021-09-02 17:54 etc -> /data/mysql-8.0.24/etc
    drwxr-xr-x.  3 mysql mysql    282 2021-03-26 03:42 include
    drwxr-xr-x.  6 mysql mysql    201 2021-03-26 03:42 lib
    -rw-r--r--.  1 mysql mysql 274942 2021-03-22 16:44 LICENSE
    lrwxrwxrwx.  1 root  root      22 2021-09-02 17:54 log -> /data/mysql-8.0.24/log
    drwxr-xr-x.  4 mysql mysql     30 2021-03-26 03:42 man
    -rw-r--r--.  1 mysql mysql    666 2021-03-22 16:44 README
    drwxr-xr-x. 28 mysql mysql   4096 2021-03-26 03:42 share
    drwxr-xr-x.  2 mysql mysql     77 2021-03-26 03:42 support-files
    
    

    5.重启服务

    #1.重启服务
    [root@mccann-dbh /usr/local/mysql]$ systemctl  start mysqld.service 
    
    #2.查看服务状态
    [root@mccann-dbh /usr/local/mysql]$ systemctl  status mysqld.service 
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
       Active: active (running) since Thu 2021-09-02 17:55:42 CST; 5s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
     Main PID: 20316 (mysqld_safe)
       CGroup: /system.slice/mysqld.service
               ├─20316 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf
               └─21948 /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/lo...
    
    Sep 02 17:55:42 mccann-dbh systemd[1]: Started MySQL Server.
    Sep 02 17:55:43 mccann-dbh mysqld_safe[20316]: 2021-09-02T09:55:43.181022Z mysqld_safe Logging to '/usr/local/mysql/log/error.log'.
    Sep 02 17:55:43 mccann-dbh mysqld_safe[20316]: 2021-09-02T09:55:43.203721Z mysqld_safe Starting mysqld daemon with databases fro...ql/data
    Hint: Some lines were ellipsized, use -l to show in full.
    

    6.登录数据库

    [root@mccann-dbh ~]$ mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 8
    Server version: 8.0.24 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    root@localhost 17:56:  [(none)]> 
    root@localhost 17:56:  [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    +--------------------+
    4 rows in set (0.01 sec)
    
    root@localhost 17:56:  [(none)]> quit
    Bye
    

    五、Nginx安装

    1.安装Nginx

    1.编写nginx安装脚本
    [root@mccann-dbh ~]$ vim Ins_Nginx.sh 
    #!/usr/bin/bash
    # Author:jh
    # Time:2020-12-11  18:59:53
    # Name:nginx_guanfang_ins.sh
    # Version: 1.0
    # Discription: To  
    
    #1.配置nginx官方源
    cat >/etc/yum.repos.d/nginx.repo<<'EOF'
    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    EOF
    
    #2.安装依赖
    yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
    
    #3.安装nginx
    yum install -y nginx
    
    #5.启动服务
    systemctl --now enable nginx
    
    #6.查看版本号
    nginx -v
    
    #7.验证服务
    curl 127.0.0.1:80
    
    rm -rf ./Ins_Nginx.sh
    
    2.添加执行权限
    [root@mccann-dbh ~]$ chmod +x Ins_Nginx.sh
    
    3.运行脚本
    [root@mccann-dbh ~]$ sh Ins_Nginx.sh
    
    4.修改nginx配置文件
    [root@mccann-dbh ~]$ cd /etc/nginx/
    [root@mccann-dbh /etc/nginx]$ vim nginx.conf 
    user root;
    worker_processes auto;
    worker_cpu_affinity auto;
    error_log /var/log/nginx/error.log warn;
    pid /run/nginx.pid;
    worker_rlimit_nofile 35535;
    
    events {
        use epoll;    
        worker_connections 10240;
    }
    
    http {
        include             mime.types;
        default_type        application/octet-stream;    
        charset utf-8;
        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  /var/log/nginx/access.log  main;
    
        server_tokens off;
        client_max_body_size 200m;
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        gzip on;
        gzip_disable "MSIE [1-6].";
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_buffers 16 8k;
        gzip_min_length 1024;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg;
        include /etc/nginx/conf.d/*.conf;                               
    }
    

    3.启动Nginx并设置开机自启

    #1.启动Nginx并设置开机自启
    [root@mccann-dbh /etc/nginx]$ systemctl  start nginx
    [root@mccann-dbh /etc/nginx]$ systemctl  enable nginx
    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
    
    #2.查看Nginx状态
    [root@mccann-dbh /etc/nginx]$ systemctl  status nginx
    ● nginx.service - The nginx HTTP and reverse proxy server
       Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
       Active: active (running) since Thu 2021-09-02 16:51:55 CST; 8s ago
     Main PID: 18015 (nginx)
       CGroup: /system.slice/nginx.service
               ├─18015 nginx: master process /usr/sbin/nginx
               ├─18016 nginx: worker process
               ├─18017 nginx: worker process
               ├─18018 nginx: worker process
               └─18019 nginx: worker process
    
    Sep 02 16:51:55 mccann-dbh systemd[1]: Starting The nginx HTTP and reverse proxy server...
    Sep 02 16:51:55 mccann-dbh nginx[18010]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    Sep 02 16:51:55 mccann-dbh nginx[18010]: nginx: configuration file /etc/nginx/nginx.conf test is successful
    Sep 02 16:51:55 mccann-dbh systemd[1]: Started The nginx HTTP and reverse proxy server.
    

    六、配置Nginx域名访问

    1.配置mccann-dbh-h5前端

    [root@mccann-dbh ~]$ cd /etc/nginx/conf.d/
    [root@mccann-dbh /etc/nginx/conf.d]$ vim dbhh5.mccann.dataxbusiness.com.conf
      server {
            listen       80;
            server_name  dbhh5.mccann.dataxbusiness.com;
    
            location / {
               root /data/webproject/dbhh5;
            }
    
        }
    

    2.配置mccann-dbh-pc前端

    [root@mccann-dbh /etc/nginx/conf.d]$ cat dbhweb.mccann.dataxbusiness.com.conf
      server {
            listen       80;
            server_name  dbhweb.mccann.dataxbusiness.com;
    
            location / {
               root /data/webproject/dbhweb;
            }
    
        }
    

    3.配置mccann-dbh后端

    [root@mccann-dbh /etc/nginx/conf.d]$ cat dbhbg.mccann.dataxbusiness.com.conf
    upstream dbhbg.mccann.dataxbusiness.com {
            server localhost:6666;
    }
    
    server {
    	listen 80;
    #        listen 443 ssl;
            server_name dbhbg.mccann.dataxbusiness.com;
    
    #        ssl_certificate      /etc/ssl/private/dm/rbcas.com.cn.pem;
    #        ssl_certificate_key  /etc/ssl/private/dm/rbcas.com.cn.key;
    
    #       ssl_session_timeout 5m;
    #       ssl_protocols TLSV1 TLSv1.1 TLSv1.2;
    #       ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    #       ssl_prefer_server_ciphers on;
    
            access_log /data/logs/dmtest.rbcas.com.cn_access.log;
            error_log  /data/logs/dmtest.rbcas.com.cn_error.log;
    
            location / {
            proxy_pass http://dbhbg.mccann.dataxbusiness.com;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
            # enables WS support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection  "upgrade";
            }
    
    }
    

    4.配置前后端相关目录

    [root@mccann-dbh /etc/nginx/conf.d]$ mkdir -p /data/webproject/dbhh5
    [root@mccann-dbh /etc/nginx/conf.d]$ mkdir -p /data/webproject/dbhweb
    [root@mccann-dbh /etc/nginx/conf.d]$ mkdir -p /data/logs/
    

    七、上传前端web文件

    1.上传mccann-dbh-h5前端

    #1.上传mccann-dbh-h5前端文件
    [root@mccann-dbh /etc/nginx/conf.d]$ cd /data/webproject/dbhh5
    [root@mccann-dbh /data/webproject/dbhh5]$ rz
    
    #2.查看压缩包
    [root@mccann-dbh /data/webproject/dbhh5]$ ll
    total 764
    -rw-r--r--. 1 root root 781184 2021-09-02 18:21 dbh-h520210902-1.zip
    
    #2.解压mccann-dbh-h5前端文件
    [root@mccann-dbh /data/webproject/dbhh5]$ unzip dbh-h520210902-1.zip 
    

    2.上传mccann-dbh-pc前端

    #1.上传mccann-dbh-pc前端文件
    [root@mccann-dbh /data/webproject/dbhh5]$ cd /data/webproject/dbhweb
    [root@mccann-dbh /data/webproject/dbhweb]$ rz
    
    #2.查看压缩包
    [root@mccann-dbh /data/webproject/dbhweb]$ ll
    total 1356
    -rw-r--r--. 1 root root 1386512 2021-09-02 18:21 dbh-pc20210902-1.zip
    
    #3.解压mccann-dbh-pc前端文件
    [root@mccann-dbh /data/webproject/dbhweb]$ unzip dbh-pc20210902-1.zip 
    

    八、上传后端jar文件

    #1.新建后端dbh文件存放目录
    [root@mccann-dbh ~]$ mkdir -p /data/backproject/dbh 
    
    #2.上传后端dbh文件
    [root@mccann-dbh ~]$ cd /data/backproject/dbh
    [root@mccann-dbh /data/backproject/dbh]$ rz
    
    #3.查看jar包
    [root@mccann-dbh /data/backproject/dbh]$ ll
    total 134256
    -rw-r--r--. 1 root root       287 2021-09-02 19:02 application-prod.yml
    -rw-r--r--. 1 root root       631 2021-09-02 19:41 application.yml
    -rw-r--r--. 1 root root 137463918 2021-09-02 18:28 dbh-0.0.1-SNAPSHOT.jar
    drwxr-xr-x. 2 root root        55 2021-09-02 19:40 logs
    -rw-r--r--. 1 root root       674 2021-09-02 20:04 run.sh
    drwxr-xr-x. 2 root root         6 2021-09-02 19:40 upload
    
    #4.编写启动脚本
    [root@mccann-dbh /data/backproject/dbh]$ vim run.sh 
    Project_name=$1
    Port_no=$2
    
    #echo $Project_name
    #echo $Port_no
    
    source /etc/profile
    
    # 进入到项目
    cd /data/backproject/$Project_name
    
    # 找到原进程,kill
    pid=$(ps -ef | grep java| grep $Project_name|awk -F '[ ]+' '{print $2}')
    kill -9 $pid
    
    
    #启动jar
    nohup java -jar $Project_name-0.0.1-SNAPSHOT.jar --server.port=$Port_no -server -Xmx1000m -Xms1000m -Xmn700m -XX:+UseParallelGC &
    
    echo "starting service..."
    sleep 20
    
    #根据重启后是否有当前应用判断启动是否成功
    pid=$(ps -ef | grep java| grep $Project_name|awk -F '[ ]+' '{print $2}')
    #echo $pid
    if [ -z $pid ];then
      echo "启动失败"
      exit 1
    else
      echo $Project_name :  $pid  "SUCCESS"
    fi
    
    #5.启动jar包
    [root@mccann-dbh /data/backproject/dbh]$ sh run.sh dbh 6666
    kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
    starting service...
    nohup: appending output to ‘nohup.out’
    dbh : 27108 SUCCESS
    
    #6.查看进程
    [root@mccann-dbh /data/backproject/dbh]$ ps -ef |grep dbh
    root     27108     1 23 20:09 pts/1    00:00:22 java -jar dbh-0.0.1-SNAPSHOT.jar --server.port=6666 -server -Xmx1000m -Xms1000m -Xmn700m -XX:+UseParallelGC
    root     27233 25002  0 20:11 pts/1    00:00:00 grep --color=auto dbh
    

    九、重载Nginx并放行端口

    #1.重载Nginx
    [root@mccann-dbh ~]$ nginx -s reload
    
    #2.登录亚马逊云服务器,放行80端口,实现全网访问
    

    十、Web测试访问

    #1.mccann-dbh-h5访问,输入用户名密码,课正常登陆。
    

    #1.mccann-dbh-pc访问,输入用户名密码,课正常登陆。
    

    #3.创建用户账号,按照顺序依次创建了账号Shiseido、Administrator-MRM,至此mccann-dbh生产环境部署完成。
    

  • 相关阅读:
    asp.net mvc验证那些事
    RemoteAttribute Class
    代理自动配置文件PAC
    海康威视摄像头密码重置
    开漏输出与推挽输出
    半导体发光二极管工作原理
    晶振电路原理
    下一代的iPaaS平台
    重温UAT
    Ira主题shopify模板修改
  • 原文地址:https://www.cnblogs.com/jhno1/p/15220887.html
Copyright © 2020-2023  润新知