首先进行系统安装,此处不进行详细介绍,自行百度安装
cd /etc/sysconfig/network-scripts/
ls
vi ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #静态ip
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=3ae4be2f-7000-4147-8ac2-c5a4fa848f31
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.1.100 #ip地址
NETMASK=255.255.255.0 #子网掩码
GATEWAY=192.168.1.1 #网关
DNS1=202.99.160.68 #dns
DNS2=202.99.166.4
ZONE=public
service network restart
ping www.baidu.com
详细页面
firewall-cmd --state
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all
rpm -qa|grep -E "openssh"
sudo yum install openssh*
sudo systemctl enable sshd
service sshd start
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --reload
yum -y install wget
wget http://mirrors.aliyun.com/repo/Centos-7.repo
cp Centos-7.repo /etc/yum.repos.d/
rm -rf Centos-7.repo
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
mv Centos-7.repo CentOS-Base.repo
yum clean all
yum makecache
yum update
yum -y install vim*
cd /usr/local/
wget http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.tar.gz?AuthParam=1531973178_bfda57895bf56fc4e64f754387fe008d
tar -zxvf jdk-8u181-linux-x64.tar.gz\?AuthParam\=1531973178_bfda57895bf56fc4e64f754387fe008d
rm -rf jdk-8u181-linux-x64.tar.gz\?AuthParam\=1531973178_bfda57895bf56fc4e64f754387fe008d
mv jdk1.8.0_181/ jdk1.8
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
source /etc/profile
java
出现以下情况成功
cd /usr/local/
wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v8.0.53/bin/apache-tomcat-8.0.53.tar.gz
tar -zxvf apache-tomcat-8.0.53.tar.gz
rm -rf apache-tomcat-8.0.53.tar.gz
mv apache-tomcat-8.0.53/ tomcat8
cd /root
ln -s /usr/local/tomcat8/ tomcat8
vim /etc/init.d/tomcat8
#!/bin/bash
#
## description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
export JAVA_HOME=/usr/local/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
CATALINA_HOME=/usr/local/tomcat8
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
chmod a+x /etc/init.d/tomcat8
chkconfig tomcat8 on
启动:service tomcat8 start
重启:service tomcat8 restart
关闭:service tomcat8 stop
申领ssl证书(百度云、阿里云、腾讯云都有免费证书)
1、首先将申请好的证书下载解压,上传到服务器上,我上传到了tomcat目录下的ssl_cert文件夹下
2、 修改tomcat/conf 文件夹的 server.xml文件,开启https
#默认开启8080端口,并且自动转发到8443这是tomcat自带代码不用修改
#在他下边添加一下代码,开启8443端口作为tomcat的ssl端口,如果未使用其他服务器(nginx)建议将8080换成80,8443换成443这样访问时不用加端口号默认http是80https是443
3、修改域名对应路径webapps位置
#appBase这个目录下面的子目录将自动被部署为应用,且war文件将被自动解压缩并部署为应用,默认为tomcat下webapps目录,如果不想访问默认ROOT目录,修改这里,同理如果想访问配置目录下应用为默认应用,在此目录下新增ROOT目录文件夹。
域名1
域名2
# 设置默认项目名称 path 位虚拟目录网址 docBase 为实际目录,访问域名时会访问appBase路径/docBase路径查找项目,可设置为空
这里的关键在于
4、 如需配置两个域名访问不同的项目,则按照如下配置
#域名1服务
#域名2服务
cd /usr/local/
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
rm -rf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
#.tar.xz解压
xz -d mysql-5.7.22-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar
rm -rf mysql-5.7.22-linux-glibc2.12-x86_64.tar
mv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
mkdir /usr/local/mysql/data
groupadd mysql
useradd mysql -g mysql
chown -R mysql.mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
# 如果出现以下错误:
2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-07-14 06:40:32 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2018-07-14 06:40:32 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --
-- server log end --
# 则使用以下命令:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 如果出现以下错误:
2018-12-12T08:47:44.114511Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-12T08:47:44.116565Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-12-12T08:47:44.116618Z 0 [ERROR] Aborting
# 则使用以下命令:
/usr/local/mysql5.7/bin/mysqld --user=mysql --basedir=/usr/local/mysql5.7/ --datadir=/usr/local/mysql5.7/data --explicit_defaults_for_timestamp
# 如果出现以下错误:
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# 则执行以下命令:
yum -y install numactl
# 则执行以下命令:
yum -y install numactl
# 完成后继续安装:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 将mysql加入服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# 开机自启
chkconfig mysql on
# 开启
service mysql start
# 登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)
/usr/local/mysql/bin/mysql -u root -p
# 操作mysql数据库
>>use mysql;
# 修改密码
>>update user set authentication_string=password('你的密码') where user='root';
>>flush privileges;
>>exit;
#mysql8.0以上
mysql> use mysql;
#先把密码置为空字符串;(不让后面修改密码会报错)
mysql> use mysql;
mysql> update user set authentication_string="" where user="root";
#这个刷新非常有必要;不让后面执行alter就会出错
mysql> flush privileges;
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
10、将/etc/my.cnf中的skip-grant-tables删除(注释掉 前边加上#)
vim /etc/my.cnf
/usr/local/mysql/bin/mysql -u root -p
>>ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码';
>>exit;
/usr/local/mysql/bin/mysql -u root -p
>>use mysql;
>>update user set host='%' where user = 'root';
>>flush privileges;
>>exit;
ln -s /usr/local/mysql/bin/mysql /usr/bin
yum install wget gcc gcc-c++ pcre-devel zlib-devel
cd /usr/local/
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar zxvf nginx-1.14.0.tar.gz
rm -rf nginx-1.14.0.tar.gz
mv nginx-1.14.0/ nginx1.14
cd nginx1.14
./configure
make && make install
vim /etc/init.d/nginx
#! /bin/bash
# Startup script for the nginx Web Server
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: nginx
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
设置执行权限
chmod a+x /etc/init.d/nginx
注册成服务
chkconfig --add nginx
设置开机启动
chkconfig nginx on
重启, 查看nginx服务是否自动启动
shutdown -h 0 -r
netstat -apn|grep nginx
#启动nginx服务
/etc/init.d/nginx start
#systemctl start nginx.service
#停止nginx服务
/etc/init.d/nginx stop
#systemctl stop nginx.service
#重启nginx服务
/etc/init.d/nginx restart
#systemctl restart nginx.service
#重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效)
#/etc/init.d/nginx reload
#systemctl reload nginx.service
安装OpenSSL
#进入安装路径
cd /usr/local/
#下载OpenSSL
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
#解压
tar zxvf openssl-1.1.1a.tar.gz
#删除压缩包
rm -rf openssl-1.1.1a.tar.gz
#安装
cd openssl-1.1.1a/
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make && make install
#查看版本
openssl version -a
#安装openssl-devel
yum install openssl-devel
添加http_ssl_module模块
.#看下编译安装nginx的时候,都编译安装的哪些模块。
/usr/local/nginx/sbin/nginx -V
#进入之前下载并解压了的源码包目录;重新编译nginx
cd /usr/local/nginx1.14.2/
#开启权限
chmod +x ./configure
#编译
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
#停止nginx
/etc/init.d/nginx stop
#备份一下原来的启动脚本。
cp /etc/init.d/nginx /etc/init.d/nginx.back
#替换nginx二进制文件
cp objs/nginx /usr/local/nginx/sbin/
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? yes
#看看是否启动了对应模块
/usr/local/nginx/sbin/nginx -V
#提示
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
#启动nginx
/etc/init.d/nginx start
#查看是否正常监听80端口
netstat -lnp|grep nginx
cd /usr/local/
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
tar -zxvf redis-4.0.10.tar.gz
rm -rf redis-4.0.10.tar.gz
mv redis-4.0.10/ redis
yum install gcc tcl
cd redis
make MALLOC=libc
cd src && make install
./redis-server
出现以下情况成功(按 ctrl + c可以关闭窗口)
cd /usr/local/redis/
vim redis.conf
1、修改daemonize
将
daemonize no #默认为no
修改为
daemonize yes #后台进程方式改为yes
2、修改bind 配置
将
bind 127.0.0.1 #默认只有本机才能够连接
修改为
bind 0.0.0.0 #所有ip都可以访问(也可修改为限定ip)
3、修改protected-mode配置
将
protected-mode yes #在默认保护模式下启用
修改为
protected-mode no #禁用它,任何client不用认证即可连接
4、修改port端口号
将
port 6379 #默认为6379端口
修改为其他端口
port 6379 #可根据实际情况配置
5、设置密码
将 requirepass foobared
变为
requirepass 你的密码
指定redis.conf文件启动
cd /usr/local/redis/src/
./redis-server ../redis.conf
测试redis
./redis-cli -h 127.0.0.1 -p 6379 -a 你的密码
127.0.0.1:6379> set ko 'ok'
OK
127.0.0.1:6379> keys *
1) "ko"
127.0.0.1:6379> get ko
"ok"
127.0.0.1:6379> exit
关闭redis进程
首先使用ps -aux | grep redis查看redis进程,使用kill命令杀死进程
ps -aux | grep redis
root 2852 0.1 0.2 141832 2028 ? Ssl 16:45 0:00 ./redis-server 127.0.0.1:6379
root 2857 0.0 0.0 112704 976 pts/0 S+ 16:46 0:00 grep --color=auto
redis
kill -9 2852
在/etc目录下新建redis目录
cd /etc/
mkdir redis
将/usr/local/redis/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf
cp /usr/local/redis/redis.conf /etc/redis/6379.conf
将redis的启动脚本复制一份放到/etc/init.d目录下
cp /usr/local/redis/utils/redis_init_script /etc/init.d/redis
设置redis开机自启动 。先切换到/etc/init.d目录下,然后执行自启命令
cd /etc/init.d/
chkconfig redis on
service redis does not support chkconfig
看结果是redisd不支持chkconfig
解决方法:使用vim编辑redis文件(/etc/init.d/redis),在第一行加入如下两行注释,保存退出
# chkconfig: 2345 90 10
# description: Redis is a persistent key-value database
再次执行开机自启命令,成功
chkconfig redis on
启动:
service redis start
关闭:
service redis stop
cd /etc/init.d/
vi /etc/init.d/redis
然后
配置密码常量 PWD=你的密码
将关闭处代码更改为
$CLIEXEC -a $PWD -p $REDISPORT shutdown
或
$CLIEXEC -a "root" -p $REDISPORT shutdown
不更改会影响关闭效率。