主要使用Nginx和vsftpd. 安裝方面可以直接從nginx官網(wǎng)上下載,或者...
yum install nginx 如果沒(méi)有yum源則需要自行添加再進(jìn)行install.
yum install wgetwget http://www.atomicorp.com/installers/atomic sh ./atomic yum check update 系統(tǒng)環(huán)境可能有少許差異,執(zhí)行以下命令,把缺少的東西補(bǔ)上:
yum install gcc-c++yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel如果是從官網(wǎng)上下載的則進(jìn)行如下操作:
[root@admin local]# cd /usr/local[root@admin local]# tar -zxv -f nginx-1.7.7.tar.gz[root@admin local]# rm -rf nginx-1.7.7.tar.gz[root@admin local]# mv nginx-1.7.7 nginx[root@admin local]# cd /usr/local/nginx./configure時(shí)可能由于系統(tǒng)上的差異需要親自指定一些東西,比如加上參數(shù)--with-openssl之類(lèi):
[root@admin nginx]# ./configure --PRefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf[root@admin nginx]# make[root@admin nginx]# make install
修改防火墻配置:
vim /etc/sysconfig/iptables添加配置項(xiàng)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT重啟防火墻和網(wǎng)絡(luò)配置
service iptables restart /etc/init.d/network restart安裝vsftpd:
yum install vsftpd 配置首先確認(rèn)一下nginx指向的配置文件是/usr/local/nginx/conf/nginx.conf執(zhí)行:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf對(duì)nginx沒(méi)有做太復(fù)雜的配置,僅僅是創(chuàng)建了一個(gè)虛擬目錄并打開(kāi)了目錄瀏覽功能。我想訪問(wèn)http://localhost/apps時(shí)實(shí)際訪問(wèn)的路徑是/home/appmanager/首先我需要在nginx/html下創(chuàng)建一個(gè)apps文件夾,盡管實(shí)際訪問(wèn)的不是這個(gè)路徑。
mkdir /usr/local/nginx/html/apps然后修改nginx/conf/nginx.conf在默認(rèn)的server里再添加一個(gè)location并指定實(shí)際路徑:
location /apps/ { root /home/appmanager/; #alias ; autoindex on; #autoindex_exact_size off; #autoindex_localtime on;} autoindex on便是打開(kāi)瀏覽功能。 root則是將apps映射到/home/appmanager/apps/當(dāng)然,alias也可以實(shí)現(xiàn)我想要的效果,只是用法上和root稍有差異。
接著需要?jiǎng)?chuàng)建用戶,就是上面配置文件中的appmanager。
useradd -d /home/appmanager -M appmanager接著指定目錄并加入權(quán)限
chown appmanager /home/appmanagerchmod 777 -R /home/appmanager不知是什么原因,我第一次創(chuàng)建的用戶的目錄總是不生效,雖然多次進(jìn)行usermod -d也毫無(wú)效果....
無(wú)論如何現(xiàn)在可以通過(guò)Jsch api訪問(wèn)了。
public static void main(String[] args) throws JSchException { session session = null; ChannelSftp channelSftp = null; try { JSch.setLogger(new JSCHLogger()); JSch jsch = new JSch(); session = jsch.getSession("appmanager", "101.x.x.x", "22"); session.setPassWord("password"); Properties config = new Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); channelSftp = (ChannelSftp) session.openChannel("sftp"); channelSftp.connect(); } catch (JSchException | SftpException | IOException e) { logger.error(e.getMessage(), e); } finally { if (channelSftp != null) { channelSftp.disconnect(); } if (session != null) session.disconnect(); }}新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注