CentOS配置Java运行环境
- CentOS 7
- jdk 1.8
CentOS 7 jdk的安装
- 清理系统默认自带的jdk
首先使用rpm -qa | grep jdk
查看一家安装的jdk,然后使用sudo yum remove XXX
(XXX)为上一个命令查询到的结果 - 安装jdk
使用sudo rpm -ivh jdk-xxx-linux-x64.rpm
进行安装,默认安装路径是:/usr/java
- 添加环境变量
使用sudo vim /etc/profile
命令编辑文件,在文件底部增加:使配置生效:1
2
3export JAVA_HOME=/usr/java/jdkx.x.x_xx
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin. /etc/profile
CentOS 7 tomcat的安装
- 到
tomcat
官网https://tomcat.apache.org/
下载对应版本tomcat,这里使用的是apache-tomcat-8.5.40.tar.gz
- 使用
tar -zxvf apache-tomcat-8.5.40.tar.gz
命令解压 - 添加环境变量 使用vim /etc/profile 编辑文件 在底部添加:并在上面增加的
1
2export TOMCAT_HOME=/usr/tomcat
export CATALINA_HOME=/usr/tomcatPATH
路径后面追加上tomcat
的bin
地址1
export PATH=$PATH:$JAVA_HOME/bin:$TOMCAT_HOME/bin
ContOS 7 maven的配置
- 到
maven
官网http://maven.apache.org
下载对应版本maven,这里使用的是apache-maven-3.6.1-bin.tar.gz
- 使用
tar -zxvf apache-maven-3.6.1-bin.tar.gz
命令解压 - 添加环境变量 使用vim /etc/profile 编辑文件 在底部添加:并在上面增加的
1
export MAVEN_HOME=/usr/maven
PATH
路径后面追加上maven
的bin
地址1
export PATH=$PATH:$JAVA_HOME/bin:$TOMCAT_HOME/bin:$MAVEN_HOME/bin
ContOS 7 vsftpd配置
查看是否安装了vsftpd
1
rpm -qa | grep vsftpd
安装vsftpd
1
yum install -y vsftpd
新建ftp根目录
1
mkdir /ftproot
添加一个ftp用户并设置主目录并指定文件的拥有者,和禁止ssh连接(useradd xxx)
1
2
3
4
5
6useradd testftp -d /ftproot/testftp/ -s /sbin/nologin
# 或者
useradd testftp -s /sbin/nologin
usermod testftp -d /ftproot/testftp/
# 指定文件拥有者为创建的用户:
sudo chown -R testftp.testftp ./testftp/给ftp用户添加密码(passwd xxx)
1
sudo passwd testftp
防火墙开放21端口
1
firewall-cmd --zone=public --add-port=21/tcp --permanent
防火墙添加FTP服务
1
2firewall-cmd --permanent --zone=public --add-service=ftp
firewall-cmd --reload无法连接ftp解决办法:
- 查看ftp的Selinux状态:
getsebool -a | grep ftp
1
2
3
4
5
6
7
8
9
10
11
12ftpd_anon_write --> off
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> off
ftpd_use_cifs --> off
ftpd_use_fusefs --> off
ftpd_use_nfs --> off
ftpd_use_passive_mode --> off
httpd_can_connect_ftp --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
tftp_home_dir --> off- 在结果中可以看到:
tftp_home_dir --> off
、ftpd_full_access --> off
- 将状态改为on:
setsebool -P tftp_home_dir on
、setsebool -P ftpd_full_access on
- 重启vsftpd服务:
systemctl restart vsftpd.service
- 重启firewall服务:
systemctl restart firewalld.service
- 查看ftp的Selinux状态:
开启ftp被动模式
- 打开vsftpd.conf文件,在后面加上
1
2pasv_min_port=30000
pasv_max_port=30999并开放30000-30999端口
1
2
3firewall-cmd --zone=public --add-port=30000-30999/tcp --permanent
firewall-cmd --zone=public --add-port=30000-30999/udp --permanent
firewall-cmd --reload设置开机启动vsftpd
1
systemctl enable vsftpd.service
不允许用户切出当前目录(只有在chroot_list_file指定的文件中出现的用户才能切换到上级目录)
1
2
3
4chroot_local_user=YES
chroot_list_enable=NO
chroot_list_file=/etc/vsftpd/chroot_list
allow_writeable_chroot=YESftpusers和user_list 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19vsftpd有两个默认存放用户名单的文件(默认在/etc/vsftpd/ 目录下),来对访问FTP服务的用户身份进行管理和限制。
vsftpd会分别检查两个配置文件,只要是被任何一个文件所禁止的用户,FTP访问到本机的请求都会被拒。
user_list:可以作为用户白名单,或者是黑名单,或者无效名单。完全由userlist_enable和userlist_deny这两个参数决定。
ftpusers:只能是用户黑名单,不受任何参数限制。
userlist_enable和userlist_deny参数
决定user_list文件性质的参数 userlist_enable和userlist_deny
(vsftpd服务程序的主配置文件默认位置 /etc/vsftpd/vsftpd.conf)
userlist_enable=YES userlist_deny=YES 黑名单,拒绝文件中的用户FTP访问
userlist_enable=YES userlist_deny=NO 白名单,拒绝除文件中的用户外的用户FTP访问
userlist_enable=NO userlist_deny=YES/NO 无效名单,表示没有对任何用户限制FTP访问
总之,要想让user_list有效,userlist_enable=YES==注意!!!! 一定要把
/etc/pam.d/vsftpd
文件中的 auth required pam_shells.so给注释掉,否则会检查当前用户是否有登录ssh的权限,为nologin的用户会无法连接ftp==
ContOS 7 安装nginx
- 安装nginx所需要的依赖环境
1
2
3
4
5
6
7
8# gcc
sudo yum install gcc-c++
# pcre
sudo yum install pcre pcre-devel
# zlib
sudo yum install -y zlib zlib-devel
# openssl
sudo yum install openssl openssl-devel - 到
nginx
官网http://nginx.org/en/download.html
下载nginx,并使用命令行解压、安装1
2
3tar -zxvf nginx-1.15.12.tar.gz
cd nginx-1.15.12/
sudo ./configure && make && make install
3.nginx
常用命令
1 | nginx -s reload :修改配置后重新加载生效 |
- 配置
nginx
首先在
conf
目录的nginx.conf
中server:{}结尾后添加一行:include vhost/*.conf;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#user nobody; 如果访问文件服务器 这里修改为ftp的用户名 可以解决403
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
##########################vhost#####################################
include vhost/*.conf; #这里添加一行!!!!!
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}然后新建一个
vhost
文件夹,里面可以放置*.conf
的配置文件,两个简单的配置示例:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34# 配置反向代理到指定端口
server {
listen 80;
autoindex on;
server_name codedog.link;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location / {
proxy_pass http://127.0.0.1:8080/;
}
}
# 配置反向代理到指定目录
server {
listen 80;
autoindex off;
server_name codedog.link;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location / {
root /product/ftpfile/img/;
add_header Access-Control-Allow-Origin *;
}
}
ContOS 7 配置开放端口
ContOS 7 的防火墙是:firewalld
- 基本用法:
- 启动:
systemctl start firewalld
- 查看状态:
systemctl status firewalld
- 停止:
systemctl disable firewalld
- 禁用:
systemctl stop firewalld
- 添加一个端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
- 重新载入:
firewall-cmd --reload
- 查看:
firewall-cmd --zone= public --query-port=80/tcp
- 删除:
firewall-cmd --zone= public --remove-port=80/tcp --permanent
ContOS 7 安装mysql
- 打开
mysql
官网https://www.mysql.com/
下载对应版本yum源的安装包 - 把下载的安装包上传到
CentOS
服务器上 - 执行命令:
yum install mysql-community-server
- 安装完成后使用命令:
service mysqld start
启动mysql - mysql启动后使用
grep 'temporary password' /var/log/mysqld.log
查看安装时默认设置的密码 - 使用命令:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
修改默认密码 - 把root的登录地址修改为任意地址:
update user set host =’%' where user =’root’;