运维管理 ·

抢鲜测试 Linux 下源码编译安装 AliSQL 阿里云数据库

1 禁用 SELinux和NetworkManager

#关闭selinux 备份selinux config文件[root@work232 ~]# /bin/cp /etc/selinux/config /etc/selinux/config.backup#把SELINUX=enforcing 改为 SELINUX=disabled[root@work232 ~]# vim /etc/selinux/config#查看selinux状态[root@work232 ~]# getenforce#临时生效[root@work232 ~]# setenforce[root@work232 ~]# service NetworkManager stop #停止NetworkManager 服务[root@work232 ~]# chkconfig NetworkManager off #禁止开机启动NetworkManager服务

2 AliSQL 编译源码所需的工具和库

yum -y install gcc gcc-c++ ncurses-devel cmake perl

3  新增AliSQL用户组

[root@work232 /]# groupadd mysql

4 创建用户 设置不允许登陆系统 -M不创建家目录,/dev/null 首先表示标准输出重定向到空设备文件

[root@work232 /]# useradd -M mysql -s /sbin/nologin -d /dev/null -g mysql

5 新建AliSQL安装目录,并设置权限

[root@work232 /]# mkdir -p /webserver/alisql # alisql安装目录[root@work232 /]# mkdir -p /data/logs/alisqllog # 日志目录 [root@work232 /]# mkdir -p /data/binlog/alisql # 二进值目录[root@work232 /]# mkdir -p /data/data_center/alisql # 数据库安装目录[root@work232 /]# mkdir -p /data/temp/alisql # 缓存目录[root@work232 /]# chown mysql.mysql -R /data/temp/alisql[root@work232 /]# chown mysql.mysql -R /data/binlog/alisql/[root@work232 /]# chown mysql.mysql -R /data/data_center/alisql

6 编译安装 jemalloc-4.5.0.tar.bz2

[root@work232 /]# wget https://github.com/jemalloc/jemalloc/releases/download/4.5.0/jemalloc-4.5.0.tar.bz2 [root@work232 /]# tar xjf jemalloc-4.5.0.tar.bz2[root@work232 /]# cd jemalloc-4.5.0 [root@work232 jemalloc-4.5.0]# LDFLAGS="-L/usr/local/lib -lrt" ./configure[root@work232 jemalloc-4.5.0]# make -j 2 && make install[root@work232 jemalloc-4.5.0]# unset LDFLAGS

7 注意: 64位系统 用这个

[root@work232 jemalloc-4.5.0]# ln -s /usr/local/lib/libjemalloc.so.2 /usr/lib64/libjemalloc.so.1

8 注意: 32位系统 用这个

[root@work232 jemalloc-4.5.0]# ln -s /usr/local/lib/libjemalloc.so.2 /usr/lib/libjemalloc.so.1

9 运行程序时可能会报找不到库 将jemalloc的库加载到系统中

[root@work232 jemalloc-4.5.0]# echo '/usr/local/lib' >/etc/ld.so.conf.d/local.conf[root@work232 jemalloc-4.5.0]# ldconfig

10 编译安装 libevent-2.1.8-stable.tar.gz

[root@work232 /]# wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz [root@work232 /]# tar zxvf libevent-2.1.8-stable.tar.gz [root@work232 libevent-2.1.8-stable]# cd libevent-2.1.8-stable[root@work232 tmux-2.3]# ./configure[root@work232 tmux-2.3]# make -j 2 && make install

11 编译安装 tmux-2.3.tar.gz

[root@work232 /]# wget https://github.com/tmux/tmux/releases/download/2.3/tmux-2.3.tar.gz [root@work232 /]# tar zxvf tmux-2.3.tar.gz[root@work232 /]# cd tmux-2.3[root@work232 tmux-2.3]# CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" ./configure[root@work232 tmux-2.3]# make -j 2 && make install[root@work232 tmux-2.3]# unset LDFLAGS# 注意: 64位系统 用这个[root@work232 tmux-2.3]# ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5# 注意: 32位系统 用这个[root@work232 tmux-2.3]# ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5

12 下载 Alisql 源码包并解压
#官网下载网址 https://github.com/alibaba/AliSQL/

[root@work232 /]# yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 flex libaio-devel
[root@work232 /]# tar zxvf alisql-5.6.32-5.tar.gz[root@work232 /]# cd alisql-5.6.32-5

13 AliSQL 编译参数说明

-DCMAKE_INSTALL_PREFIX=/webserver/alisql #安装路径-DMYSQL_DATADIR=/data/binlog/alisql #数据库文件存放位置-DSYSCONFDIR=/etc #my.cnf路径 #下面5个是数据库存储引擎设备 -DWITH_MYISAM_STORAGE_ENGINE=1 #支持 MyIASM 存储引擎-DWITH_INNOBASE_STORAGE_ENGINE=1 #支持 InnoDB 存储引擎-DWITH_ARCHIVE_STORAGE_ENGINE=1 #支持 ARCHIVE引擎-DWITH_BLACKHOLE_STORAGE_ENGINE=1 #支持 BLACKHOLE引擎-DWITH_PARTITION_STORAGE_ENGINE=1 #安装支持数据库分区-DWITH_MEMORY_STORAGE_ENGINE=1 #支持 Memory 存储引擎-DWITH_ZLIB=system # 启用libz库支持(zib、gzib相关)-DWITH_READLINE=1 # 快捷键功能(我没用过)-DMYSQL_UNIX_ADDR=/data/temp/alisql/alisql_3306.sock #连接数据库socket路径-DMYSQL_TCP_PORT=3306 #端口-DENABLED_LOCAL_INFILE=1 #允许从本地导入数据-DEXTRA_CHARSETS=all #安装所有的字符集-DDEFAULT_CHARSET=utf8 #默认字符-DDEFAULT_COLLATION=utf8_general_ci #默认字符校对-DINSTALL_SBINDIR=sbin #指向可执行文件目录(prefix/sbin)-DINSTALL_PLUGINDIR=lib/mysql/plugin #指向插件目录(prefix/lib/mysql/plugin)-DINSTALL_MANDIR=share/man #指向man文档目录(prefix/share/man)-DINSTALL_SHAREDIR=share #指向aclocal/mysqlm4安装目录(prefix/share-DINSTALL_LIBDIR=lib/mysql #指向对象代码库目录(prefix/lib/mysql)-DINSTALL_INCLUDEDIR=include/mysql #指向头文件目录(prefix/include/mysql)-DINSTALL_INFODIR=share/info #指向info文档存放目录(prefix/share/info)-DWITH_DEBUG=0 #调试模式-DWITH_SSL=yes # SSL支持

14 开始编译安装 Alisql-5.6.32-5

cmake . -DCMAKE_INSTALL_PREFIX=/webserver/alisql \-DMYSQL_DATADIR=/data/data_center/alisql \ -DCMAKE_BUILD_TYPE="Release" \ -DWITH_EMBEDDED_SERVER=0 \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_CSV_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DWITH_TOKUDB_STORAGE_ENGINE=0 \ -DENABLE_DTRACE=0 \ -DENABLED_LOCAL_INFILE=1 \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DEXTRA_CHARSETS=all \ -DMYSQL_USER=mysql \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DENABLE_DOWNLOADS=1 \ -DWITH_DEBUG=OFF \ -DENABLED_PROFILING=ON \ -DMYSQL_MAINTAINER_MODE=OFFmake -j 2 && make install #等半小时后或者更长,这个和电脑配置有关

15 建立开机启动配置文件

[root@work232 alisql-5.6.32-5]# /bin/cp /webserver/alisql/support-files/mysql.server /etc/init.d/mysqld[root@work232 alisql-5.6.32-5]# [ -z "`grep transparent_hugepage /etc/init.d/mysqld`" ] && sed -i "s@^basedir=.*@echo never > /sys/kernel/mm/transparent_hugepage/enabled\n&@" /etc/init.d/mysqld

16 修改启动文件安装路径

[root@work232 alisql-5.6.32-5]# sed -i "s@^basedir=.*@basedir=/webserver/alisql@" /etc/init.d/mysqld

17 修改数据库数据路径

[root@work232 alisql-5.6.32-5]# sed -i "s@^datadir=.*@datadir==/data/data_center/alisql@" /etc/init.d/mysqld

18 设置启动文件权限

[root@work232 alisql-5.6.32-5]# chmod +x /etc/init.d/mysqld

19 添加开机启动

[root@work232 alisql-5.6.32-5]# chkconfig --add mysqld[root@work232 alisql-5.6.32-5]# chkconfig mysqld on

20 生成配置文件 my.cnf

注意:下面配置可能有错,希望那位大神帮忙指点一下 QQ:2016571396,小白这里只能提供您参考一下~~!

[client]port = 3306socket = /tmp/mysql.sockdefault-character-set = utf8mb4[mysql]prompt="AliSQL [\\d]> "no-auto-rehash[mysqld]port = 3306user = mysqlsocket = /tmp/mysql.sockbasedir = /webserver/alisqldatadir = /data/data_center/alisqlpid-file = /data/temp/alisql/mysql.pidtmpdir = /data/temp/alisqlslave-load-tmpdir = /data/data_center/alisqllog_error = /data/logs/alisqllog/alisql_error.log#secure-file-priv = /webserver/alisql/uploads#慢查询slow_query_log = 1long_query_time = 2log-queries-not-using-indexesslow_query_log_file = /data/logs/alisqllog/alisql_slow.loglog-slow-admin-statements = 1log-slow-slave-statements = 1log-bin-trust-function-creators = 1#init-connect = 'SET NAMES utf8'#character-set-server = utf8init-connect = 'SET NAMES utf8mb4'character-set-server = utf8mb4symbolic-links = 0#lower_case_table_names = 1performance_schema = 0bind-address = 0.0.0.0#开启查询缓存explicit_defaults_for_timestamp=true#消耗系统IO 内存等#log-output = FILE#general_log = off#general_log_file = /data/logs/alisqllog/general.log##^^^^^^^^^^^^^^^^^^^^^^主从同步相关设置开始^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^##server-id = 10binlog_cache_size = 4Mmax_binlog_size = 1Gmax-binlog-cache-size = 2Gmax-relay-log-size = 1Glog_bin = /data/binlog/alisql/Alisql-Binbinlog_format = mixedlog_bin_index = /data/binlog/alisql/Binlog.indexexpire_logs_days = 90#skip-locking#禁止外网skip-networking#禁止域名解析skip-name-resolve#skip-grant-tables#禁止锁定skip-external-lockingskip_show_databaseskip_symbolic_linksback_log = 300max_connections = 1000max_connect_errors = 6000open_files_limit = 65535#表缓存数table_open_cache = 128binlog_cache_size = 1M#最大表量max_heap_table_size = 256Mtmp_table_size = 16M#根据物理内存设置规则如下:1G=8 ; 2G=16; 3G=32; 3G>= =64thread_cache_size = 8open-files-limit=8192#排序缓冲sort_buffer_size=256M#启动高速缓存query_cache_type = 1#查询缓存 很少有相同的查询,最好不要使用查询缓存query_cache_size = 128Mquery_cache_limit = 2Mflush_time = 0#连续缓冲join_buffer_size = 16Mgroup_concat_max_len=2048000table_definition_cache = 1400ft_min_word_len = 4#预读缓冲read_buffer_size = 2M#次缓冲read_rnd_buffer_size = 64Mquery_cache_min_res_unit = 1MBbulk_insert_buffer_size = 8M#索引缓冲 比较理想的设置:Key_blocks_used / (Key_blocks_unused + Key_blocks_used) * 100% ≈ 80%key_buffer_size=64M#default-storage-engine = MyISAMdefault_storage_engine = InnoDBinnodb_file_per_table = 1innodb_open_files = 500#参数的配置在物理内存的70%-80%之间innodb_buffer_pool_size = 64M#InnoDB 使用后台线程处理数据页上写 I/O(输入)请求的数量innodb_write_io_threads = 4#InnoDB 使用后台线程处理数据页上读 I/O(输出)请求的数量innodb_read_io_threads = 4innodb_thread_concurrency = 0innodb_purge_threads = 1innodb_flush_log_at_trx_commit = 2#日志缓冲池,控制在8M-16M即可innodb_log_buffer_size = 2M#InnoDB 日志文件的大小innodb_log_file_size = 256Minnodb_log_files_in_group = 3#控制了 Dirty Page 在 Buffer Pool 中所占的比率innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120#缓冲区刷新到磁盘时,刷新脏页数量,ssd磁盘,或做了raid后,可将此值设置较大innodb_io_capacity = 200innodb_adaptive_flushing = OFFinnodb_autoextend_increment = 64innodb_buffer_pool_instances = 8innodb_concurrency_tickets = 5000innodb_old_blocks_time = 1000innodb_stats_on_metadata = 0#*** MyISAM Specific optionsmyisam_sort_buffer_size = 16Mmyisam_max_sort_file_size = 10Gmyisam_repair_threads = 1#导入大的sql文件的方法interactive_timeout = 28800wait_timeout = 28800connect_timeout = 20#单数据包max_allowed_packet = 500M#thread_concurrency = 8[mysqlhotcopy]interactive-timeout[mysqldump]quickmax_allowed_packet = 500M[myisamchk]key_buffer_size = 8Msort_buffer_size = 8Mread_buffer = 4Mwrite_buffer = 4M

21 建立初始化数据库,64位系统必须指定目录

[root@work232 alisql-5.6.32-5]#/webserver/alisql/scripts/mysql_install_db--user=mysql--basedir=/webserver/alisql --datadir=/data/data_center/alisql

22 设置 my.cnf 权限 为 600 防止黑客攻击

[root@work232 alisql]# chown mysql.mysql /etc/my.cnf[root@work232 alisql]# chmod 600 /etc/my.cnf[root@work232 alisql]# chown mysql.mysql -R /data/data_center/alisql

23 启动数据库服务

[root@work232 alisql-5.6.32-5]# service mysqld start

24 设置Alisql加入PATH路径环境变量

[root@work232 alisql]# vim /etc/profile # 修改export PATH= 在最下面添加export PATH=/webserver/alisql/bin:$PATH # 如果有多个路径请用 英文分号(;) 隔开[root@work232 alisql]# source /etc/profile # 使/etc/profile里的配置立即生效

25 修改MySQL用户root的密码

#删除默认 test数据库[root@work232 alisql] mysql -uroot -e "drop database test;"[root@work232 alisql] mysql -uroot -e "delete from mysql.user WHERE USER='root' AND HOST='::1';"[root@work232 alisql] mysql -uroot -e "delete from mysql.user where Host='localhost' AND User='';"[root@work232 alisql] mysql -uroot -e "delete from mysql.user where Host='$host' AND User='';"[root@work232 alisql] mysql -uroot -e "update mysql.user set host='%' where host='$host' AND User='root';"

26 删除默认的数据库和用户

[root@work232 alisql] mysql -uroot -e "delete from mysql.proxies_priv where Host!='localhost';"[root@work232 alisql] mysql -uroot -e "delete from mysql.db where User='';"

27 修改 root 用户名为 fooher.com

[root@work232 alisql] mysql -uroot -e "update mysql.user set user='www.fooher.com' where User='root';"# 修改密码-127.0.0.1[root@work232 alisql] mysql -uroot -e "grant all privileges on *.* to fooher.com @'127.0.0.1' identified by \"www.fooher.com\" with grant option;"

28 修改密码

[root@work232 alisql] mysql -uroot -e "grant all privileges on *.* to fooher.com@'localhost' identified by \"www.fooher.com\" with grant option;"

29 添加用户远程访问

[root@work232 alisql] mysql -uroot -e "grant all privileges on *.* to fooher.com@'%' identified by \"www.fooher.com\" with grant option;"

30  刷新数据库

[root@work232 alisql] mysql -uroot -e "flush privileges;"

31 删除默认测试数据库文件

[root@work232 alisql] rm -rf /webserver/alisql/data[root@work232 alisql] rm -rf /webserver/alisql/mysql-test

32 添加 Alisql 到系统库中

[root@work232 alisql] /webserver/alisql/lib > /etc/ld.so.conf.d/alisql.conf[root@work232 alisql] ldconfig #刷新动态库配置[root@work234 alisql]# reboot # 最好重启一下系统

到此 Alisql 数据库安装完成 By 运维天涯

评论已关闭