一、卸载旧的mariadb 查询已安装的软件: rpm -qa | grep Maria* 卸载:yum -y remove mari* 删除数据库文件:rm -rf /var/lib/mysql/* ? 二、安装相关包且源码安装cmake yum groupinstall "Development Tools" yum install libaio libaio-devel bison bison-devel zlib-devel cmake openssl openssl-devel ncurses ncurses-devel libcurl-devel libarchive-devel boost boost-devel lsof wget 可以去cmake 官网进行下载: https://cmake.org/download/ ?一、卸载旧的mariadb查询已安装的软件:rpm -qa | grep Maria*卸载:yum -y remove mari*删除数据库文件:rm -rf /var/lib/mysql/*?二、安装相关包且源码安装cmakeyum groupinstall Development Toolsyum ...
三、下载和编译jemalloc cd /usr/local/src wget https://github.com/jemalloc/jemalloc/releases/download/4.3.1/jemalloc-4.3.1.tar.bz2 tar jxvf jemalloc-4.3.1.tar.bz2 cd jemalloc-4.3.1 ./configure &&make && make install ? 四、准备目录 这里提前预定MariaDB的安装目录为/usr/local/mysql并且数据库目录为/data/mysql,这里要建立系统用户及组和数据库存放目录,并且将数据库存放目录赋予mysql用户及组权限,操作如下:(请注意特别说明一下:这里说的数据库目录是指的具体数据库存储文件, 而不是安装文件!) ----创建maria安装目录 # mkdir -p /usr/local/mysql ----创建数据库存放目录 # mkdir -p /data/mysql 或使用下面命令: # mkdir -pv /data/mysql/{data,logs/{binlog,relaylog}} ----建立用户,目录,设置权限 # useradd -s /sbin/nologin -g mysql -M mysql ----改变数据库存放目录所属用户及组为 mysql:mysql # chown mysql:mysql /data/mysql -R 以下是上面创建系统用户mysql的各个参数说明: -r: 添加系统用户( 这里指将要被创建的系统用户mysql ) -g: 指定要创建的用户所属组( 这里指添加到新系统用户mysql到mysql系统用户组 ) -s: 新系统帐户的登录shell( /sbin/nologin 这里设置为将要被创建系统用户mysql不能用来登录系统 ) -d: 新帐户的主目录( 这里指定将要被创建的系统用户mysql的家目录为 /usr/local/mysql ) -M: 不要创建用户的主目录( 也就是说将要被创建的系统用户mysql不会在 /home 目录下创建 mysql 家目录 ) ? 五、下载、解压并编译安装 https://downloads.mariadb.org/interstitial/mariadb-10.2.18/source/mariadb-10.2.18.tar.gz/from/http%3A//mirrors.tuna.tsinghua.edu.cn/mariadb/?serve # tar zxvf mariadb-10.2.18.tar.gz # cd mariadb-10.2.18 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITHOUT_TOKUDB=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system -DWITH_LOBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci ? 下面这个简单一点:cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITHOUT_TOKUDB=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci ? -DCMAKE_INSTALL_PREFIX是指定安装的位置,这里是/usr/local/mysql -DMYSQL_DATADIR是指定MySQL的数据目录,这里是/data/mysql -DSYSCONFDIR是指定配置文件所在的目录,一般都是/etc,具体的配置文件是/etc/my.cnf, -DWITHOUT_TOKUDB=1这个参数一般都要设置上,表示不安装tokudb引擎,tokudb是MySQL中一款开源的存储引擎,可以管理大量数据并且有一些新的特性,这些是Innodb所不具备的,这里之所以不安装,是因为一般计算机默认是没有Percona Server的,并且加载tokudb还要依赖jemalloc内存优化,一般开发中也是不用tokudb的,所以暂时屏蔽掉,否则在系统中找不到依赖会出现:CMake Error at storage/tokudb/PerconaFT/cmake_modules/TokuSetupCompiler.cmake:179 (message)这样的错误 -DDEFAULT_CHARSET 字符集,这里是utf-8 -DDEFAULT_COLLATION排序规则,这里是utf8_general_ci 注意: 1)如果上面make需要修改参数,重新编译 可以删除原来本目录下的CMakeCache.txt mv CMakeCache.txt CMakeCache.txt.bak # rm -f CMakeCache.txt make && make install ? 六、使用jemalloc优化mariadb 使用jemalloc优化MaridDB编译方法,cmake预编译时加上下面参数 -DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" -DWITH_SAFEMALLOC=OFF 或者直接加载,修改mysqld_safe,运行命令: sed -i 's@executing mysqld_safe@executing mysqld_safe\nexport LD_PRELOAD=/usr/local/lib/libjemalloc.so@' /usr/local/mysql/bin/mysqld_safe service mysqld restart ? 七、拷贝配置文件并修改 # cp support-files/my-large.cnf /etc/my.cnf vim /etc/my.cnf 增加如下: ?datadir = /data/mysq/ innodb_flush_log_at_trx_commit = 2? innodb_file_per_table = ON ? skip_name_resolve = ON 注意:查看配置文件当前有效配置如下 # sed -e "s/#.*//g" /etc/my.cnf | awk '{if (length !=0) print $0}' [client] port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 256M max_allowed_packet = 1M table_open_cache = 256 sort_buffer_size = 1M read_buffer_size = 1M read_rnd_buffer_size = 4M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size= 16M thread_concurrency = 8 log-bin=mysql-bin binlog_format=mixed server-id = 1 datadir = /data/mysql/ innodb_data_home_dir = /data/mysql innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /data/mysql innodb_buffer_pool_size = 256M innodb_log_file_size = 64M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 2 innodb_lock_wait_timeout = 50 innodb_file_per_table = ON skip_name_resolve = ON [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 128M sort_buffer_size = 128M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout ? 八、初始化mariadb cd /usr/local/mysql # scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql --defaults-file=/etc/my.cnf ? 出现下列信息: To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! To do so, start the server, then issue the following commands: ? '/usr/local/mysql//bin/mysqladmin' -u root password 'new-password' '/usr/local/mysql//bin/mysqladmin' -u root -h Anwar01 password 'new-password' ? Alternatively you can run: '/usr/local/mysql//bin/mysql_secure_installation' ? which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. You can start the MariaDB daemon with: cd '/usr/local/mysql/' ; /usr/local/mysql//bin/mysqld_safe --datadir='/data/mysql' ? You can test the MariaDB daemon with mysql-test-run.pl cd '/usr/local/mysql//mysql-test' ; perl mysql-test-run.pl ? 查看初始化结果: # ll /data/mysql ? 九、设置自动启动脚本,启动服务 # cp support-files/mysql.server /etc/rc.d/init.d/mysqld # chmod +x /etc/rc.d/init.d/mysqld # chkconfig --add mysqld # /etc/init.d/mysqld restart 启动mariadb systemctl start mysqld ? 十、添加环境变量? # vim /etc/profile #export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin # source /etc/profile ? 十一、检查默认配置和运行情况 mysqld --print-defaults 信息显示如下: mysqld would have been started with the following arguments: --port=3306 --socket=/tmp/mysql.sock --skip-external-locking --key_buffer_size=256M --max_allowed_packet=1M --table_open_cache=256 --sort_buffer_size=1M --read_buffer_size=1M --read_rnd_buffer_size=4M --myisam_sort_buffer_size=64M --thread_cache_size=8 --query_cache_size=16M --thread_concurrency=8 --log-bin=mysql-bin --binlog_format=mixed --server-id=1 --innodb_data_home_dir=/data/mysql --innodb_data_file_path=ibdata1:10M:autoextend --innodb_log_group_home_dir=/data/mysql --innodb_buffer_pool_size=256M --innodb_log_file_size=64M --innodb_log_buffer_size=8M --innodb_flush_log_at_trx_commit=2 --innodb_lock_wait_timeout=50 --innodb_file_per_table=ON ? --skip_name_resolve=ON #ss -tlnp|grep :3306 #lsof |grep jemalloc ? 十二、初始安全设置,初始化数据库用户表,连接mariadb使用 #mysql_secure_installation #mysql -u root -p #show engines; #show VARIABLES like "character_set%";
沃梦达教程
本文标题为:centos7.4下源码安装mariadb
猜你喜欢
- 【转载】CentOS安装Tomcat 2023-09-24
- 利用Docker 运行 python 简单程序 2022-10-16
- 解决:apache24 安装后闪退和配置端口映射和连接超时设置 2023-09-11
- 阿里云ECS排查CPU数据分析 2022-10-06
- 教你在docker 中搭建 PHP8 + Apache 环境的过程 2022-10-06
- KVM虚拟化Linux Bridge环境部署的方法步骤 2023-07-11
- CentOS_mini下安装docker 之 安装docker CE 2023-09-23
- nginx中封禁ip和允许内网ip访问的实现示例 2022-09-23
- IIS搭建ftp服务器的详细教程 2022-11-15
- CentOS7安装GlusterFS集群的全过程 2022-10-10