一、安装JDK
1.创建安装目录
[root@localhost local]# mkdir /usr/local/java/
2.解压到新建目录
[root@localhost local]# tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local/java/
[root@localhost local]# tar -zxvf jdk-8u211-linux-x64.tar.gz -C /usr/local/java/
3.设置环境变量
打开文件
[root@localhost local]# vim /etc/profile
在文件末尾添加
export JAVA_HOME=/usr/local/java/jdk1.8.0_211
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
注: 进入编辑模式:ctrl+g;编辑:输入i ;退出编辑模式:esc;不保存退出文件: :q!;保存退出文件: :wq;
使环境变量生效
[root@localhost local]# source /etc/profile
添加软链接
[root@localhost local]# ln -s /usr/local/java/jdk1.8.0_211/bin/java /usr/bin/java
检查java版本
[root@localhost local]# java -version
二、Centos7安装Redis
1.安装gcc依赖
由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v),如果没有安装,执行以下命令进行安装
[root@localhost local]# cdall -y gcc
### 2.下载并解压安装包
[root@localhost local]# wget http://download.redis.io/releases/redis-5.0.11.tar.gz
[root@localhost local]# tar -zxvf redis-5.0.11.tar.gz
3.cd切换到redis解压目录下,执行编译
[root@localhost local]# cd redis-5.0.11
[root@localhost redis-5.0.11]# make
4.安装并指定安装目录
[root@localhost redis-5.0.11]# make install PREFIX=/usr/local/redis
5.启动服务
5.1前台启动
[root@localhost redis-5.0.11]# cd /usr/local/redis/bin/
[root@localhost bin]# ./redis-server
5.2后台启动
从 redis 的源码目录中复制 redis.conf 到 redis 的安装目录
[root@localhost bin]# cp /data/dam/software/redis-5.0.11/redis.conf /usr/local/redis/bin/
[root@localhost ~]# cp /home/redis/redis.conf /usr/local/redis/bin/
修改 redis.conf 文件,把 daemonize no 改为 daemonize yes
[root@localhost bin]# vi redis.conf
后台启动
[root@localhost bin]# ./redis-server redis.conf
6.设置开机启动
添加开机启动服务
[root@localhost bin]# vi /etc/systemd/system/redis.service
复制粘贴以下内容:
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
注意:ExecStart配置成自己的路径
设置开机启动
[root@localhost bin]# systemctl daemon-reload
[root@localhost bin]# systemctl start redis.service
[root@localhost bin]# systemctl enable redis.service
创建 redis 命令软链接
[root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis
服务操作命令
[root@localhost ~]# systemctl start redis.service #启动redis服务
[root@localhost ~]# systemctl stop redis.service #停止redis服务
[root@localhost ~]# systemctl restart redis.service #重新启动服务
[root@localhost ~]# systemctl status redis.service #查看服务当前状态
[root@localhost ~]# systemctl enable redis.service #设置开机自启动
[root@localhost ~]# systemctl disable redis.service #停止开机自启动
三、centos7 安装zookeeper
1.下载安装包
1)进入安装目录
[root@localhost ~]# cd /home/install/
2)下载安装包
[root@localhost ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/stable/apache-zookeeper-3.5.8-bin.tar.gz
2.解压安装
1)解压至安装目录
//解压
[root@localhost ~]# tar -zxcf /home/install/apache-zookeeper-3.5.8-bin.tar.gz -C /usr/local/
//移动安装目录
[root@localhost ~]# mv /usr/local/apache-zookeeper-3.5.8-bin /usr/local/zookeeper
2)拷贝样本配置为主配置,进入配置目录,赋值拷贝样本文件
[root@localhost ~]# cd /usr/local/zookeeper/conf/
[root@localhost ~]# cp zoo_sample.cfg zoo.cfg
3)创建数据存储目录与日志目录
[root@localhost ~]# mkdir /home/zookeeper/data
[root@localhost ~]# mkdir /home/zookeeper/logs
4)修改数据存储和日志目录
[root@localhost ~]# vim /usr/local/zookeeper/conf/zoo.cfg
3.配置zookeeper环境变量
1)依赖JVM环境,所以JVM与zookeeper环境变量都要配置
[root@localhost ~]# vim /etc/profile
2)在尾部加入或修改以下
export JAVA_HOME=/usr/local/java/jdk1.8.0_211
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
ZOOKEEPER_HOME=/home/zookeeper
PATH=$PATH:$ZOOKEEPER_HOME/bin
export PATH ZOOKEEPER_HOME PATH
3)使其生效
[root@localhost ~]# source /etc/profile
4.测试
1)启动
[root@localhost ~]# /usr/local/zookeeper/bin/zkServer.sh start
2)连接
[root@localhost ~]# /usr/local/zookeeper/bin/zkCli.sh
3)增删改查
略
4)其他,如查看指令帮助
[root@localhost ~]# help
5.开机启动
1)编辑zookeeper.service文件
[root@localhost ~]# vim /usr/lib/systemd/system/zookeeper.service
[root@localhost ~]# vim /etc/systemd/system/zookeeper.service
加入如下内容
[Unit]
Description=zookeeper
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
[Install]
WantedBy=multi-user.target
2)zookeeper.service文件生效
[root@localhost ~]# systemctl daemon-reload
3)设置开机启动
[root@localhost ~]# systemctl enabled zookeeper.service
4)启动
[root@localhost ~]# systemctl start zookeeper.service
5)关闭
[root@localhost ~]# systemctl stop zookeeper.service
6)重启
[root@localhost ~]# systemctl restart zookeeper.service
7)查看是否开机启动
[root@localhost ~]# systemctl is-enabled zookeeper.service
8)systemctl取消开机启动redis
[root@localhost ~]# systemctl disable zookeeper.service
四、centos7安装tomcat
1.准备工作
检查是否有java环境
[root@localhost ~]# java -version
下载tomcat 可本地下载后上传服务器 也可以用wget命令下载
[root@localhost ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.51/bin/apache-tomcat-8.5.51.tar.g
2.安装tomcat
1)新建存放目录
[root@localhost ~]# mkdir /usr/local/tomcat
2)拷贝下载好的 apache-tomcat-8.5.51.tar.gz 到 tomcat目录下
[root@localhost ~]# cp apache-tomcat-8.5.51.tar.gz /usr/local/tomcat/
3)进入tomcat目录,并解压apache-tomcat-8.5.51.tar.gz
[root@localhost ~]# cd /usr/local/tomcat/
[root@localhost tomcat]# tar -zxvf apache-tomcat-8.5.51.tar.gz
4)进入解压的tomcat包的bin目录,并启动tomcat
[root@localhost tomcat]# cd /usr/local/tomcat/apache-tomcat-8.5.51/bin/
[root@localhost bin]# ./catalina.sh start
或:
[root@localhost bin]# ./startup.sh
注: ./catalina.sh start 和 ./startup.sh 都能启动tomcat。使用 ./catalina.sh stop 或 ./shutdown.sh 停止tomcat。
3.服务相关命令
查看 tomcat进程
[root@localhost ~]# ps -ef |grep tomcat
杀掉进程
[root@localhost ~]# kill -9 PID
切换到tomcat目录
[root@localhost ~]# cd /data/tomcat/tomcat80/bin
启动命令/停止命令:
[root@localhost ~]# ./startup.sh
[root@localhost ~]# ./shutdown.sh
查看日志:
[root@localhost ~]# tail -f /data/tomcat/tomcat80/logs/catalina.out
新建备份文件夹
[root@localhost ~]# mkdir 123_bak
备份文件
[root@localhost ~]# mv /data/tomcat/tomcat80/webapps/dcmAdmin /data/ocbackup/123_bak/dcmAdmin
五、centos7安装mysql5.7
1.检查系统是否安装过mysql
[root@localhost ~]# rpm -qa|grep mysql
查询所有mysql 对应的文件夹,全部删除
[root@localhost ~]# whereis mysql
[root@localhost ~]# find / -name mysql
2.卸载CentOS7系统自带mariadb
[root@CDH-141 ~]# rpm -qa|grep mariadb
[root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
查看系统自带的Mariadb
[root@CDH-141 ~]# mariadb-libs-5.5.44-2.el7.centos.x86_64
删除etc目录下的my.cnf,一定要删掉,等下再重新建,之前我就用这个文件,后面改配置各种不生效
[root@CDH-141 ~]# rm /etc/my.cnf
3.检查有无安装过mysql 用户组
检查mysql 用户组是否存在
[root@localhost ~]# cat /etc/group | grep mysql
[root@localhost ~]# cat /etc/passwd |grep mysql
创建mysql 用户组和用户
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
4.下载安装,从官网安装下载
[root@localhost ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
5.解压安装mysql
[root@localhost ~]# tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
//顺便改一下名字
[root@localhost ~]# mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql
6.更改mysql 目录下所有文件夹所属的用户组和用户,以及权限
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql
[root@localhost ~]# chmod -R 755 /usr/local/mysql
7.进入mysql/bin/目录,编译安装并初始化mysql,务必记住数据库管理员临时密码
[root@localhost ~]# ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysq
8.编写配置文件 my.cnf ,并添加配置
进入配置文件
[root@localhost ~]# vi /etc/my.cnf
在插入模式下编写,完成后保存
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
表名大小写不明感,敏感为
[root@localhost ~]# lower_case_table_names=1
9.启动mysql 服务器
查询服务
[root@localhost ~]# ps -ef|grep mysql
[root@localhost ~]# ps -ef|grep mysqld
结束进程
[root@localhost ~]# kill -9 PID
启动服务
[root@localhost ~]# /usr/local/mysql/support-files/mysql.server start
10.添加软链接,并重启mysql 服务
添加软链接
[root@localhost ~]# ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
重启mysql服务
[root@localhost ~]# service mysql restart
11.登录mysql ,密码就是初始化时生成的临时密码
[root@localhost ~]# mysql -u root -p
12.修改密码,因为生成的初始化密码难记,注意: 分号(;) 结尾
[root@localhost ~]# set password for root@localhost = password('root');
13.开放远程连接
[root@localhost ~]# use mysql;
[root@localhost ~]# update user set user.Host='%' where user.User='root';
[root@localhost ~]# flush privileges;
14.设置开机自启
//将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
//赋予可执行权限
[root@localhost ~]# chmod +x /etc/init.d/mysqld
//添加服务
[root@localhost ~]# chkconfig --add mysqld
//显示服务列表
[root@localhost ~]# chkconfig --list
六、开始设置开机启动
1.修改/etc/rc.d/rc.local文档
[root@localhost ~]# vim /etc/rc.d/rc.local
2.在末行添加如下内容
[root@localhost ~]# export JAVA_HOME=/usr/java/jdk1.8.0_211
[root@localhost ~]# /home/ucenter/soft/tomcat-8080/bin/startup.sh
3.重启服务器
[root@localhost ~]# reboot
[root@localhost ~]# ps -ef|grep tomcat-8080
七、Centos7开放及查看端口
1.开放端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=8081/tcp --permanent # 开放5672端口
[root@localhost ~]# firewall-cmd --zone=public --remove-port=5672/tcp --permanent #关闭5672端口
[root@localhost ~]# firewall-cmd --reload # 配置立即生效
2.查看防火墙所有开放的端口
[root@localhost ~]# firewall-cmd --zone=public --list-ports
3..关闭防火墙
如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估
[root@localhost ~]# systemctl stop firewalld.service
4.查看防火墙状态
[root@localhost ~]# firewall-cmd --state
5.查看监听的端口
[root@localhost ~]# netstat -lnpt
注:centos7默认没有 netstat 命令,需要安装 net-tools 工具,yum install -y net-tools
6.检查端口被哪个进程占用
[root@localhost ~]# netstat -lnpt |grep 5672
7.查看进程的详细信息
[root@localhost ~]# ps 6832
8.中止进程
[root@localhost ~]# kill -9 6832
9.mysql 创建用户
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
CREATE USER 'dcm_oct'@'%' IDENTIFIED BY 'dcm_oct_admin';
10.授权
GRANT privileges ON databasename.tablename TO 'dcm_oct'@'%';
11.授权全部权限
GRANT ALL ON *.* TO 'dcm_oct'@'%';
REVOKE SELECT ON *.* FROM 'pig'@'%';