CentOS7配置MySQL、Nginx、Spring Boot

  • CentOS内核和GCC升级
  • 安装MySQL数据库服务器
  • Nginx及其依赖
    • 安装OpenSSL
    • 其他依赖库
    • Nginx
  • Spring Boot配置


CentOS内核和GCC升级

#更新系统内核和程序升级
yum update

#安装centos软件集
yum install centos-release-scl-rh centos-release-scl

#检查组件升级
yum check-update

#安装gcc4
yum install devtoolset-4-gcc devtoolset-4-gcc-c++

#启用gcc
source /opt/rh/devtoolset-4/enable

#验证gcc版本
gcc -v


安装MySQL数据库服务器

#查看旧版本MySQL
rpm -qa|grep mysql
rpm -qa|grep mariadb

#卸载MariaDB
rpm -e --nodeps mariadb

#删除数据目录
ls -l /var/lib|grep mysql
rm -rf /var/lib/mysql

#安装numactl依赖
yum install numactl

#按依赖关系依次安装MySQL组件
rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm 
rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm

#初始化MySQL
cd ../sbin
service mysqld start

#检查mysqld运行状态
service mysqld status

#找到临时登录密码
vi /var/log/mysqld.log

#登录
mysql -uroot -p

#修改root密码
alter user 'root'@'localhost' identified by 'Aa123456';

#添加远程登录用户
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Aa123456' WITH GRANT OPTION;

#检查用户表,刷新内存权限
select host, user from user;
FLUSH PRIVILEGES;


Nginx及其依赖

安装OpenSSL

./config --prefix=/opt/openssl-1.0.2k \
--openssldir=/opt/openssl-1.0.2k/conf \
--shared
make
make test
make install

其他依赖库

yum install gcc.x86_64 gcc-c++.x86_64 libxml2.x86_64 libxml2-devel.x86_64 libxslt.x86_64 libxslt-devel.x86_64 gd.x86_64 gd-devel.x86_64

Nginx

./configure --prefix=/opt/nginx-1.11.13 \
--with-openssl=/root/openssl-1.0.2k \
--with-pcre=/root/pcre-8.40 \
--with-zlib=/root/zlib-1.2.11 \
--with-md5=/opt/openssl-1.0.2k/lib/ \
--with-sha1=/opt/openssl-1.0.2k/lib/ \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_stub_status_module \
--with-http_image_filter_module \
--with-http_auth_request_module \
--with-http_mp4_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-ipv6
make && make install

Nginx测试

#启动、重启测试
/opt/nginx-1.10.1/sbin/nginx
/opt/nginx-1.10.1/sbin/nginx -s reload

#强制停止Nginx
pkill -9 nginx

配置systemctl服务

vi /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=syslog.target network.target
[Service]
Type=forking
ExecStart= /opt/nginx-1.11.13/sbin/nginx
ExecReload= /opt/nginx-1.11.13/sbin/nginx -s restart
ExecStop= /opt/nginx-1.11.13/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

systemctl服务测试

#重载systemctl的守护进程
systemctl daemon-reload

#开启nginx服务
systemctl start nginx
systemctl restart nginx
systemctl stop nginx

#nginx服务开机运行
systemctl enable nginx

#查询nginx服务状态
systemctl status -l nginx

nginx.conf配置
开启gzip
在server:80代码块中加入rewrite ^(.*) https://$host$1 permanent;
底部增加

server {
        listen 443;
        server_name www.application.net; #填写绑定证书的域名

        ssl on;
        ssl_certificate /opt/nginx-1.10.2/conf/nginx_ssl_small.meing.net/1_www.application.net_bundle.crt;
        ssl_certificate_key /opt/nginx-1.10.2/conf/nginx_ssl_small.meing.net/2_www.application.net.key;

        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
        ssl_prefer_server_ciphers on;

        location ^~ /base/ {
            proxy_pass  http://localhost:8080; 
            proxy_redirect default;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location / {
            root /www/index;
            index index.html;
        }
    }


Spring Boot配置

#安装OpenJDK
yum install java-1.8.0-openjdk

将Spring Boot编译后的jar交给systemd管理

vi /usr/lib/systemd/system/application.service

[Unit]
Description=application server
After=syslog.target network.target

[Service]
Type=simple
User=root
ExecStart=/usr/bin/java -jar -Djava.security.egd=file:/dev/./urandom /www/base/com.application.www-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl enable application.server

你可能感兴趣的:(Linux)