Centos7 安装MySQL
下载MySQL源
- 再网页复制此链接: https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
- mkdir /home/mysql && cd /home/mysql
- wget
https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
下载
- yum localinstall mysql80-community-release-el7-1.noarch.rpm
- yum install mysql-community-server
运行
- 启动MySQL: systemctl start mysqld
- 重启MySQL: systemctl restart mysqld
- 停止MySQL: systemctl stop mysqld
- 设置开机启动: systemctl enable mysqld
修改初始密码
- grep 'temporary password' /var/log/mysqld.log 来查看默认的初始密码
- 登录MySQL, 修改密码: alter user 'root'@'localhost identified by 'PASSWORD';
- ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD';
添加远程登录
- 选择数据库: use DataBase;
- grant all on . to 'root'@'%'; 或者: update user set host='%' where user='root';
- flush privileges; 刷新权限
卸载MySQL
- yum remove mysql-community-server
- 删除文件: rm -rf /var/lib/mysql
- rm /etc/my.cnf
- rm -rf /usr/share/mysql-8.0
CentOS7防火墙firewalld配置
-
启动: systemctl start firewalld
-
停止: systemctl stop firewalld
-
重启: systemctl restart firewalld.service
-
查看防火墙的状态: systemctl status firewalld
- 设置开机启动: systemctl enable firewalld.service
- 设置开机禁用: systemctl disable firewalld
- 查看是否开机启动: systemctl is-enabled firewalld.service
- 查看已启动的服务列表: systemctl list-unit-files|grep enabled
- 查看启动失败的服务列表:systemctl --failed
- 查看版本:firewall-cmd --version
- 查看帮助:firewall-cmd --help
- 显示状态:firewall-cmd --state
-
查看所有打开的端口:firewall-cmd --zone=public --list-ports
-
更新防火墙规则:firewall-cmd --reload
- 查看区域信息:firewall-cmd --get-active-zones
- 查看指定接口所属区域:firewall-cmd --get-zone-of-interface=eth0
-
开放某个端口: firewall-cmd --zone=public --add-port=80/tcp --permanent
- 查看80端口:firewall-cmd --zone=public --query-port=80/tcp
- firewall-cmd --zone=public --add-port=8888/tcp --permanent
- firewall-cmd --zone=public --add-port=8080/tcp --permanent
- firewall-cmd --zone=public --add-port=21/tcp --permanent
- firewall-cmd --zone=public --add-port=22/tcp --permanent
- firewall-cmd --zone=public --add-port=3306/tcp --permanent
- firewall-cmd --zone=public --add-port=443/tcp --permanent
-
删除80端口:firewall-cmd --zone=public --remove-port=80/tcp --permanent
-
开放端口区间:firewall-cmd --permanent --zone=public --add-port=8080-9999/tcp //永久
- 重新载入使配置立即生效:firewall-cmd --reload
Centos7 安装 Nginx
- 安装pcre库是为了使Nginx支持具备URL重写功能的Rewite模块,如不安装则Nginx无法使用此模块功能(典型功能为伪静态)yum -y install pcre-devel
- 安装编译需要的组件: yum -y install zlib-devel openssl-devel
- 创建软件配套专用的用户(禁止登录及不创建家目录) : [root@localhost ~]# useradd www -s /sbin/nologin -M
- 切换目录 : cd /usr/src/
- 下载: wget http://nginx.org/download/nginx-1.12.2.tar.gz && tar -zxf nginx-1.12.2.tar.gz
--2018-03-02 13:05:56-- http://nginx.org/download/nginx-1.12.2.tar.gz
- cd nginx-1.12.2
- 编译配置文件 : ./configure --user=www --group=www --prefix=/usr/local/nginx-1.12.2 --with-mail_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module
- 编译 : make && make install
- 创建软链接 : ln -s /usr/local/nginx-1.12.2/ /usr/local/nginx
centOS7 安装JDK11
- 检查自带的jdk : rpm -qa |grep jdk
- 如果有输出信息,批量卸载系统自带 : rpm -qa | grep java | xargs rpm -e --nodeps
- 将JDK压缩文件包上传到服务器
- 在 /usr/java 目录中解压压缩包
- vim /etc/profile 在最后面添加(目的就是将Java以及tomcat添加为环境变量):
# java 的配置
export JAVA_HOME=/usr/java/jdk-11.0.6
export CLASPATH=$JAVA_HOME/lib
export CATALINA_HOME=/home/jefxff/www/tomcat/tomcat-a
export CATALINA_2_HOME=/home/jefxff/www/tomcat/tomcat-b
export PATH=$PATH:$JAVA_HOME/bin:$CATALINA_HOME:$CATALINA_2_HOME
编辑tomcat/server.xml以及nginx/nginx/conf进行配置
配置 tomcat-a 和 tomcat-b
- 将tomcat上传到服务器/home/jefxff/www/tomcat/, 并且复制一份, 分别为 tomcat-a 和 tomcat-b
- 配置tomcat-a 和 tomcat-b 的 server.xml
- tomcat-a : server:10800; http:1005; ajp:1009; ajp中添加secretRequired=""
- tomcat-b : server:20800; http:2005; ajp:2009; ajp中添加secretRequired=""
- 配置 tomcat-b /bin/catalina.sh, 在顶部添加
- export CATALINA_BASE=$CATALINA_2_BASE
- export CATALINA_HOME=$CATALINA_2_HOME
- export TOMCAT_HOME=$TOMCAT_2_HOME
配置 /usr/local/nginx/conf/nginx.conf
# 配置tomcat服务
upstream tomcatServer{
ip_hash;
server localhost:1080 weight=1;
server localhost:2080 weight=1;
}
# 在location / 下面添加
proxy_pass http://tomcatServer;
编写用于启动的小脚本
#! /bin/bash
case $1 in
"start" )
echo "[ 启动 ] nginx..."
/usr/local/nginx/sbin/nginx
echo "[ 启动 ] Tomcat-a..."
/home/jefxff/www/tomcat/tomcat-a/bin/startup.sh
echo "[ 启动 ] Tomcat-b..."
/home/jefxff/www/tomcat/tomcat-b/bin/startup.sh
;;
"stop")
echo "[ 关闭 ] nginx..."
/usr/local/nginx/sbin/nginx -s stop
echo "[ 关闭 ] Tomcat-a..."
/home/jefxff/www/tomcat/tomcat-a/bin/shutdown.sh
echo "[ 关闭 ] Tomcat-b..."
/home/jefxff/www/tomcat/tomcat-b/bin/shutdown.sh
;;
"*")
echo "输入指令错误..."
;;
esac