安装mysql数据库

  1. # 下载mysql源安装包
  2. wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  3. # 安装mysql源
  4. yum localinstall mysql57-community-release-el7-8.noarch.rpm -y
  5. # 检查mysql源是否安装成功
  6. yum repolist enabled | grep "mysql.*-community.*"
  7. # 安装MySQL
  8. yum install mysql-community-server -y
  9. # 3、启动MySQL服务
  10. systemctl start mysqld
  11. # 查看MySQL的启动状态
  12. systemctl status mysqld
  13. #4、开机启动
  14. systemctl enable mysqld
  15. systemctl daemon-reload
  16. # 5、修改root本地登录密码
  17. # mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
  18. grep 'temporary password' /var/log/mysqld.log
  19. mysql -uroot -p
  20. # mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,
  21. # 并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误
  22. # 如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:
  23. # 配置默认编码为utf8
  24. # 关闭客户端dns反解
  25. echo -e "validate_password = off\ncharacter_set_server=utf8\ninit_connect='SET NAMES utf8'\nskip-name-resolve\n" >> /etc/my.cnf
  26. systemctl restart mysqld
  27. mysql -uroot -p
  28. ## 授权
  29. alter user 'root'@'localhost' identified by '123123';
  30. grant all privileges on *.* to root@'%' identified by '123123' with grant option;
  31. flush privileges;

安装Redis

  1. yum 安装redis 3.2
  2. yum -y install redis
  1. 文档 https://redis.io/download
  2. 编译安装redis-6.2.1
  3. yum install -y gcc gcc-c++ tcl
  4. wget -O /opt/tgzs/redis-6.2.1.tar.gz https://download.redis.io/releases/redis-6.2.1.tar.gz
  5. cd /opt/tgzs/
  6. #解压redis
  7. tar xf redis-6.2.1.tar.gz
  8. #进入解压后的目录
  9. cd redis-6.2.1
  10. #分配器allocator,如果有MALLOC 这个 环境变量, 会有用这个环境变量的 去建立Redis。
  11. #而且libc 并不是默认的分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。
  12. #但是如果你又没有jemalloc而只有 libc 当然 make 出错。 所以加这么一个参数,运行如下命令:
  13. make MALLOC=libc -j 20
  14. #编译
  15. # make -j 20
  16. #创建redis安装目录,主要用于存放redis所需bin文件
  17. mkdir -p /usr/local/redis
  18. #安装redis并指定安装目录
  19. make PREFIX=/usr/local/redis/ install
  20. # 设置path
  21. export PATH=$PATH:/usr/local/redis/bin
  22. #复制默认配置文件到/etc
  23. egrep -v "^$|#" redis.conf > redis_sample.conf
  24. #修改配置文件监听IP为0.0.0.0,否则只能本地登录
  25. sed -i s/bind\ 127.0.0.1/bind\ 0.0.0.0/g redis_sample.conf
  26. #修改运行方式为后台运行
  27. sed -i s/daemonize\ no/daemonize\ yes/g redis_sample.conf
  28. /bin/cp -f redis_sample.conf /etc/redis_6379.conf
  29. /bin/cp -f redis_sample.conf /etc/redis_6479.conf
  30. #设置日志文件路径
  31. sed -i s@logfile\ \"\"@logfile\ \"/opt/logs/redis_6379.log\"@g /etc/redis_6379.conf
  32. sed -i s@logfile\ \"\"@logfile\ \"/opt/logs/redis_6479.log\"@g /etc/redis_6479.conf
  33. #设置数据目录
  34. sed -i s@dir\ \./@dir\ /var/lib/redis_6379@g /etc/redis_6379.conf
  35. sed -i s@dir\ \./@dir\ /var/lib/redis_6479@g /etc/redis_6479.conf
  36. # 修改port
  37. sed -i 's/port 6379/port 6379/g' /etc/redis_6379.conf
  38. sed -i 's/port 6379/port 6479/g' /etc/redis_6479.conf
  39. mkdir /var/lib/redis_6379
  40. mkdir /var/lib/redis_6479
  41. mkdir /opt/logs
  42. cat <<EOF > /etc/systemd/system/redis_6379.service
  43. [Unit]
  44. Description=The redis-server Process Manager
  45. After=syslog.target network.target
  46. [Service]
  47. Type=forking
  48. ExecStart=/usr/local/redis/bin/redis-server /etc/redis_6379.conf
  49. #ExecStop=/usr/local/redis/bin/redis-shutdown
  50. [Install]
  51. WantedBy=multi-user.target
  52. EOF
  53. cat <<EOF > /etc/systemd/system/redis_6479.service
  54. [Unit]
  55. Description=The redis-server Process Manager
  56. After=syslog.target network.target
  57. [Service]
  58. Type=forking
  59. ExecStart=/usr/local/redis/bin/redis-server /etc/redis_6479.conf
  60. #ExecStop=/usr/local/redis/bin/redis-shutdown
  61. [Install]
  62. WantedBy=multi-user.target
  63. EOF
  64. systemctl daemon-reload
  65. #设置redis开机自启
  66. system enable redis_6379
  67. system enable redis_6479
  68. #启动redis
  69. systemctl restart redis_6379
  70. systemctl restart redis_6479
  71. #查看redis状态
  72. systemctl status redis_6379
  73. systemctl status redis_6479