编译LNMP环境

1.编译安装mysql

MySQL5.7依赖的软件包:gcc gcc-c++ ncurses ncurses-devel bison make等供参考,安装前可以使用rpm -qa |grep $(软件包名)检查

# yum install -y gcc gcc-c++ glibc automake autoconf libtool make
# cd /tmp
# wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
# wget https://github.com/kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.gz
# wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/mysql-5.7.27.tar.gz

1.1安装make

# cd /tmp
# ls
# tar -zvxf cmake-3.14.5.tar.gz
# cd cmake-3.14.5
# ./ bootstrap
# gmake && gmake install
​
# cd ~
# cmake -version
cmake version 3.14.5

  

1.2安装boost

# cd /tmp
# tar xf boost_1_59_0.tar.gz -C /usr/local/
# cd /usr/local/
# mv boost_1_59_0/  boost
# cd boost/

  

1.3编译安装mysql

  • -M 不创建用户的HOME目录

# yum install -y gcc gcc-c++ ncurses ncurses-devel bison make
# mkdir -p /database/mysql/{data,tmp,binlog,logs}
# tree -L 2 /database/
# useradd mysql -s /sbin/nologin -M -g mysql
# id mysql
# cd /tmp
# tar xf mysql-5.7.27.tar.gz
# cd mysql-5.7.27
# cmake . -DCMAKE_INSTALL_PREFIX=/database/mysql \
-DMYSQL_DATADIR=/database/mysql/data \
-DMYSQL_UNIX_ADDR=/database/mysql/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0 \
-DWITH_BOOST=/usr/local/boost
​
    // -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    // -DWITH_PARTITION_STORAGE_ENGINE=1 \
# make install

  

1.4修改系统变量

# echo 'export PATH=/database/mysql/bin:$PATH' >> /etc/profile
# tail -1 /etc/profile
# source /etc/profile
# echo $PATH
​
# chown -R mysql:mysql /database/mysql/
# chown mysql:mysql /etc/my.cnf
​
# cp /etc/my.cnf /etc/my.cnf.bak
# vi /etc/my.cnf
[client]
port = 3306
socket = /database/mysql/tmp/mysql.sock
default-character-set = utf8
[mysqld]
port = 3306
basedir = /database/mysql
datadir = /database/mysql/data
pid-file = /database/mysql/mysqld.pid
socket = /database/mysql/tmp/mysql.sock
tmpdir = /database/mysql/tmp
character-set_server = utf8
server-id = 1
max_connections = 100
max_connect_errors = 10
log-bin = /database/mysql/binlog/mysql-bin
log-error = /database/mysql/logs/mysql_5_7_27.err

 

1.5初始化mysql数据库

# cd /database/mysql
# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/database/mysql --datadir=/database/mysql/data
# cd /database/mysql/data
# chmod +r server-key.pem
# ll server-key.pem
  • 生成初始化密码参数(5.7版本才有,必须添加,否则初始化失败,会生成空密码)

    • --initialize-insecure

  • 设定初始化用户

    • --user=mysql

1.6启动mysql

关闭防火墙、selinux

# cd //database/mysql
# cp support-files/mysql.server /etc/init.d/mysql
# ls /etc/init.d/mysql
# systemctl deamon-reload       //重载系统库
# systemctl enable mysql
# /etc/init.d/mysql restart 
# ps aux |grep mysqld
# yum install -y lsof
# lsof -i:3306

 

1.7 mysql优化(安全)

账户设置密码,添加额外管理员,重新加载mysql授予表

# msyql
> select user,host from mysql.user;         //查看账号
mysql.session   localhost
mysql.sys       localhost
root            localhost
> grant all privileges on *.* to 'zhangsan'@'localhost' identified by 'AB.123com' with grant option;
> set password for 'mysql.session'@'localhost' = password('AB.123com');
> set password for 'root'@'localhost' = password('AB.123com');
> flush privileges;
​
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
​
//授权远程用户
# mysql -uroot -p'AB.123com'
> grant all privileges on *.* to 'lisi'@'192.168.1.%' identified by 'AB.123com' with grant option;
> flush privileges;
> select user,host from mysql.user;

  

测试远程登录(客户端2;192.168.1.3)

  • -h 指登录的服务器端地址

# mysql -h192.168.1.2 -u lisi -p'AB.123com' -P3306
> show database;

 

posted @ 2021-03-09 00:15  破碎的屋檐  阅读(53)  评论(0编辑  收藏  举报