V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zhibo2144899870
V2EX  ›  程序员

LNMP 之 MySQL 配置.md

  •  
  •   zhibo2144899870 · 2018-08-29 14:47:10 +08:00 · 1297 次点击
    这是一个创建于 2277 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如何搭建直播系统 LNMP 环境,下面先教如何配置 mysql。
    一、前期准备
    1.关闭防火墙及 selinux
    service iptables stop
    chkconfig iptables off
    setenforce 0
    vi /etc/sysconfig/selinux
    SELINUX=disabled #enforcing 改为 disabled
    2.依赖包安装
    yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers make libtool* git tree bison pcre-devel perl gd gd-devel
    3.安装 libiconv (支持编码转换为函数)
    tar xf libiconv-1.14.tar.gz
    cd libiconv-1.14/
    ./configure --prefix=/usr/local make && make install

    4.安装 libmcrypt (加密算法扩展库,支持 DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法)
    tar xf libmcrypt-2.5.8.tar.gz
    cd libmcrypt-2.5.8
    ./configuremake && make install
    cd libltdl/
    ./configure --enable-ltdl-install #加载动态库 make && make install

    5.安装 mhash ( Mhash 是基于离散数学原理的不可逆向的 php 加密方式扩展库,其在默认情况下不开启。mhash 的可以用于创建校验数值,消息摘要,消息认证码,以及无需原文的关键信息保存)
    tar xf mhash-0.9.9.9.tar.bz2
    cd mhash-0.9.9.9
    ./configure
    make && make install

    6.安装 mcript ( mcrypt 是 php 里面重要的加密支持扩展库,Mcrypt 扩展库可以实现加密解密功能,就是既能将明文加密,也可以密文还原。)
    cd /usr/local/src
    tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH #暂时生效
    ./configure
    make && make install

    7.亦可以通过以下两种方法增加库文件
    ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
    ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
    ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
    ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
    ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
    ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
    ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
    ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
    ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
    ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

    vim /etc/ld.so.conf
    /usr/local/lib/
    ldconfig
    8.安装 cmake ( MySQL 从 5.5 版本开始,通过./configure 进行编译配置方式已经被取消,取而代之的是 cmake 工具)
    tar xf cmake-3.4.1.tar.gz
    cd cmake-3.4.1
    ./bootstrap
    make && make install
    二、MySQL 安装
    1.新增 mysql 用户
    groupadd -r mysql
    useradd -r -g mysql mysql
    2.新建 MySQL 所需目录
    mkdir -p /usr/local/mysql
    mkdir -p /data/mysqldb
    3.编译安装
    tar xf mysql-5.6.23.tar.gz
    cd mysql-5.6.23
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1-DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1-DSYSCONFDIR=/etc -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0
    make&& make install
    4.修改 mysql 目录权限
    cd /usr/local/mysql
    chown -R mysql:mysql .
    cd /data/mysqldb
    chown -R mysql:mysql .

    5.初始化 mysql 数据库
    cd /usr/local/mysql./scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
    6.编译修改 /etc/my.cnf
    [mysql]
    # CLIENT #port = 3306socket = /data/mysqldb/mysql.sock
    [mysqld]
    # GENERAL #user = mysqldefault-storage-engine = InnoDBsocket = /data/mysqldb/mysql.sockpid-file = /data/mysqldb/mysql.pid
    # MyISAM #key-buffer-size = 32Mmyisam-recover = FORCE,BACKUP
    # SAFETY #max-allowed-packet = 16Mmax-connect-errors = 1000000
    # DATA STORAGE #datadir = /data/mysqldb/
    # BINARY LOGGING #log-bin = /data/mysqldb/mysql-binexpire-logs-days = 14sync-binlog = 1
    # REPLICATION #skip-slave-start = 1relay-log = /data/mysqldb/relay-binslave-net-timeout = 60
    # CACHES AND LIMITS #tmp-table-size = 32Mmax-heap-table-size = 32Mquery-cache-type = 0query-cache-size = 0max-connections = 500thread-cache-size = 50open-files-limit = 65535table-definition-cache = 4096table-open-cache = 4096
    # INNODB #innodb-flush-method = O_DIRECTinnodb-log-files-in-group = 2innodb-log-file-size = 64Minnodb-flush-log-at-trx-commit = 1innodb-file-per-table = 1innodb-buffer-pool-size = 592M
    # LOGGING #log-error = /data/mysqldb/mysql-error.loglog-queries-not-using-indexes = 1slow-query-log = 1slow-query-log-file = /data/mysqldb/mysql-slow.log
    7.复制 MySQL 启动文件及其命令加入 PATH
    cp support-files/mysql.server /etc/init.d/mysqld
    vim /etc/profile.d/mysql.sh
    PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
    export PATH
    source /etc/profile.d/mysql.sh
    8.启动 MySQL 并增加启动项
    service mysqld start
    chkconfig mysqld on
    9.设置 MySQL 登录权限
    drop user ''@localhost;drop user ''@hostname;update mysql.user set password=password('*******');flush privileges;
    到这里,MySQL 编译完成
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5260 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 08:48 · PVG 16:48 · LAX 00:48 · JFK 03:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.