admin 管理员组

文章数量: 887017

Mysql,Redis,Mongo,ES单机版部署

1. 资源规划

IP区域服务安装目录
192.168.32.1开发Mysql/hrssc/gbgl/mysql
192.168.32.2开发Redis,Mongo/hrssc/gbgl/{redis,mongo}
192.168.32.3开发Elasticsearch/hrssc/gbgl/elastic

2. 中间件版本

# 版本与当前生产环境版本保持一致
- centos 7
- mysql 5.7.11
- MongoDB 4.0.2
- Redis 5.0.5
- Elasticsearch 5.6.5

3. 环境初始化

3.1 安装常用工具
- yum update -y
- yum install -y epel-release
- yum install curl tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop sysstat nethogs telnet zip unzip -y
- yum install psmisc net-tools bash-completion vim-enhanced -y
3.2 配置节点互信
# 本操作只需要在192.168.32.1节点上进行
- ssh-keygen -t rsa 
- ssh-copy-id sysadm@192.168.32.1
- ssh-copy-id sysadm@192.168.32.2
- ssh-copy-id sysadm@192.168.32.3

4. MySQL安装

4.1 准备
# 安装包上传到/home/sysadm目录
- cd /home/sysadm
- mkdir -p /hrssc/gbgl/mysql/{data,log}
4.2 配置环境变量
# 解压
- tar -xvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz -C /hrssc/gbgl/mysql
- cd /hrssc/gbgl/mysql/
- mv mysql-5.7.11-linux-glibc2.5-x86_64/* .
- rm -rf mysql-5.7.11-linux-glibc2.5-x86_64/
# 配置环境变量
- vim /etc/profile
- export PATH=/hrssc/gbgl/mysql/bin:$PATH
- source /etc/profile
4.3 创建用户
- groupadd mysql
- useradd -r -g mysql mysql
- chown -R mysql:mysql /hrssc/gbgl/mysql
4.4 创建配置文件
- cp -a ./support-files/my-defaultf  /etc/myf 

编辑myf

[mysqld]
port = 3306
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /hrssc/gbgl/mysql/mysql.sock
basedir =/hrssc/gbgl/mysql
datadir = /hrssc/gbgl/mysql/data
pid-file =/hrssc/gbgl/mysql/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
#server-id=1
#gtid_mode=on
#enforce_gtid_consistency=on
#log-slave-updates=1
#log-bin=master-bin
#log-bin-index = master-bin.index
#relay-log = relay-log
#relay-log-index = relay-log.index
#binlog_format=row
log_error = /hrssc/gbgl/mysql/log/error.log
skip-name-resolve
#log-slave-updates=1
#relay_log_purge = 0
#slow_query_log = 1
#long_query_time = 1
#slow_query_log_file = /data/mysql/log/mysql-slow.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

4.5 初始化数据库
- cd /hrssc/gbgl/mysql
- ./bin/mysqld --defaults-file=/etc/myf --initialize --user=mysql --basedir=/hrssc/gbgl/mysql --datadir=/hrssc/gbgl/mysql/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp # 获取初始密码,后面登录备用
- grep "password" /hrssc/gbgl/mysql/log/error.log
4.6 启动
# 配置systemdcat >/etc/systemd/system/mysqld.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/hrssc/gbgl/mysql/bin/mysqld --defaults-file=/etc/myf
LimitNOFILE = 5000
EOF# 启动
- systemctl enable mysqld
- systemctl start mysqld
4.6 配置账号
# 输入4.5获取到的初始密码进行登录
- mysql -u root -p 
- pdate user set authentication_string=PASSWORD('$Mhk!YiNM0') where User='root';# 授权
- grant all privileges on *.* to root@'192.168.32.%' identified by '$Mhk!YiNM0';
- FLUSH PRIVILEGES;

5.MongoDB安装

5.1 准备
- cd /home/sysadm
- mkdir -p /hrssc/gbgl/mongo/{data,log}
5.2 配置环境变量
# 1.解压
- tar -zvxf mongodb-linux-x86_64-rhel70-4.0.20.tgz
- mv mongodb-linux-x86_64-rhel70-4.0.20/* /hrssc/gbgl/mongo/
# 2.配置环境变量
- vi /etc/profile
- export MONGODB_HOME=/hrssc/gbgl/mongo                                                                        
- export PATH=$PATH:$MONGODB_HOME/bin
- source /etc/profile
5.3 创建用户
# 创建mongo用户和修改软件的权限
- groupadd mongo
- useradd -r -g mongo mongo
- chown -R mongo:mongo /hrssc/gbgl/mongo
5.4 创建配置文件
#vim /etc/mongod.conf
# mongod.conf
# for documentation of all options,see:
# /
# where to write logging data.
systemLog:destination: filelogAppend: truepath: /hrssc/gbgl/mongo/log/mongodb.log# where and how to store data.
storage:dbPath: /hrssc/gbgl/mongo/data/dbjournal:enabled: true# how the process runs
processManagement:fork: true
net:port: 27017bindIp: 0.0.0.0
5.5 配置启动
# 配置systemd
cat >/etc/systemd/system/mongod.service <<EOF
[Unit]
Description=mongod Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
#User=mongo
#Group=mongo
Type=forking
ExecStart=/hrssc/gbgl/mongo/bin/mongod --config=/etc/mongod.conf
ExecStop=/hrssc/gbgl/mongo/bin/mongod  --config=/etc/mongod.conf --shutdown
PrivateTmp=true
LimitNOFILE = 5000
EOF# 开机启动
systemctl enable mongod
systemctl start mongod

6. Redis安装

6.1 准备
- cd /home/sysadm
- mkdir -p /hrssc/gbgl/redis/{data,log}# 安装依赖
- yum install gcc gcc-c++
6.2 解压安装
- tar -zvxf redis-5.0.5.tar.gz 
- mv redis-5.0.5/* /hrssc/gbgl/redis/# 安装
- cd /hrssc/gbgl/redis
- make && make install
6.3 创建配置文件
 - cp /hrssc/gbgl/redis/redis.conf /etc/redis.conf- vim /hrssc/gbgl/redis/redis.conf
- 配置允许所有ip都可以访问redis,在bind 127.0.0.1前加“#”将其注释掉
- 默认为保护模式,把 protected-mode yes 改为 protected-mode no
- 默认为不守护进程模式,把daemonize no 改为daemonize yes
- 将 requirepass foobared前的“#”去掉,密码改为你想要设置的密码(练习设置为123456,即将foobared改为123456)
6.4 配置启动

cat >/etc/systemd/system/redis.service <<EOF
[Unit]
Description=Redis
After=network.target[Service]
Type=forking
ExecStart=/hrssc/gbgl/redis/src/redis-server /etc/redis.conf
ExecStop=/hrssc/gbgl/redis/src/redis-cli -h 127.0.0.1 -p 6379 shutdownRestartSec=10
Restart=always[Install]
WantedBy=multi-user.target
EOFsystemctl daemon-reload
systemctl enable redis
systemctl start redis 

7. Elasticsearch安装

7.1 准备
 - cd /home/sysadm- mkdir -p /hrssc/gbgl/{elastic,elastic-head}- unzip elasticsearch-5.6.5.zip- mv elasticsearch-5.6.5/* /hrssc/gbgl/elastic# 修改虚拟内存限制(root)# max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
- vi /etc/sysctl.conf
- vm.max_map_count=655360
- sysctl -p
# 修改创建文件限制,线程限制(root)
- vim /etc/security/limits.conf
# max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
* soft nofile 65536
* hard nofile 131072
# max number of threads [3818] for user [es] is too low, increase to at least [4096]
* soft nproc 2048
* hard nproc 409 # 查看验证命令
- ulimit -Hn
- ulimit -Sn
7.2 创建用户
- groupadd elastic
- useradd -r -g elastic elastic
- chown -R elastic:elastic /hrssc/gbgl/elastic
7.3 安装
- su elastic
- cd /hrssc/gbgl/elastic/bin
- ./elasticsearch -d
7.4 验证
# 浏览器访问
http://192.168.32.3:9200/

8. Elasticsearch-head安装

8.1 准备
- cd /home/sysadm
- unzip elasticsearch-head-master.zip
- mv elasticsearch-head-master/* /hrssc/gbgl/elastic-head
8.2 配置环境变量
# 安装nodejs
- unzip node-v10.15.3-linux-x64.tar.gz
- mv node-v10.15.3-linux-x64/*  /hrssc/gbgl/nodejs/
- ln -s /hrssc/gbgl/nodejs/bin/node  /usr/local/bin/node
- ln -s /hrssc/gbgl/nodejs/bin/npm  /usr/local/bin/npm# 验证
- node -v
- npm -v 
8.3 安装header
- cd  /hrssc/gbgl/elastic-head/
- npm install# 修改elasticsearch.yml 配置文件,以识别elasticsearch-headhttp.cors.enabled: truehttp.cors.allow-origin: "*"# 重启elasticsearch服务# 后台运行elasticsearch-head
- nohup npm start &# 验证
http://192.168.32.3:9100/

本文标签: MySQL redis mongo ES单机版部署