[原]阿里雲服務器 操做實戰 部署C語言開發環境(vim配置,gcc) 部署J2EE網站(jdk,tomcat)

在公司呆久了, 感受全身都生鏽了, 忽然心血來潮, 準備本身用java寫一個網站.java

選來選去, 最終感受阿里雲的服務器性價比蠻高的, 買了一個最便宜的配置用來學習用.python

在家裏配置了一下, 到了公司又不會配置了, 怕忘了寫篇博客記錄下來, 一通配置下來, 發現本身有運維工程師的潛質. c++


一. 配置服務器


1. 阿里雲服務器相關的信息


阿里雲會發一個短信到手機上, 上面有服務器的公網ip, root用戶的用戶名和密碼.apache

先買一個月試用一下.vim



服務器尚未啓用, 統計數據基本沒啥用.centos




20G的磁盤tomcat




2. 使用SecureCRT終端鏈接


(1) 鏈接服務器








此時進入了終端, 界面比較戳 : 服務器




(2) 配置界面 


選項 -> 會話選項 進行以下配置 :app


 


配置完以後的界面 : 運維




界面看起來帥氣多了.



3. 使用xftp上傳文件


打開xftp以後就會彈出下面的對話框, 選擇 New 按鈕;


在這個界面配置鏈接服務器的參數, 注意要選擇SFTP協議, 由於阿里雲服務器默認選擇沒有安裝FTP, 只能使用SFTP協議鏈接;


點擊肯定以後, 就會建立這個鏈接;


選擇想要的鏈接, 點擊connect按鈕, 就能夠鏈接到服務器上了.

root目錄 : 




根目錄 :

 



上傳一個文件示例 : 





二. 配置C語言開發環境


1. 安裝gcc


(1) 配置yum源


yum安裝gcc很容易, 使用 yum -y install gcc 命令, 就能夠安裝gcc編譯器, 可是除了一點問題:


yum命令 : 說明安裝了yum




yum -y install gcc 命令 安裝gcc編譯器 : 安裝失敗, 是由於沒有安裝yum源.




阿里雲的服務器上安裝了yum, 可是沒有配置yum源, 這讓人很鬱悶, 尤爲像我這種運維小白, 查資料吧, 終與搞定了;


yum源在 etc/yum.conf 文件中進行配置 : 


阿里雲服務器中的 yum.conf : 

[main] cachedir=/var/cache/yum keepcache=0 debuglevel=2 logfile=/var/log/yum.log distroverpkg=redhat-release tolerant=1 exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 exclude=*.i?86 kernel kernel-xen kernel-debug  # Note: yum-RHN-plugin doesn't honor this. metadata_expire=1h  # Default. # installonly_limit = 3  # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d

顯然裏面沒有配置yum源, 須要在後面加上下面的內容 : 


[base] name=CentOS-5 - Base baseurl=http://ftp.sjtu.edu.cn/centos/5/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5  [update] name=CentOS-5 - Updates baseurl=http://ftp.sjtu.edu.cn/centos/5/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5  [addons] name=CentOS-5 - Addons baseurl=http://ftp.sjtu.edu.cn/centos/5/addons/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5  [extras] name=CentOS-5 - Extras baseurl=http://ftp.sjtu.edu.cn/centos/5/extras/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5  [centosplus] name=CentOS-5 - Plus baseurl=http://ftp.sjtu.edu.cn/centos/5/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5  #contrib - packages by Centos Users [contrib] name=CentOS-5 - Contrib baseurl=http://ftp.sjtu.edu.cn/centos/5/contrib/$basearch/ gpgcheck=1 enabled=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5  [dag] name=Dag RPM Repository for RHEL5 baseurl=http://ftp.riken.jp/Linux/dag/redhat/el5/en/$basearch/dag/

將yum源追加到 etc/yum.conf 配置文件中便可. 


(2) GPG keys 錯誤


因爲yum安裝了不一樣版本的 GPG keys, 會出現下面的錯誤 : 

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897


此時解決方法 : 執行 rpm --import http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5 命令 便可解決該問題;


(3) 安裝gcc編譯器


執行 yum -y install gcc 命令, 便可成功安裝gcc編譯器.


[root@AY13120614215362640bZ ~]# yum -y install gcc addons                                                                                                                                | 1.9 kB     00:00      base                                                                                                                                  | 1.1 kB     00:00      contrib                                                                                                                               | 1.9 kB     00:00      dag                                                                                                                                   | 1.9 kB     00:00      extras                                                                                                                                | 2.1 kB     00:00      update                                                                                                                                | 1.9 kB     00:00      Excluding Packages in global exclude list Finished Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package gcc.x86_64 0:4.1.2-54.el5 set to be updated --> Finished Dependency Resolution  Dependencies Resolved  =============================================================================================================================================================  Package                           Arch                                 Version                                     Repository                          Size ============================================================================================================================================================= Installing:  gcc                               x86_64                               4.1.2-54.el5                                base                               5.3 M  Transaction Summary ============================================================================================================================================================= Install      1 Package(s)          Update       0 Package(s)          Remove       0 Package(s)           Total download size: 5.3 M Downloading Packages: gcc-4.1.2-54.el5.x86_64.rpm                                                                                                           | 5.3 MB     00:00      Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction   Installing     : gcc                                                                                                                                   1/1   Installed:   gcc.x86_64 0:4.1.2-54.el5                                                                                                                                    Complete!

驗證gcc安裝成功 : 輸入 gcc --help 命令


[root@AY13120614215362640bZ ~]# gcc --help Usage: gcc [options] file... Options:   -pass-exit-codes         Exit with highest error code from a phase   --help                   Display this information   --target-help            Display target specific command line options   (Use '-v --help' to display command line options of sub-processes)   -dumpspecs               Display all of the built in spec strings   -dumpversion             Display the version of the compiler   -dumpmachine             Display the compiler's target processor   -print-search-dirs       Display the directories in the compiler's search path   -print-libgcc-file-name  Display the name of the compiler's companion library   -print-file-name=<lib>   Display the full path to library <lib>   -print-prog-name=<prog>  Display the full path to compiler component <prog>   -print-multi-directory   Display the root directory for versions of libgcc   -print-multi-lib         Display the mapping between command line options and                            multiple library search directories   -print-multi-os-directory Display the relative path to OS libraries   -Wa,<options>            Pass comma-separated <options> on to the assembler   -Wp,<options>            Pass comma-separated <options> on to the preprocessor   -Wl,<options>            Pass comma-separated <options> on to the linker   -Xassembler <arg>        Pass <arg> on to the assembler   -Xpreprocessor <arg>     Pass <arg> on to the preprocessor   -Xlinker <arg>           Pass <arg> on to the linker   -combine                 Pass multiple source files to compiler at once   -save-temps              Do not delete intermediate files   -pipe                    Use pipes rather than intermediate files   -time                    Time the execution of each subprocess   -specs=<file>            Override built-in specs with the contents of <file>   -std=<standard>          Assume that the input sources are for <standard>   --sysroot=<directory>    Use <directory> as the root directory for headers                            for headers and libraries   -B <directory>           Add <directory> to the compiler's search paths   -b <machine>             Run gcc for target <machine>, if installed   -V <version>             Run gcc version number <version>, if installed   -v                       Display the programs invoked by the compiler   -###                     Like -v but options quoted and commands not executed   -E                       Preprocess only; do not compile, assemble or link   -S                       Compile only; do not assemble or link   -c                       Compile and assemble, but do not link   -o <file>                Place the output into <file>   -x <language>            Specify the language of the following input files                            Permissible languages include: c c++ assembler none                            'none' means revert to the default behavior of                            guessing the language based on the file's extension  Options starting with -g, -f, -m, -O, -W, or --param are automatically  passed on to the various sub-processes invoked by gcc.  In order to pass  other options on to these processes the -W<letter> options must be used.  For bug reporting instructions, please see: <URL:http://bugzilla.redhat.com/bugzilla>.


2. 配置vim編輯器


一個好的vim編譯器配置, 能讓開發效率提高十倍, 這裏推薦一個vim編輯器的配置文件 : 

vimrc 文件 下載地址 : http://download.csdn.net/detail/han1202012/6684437 

使用xftp工具直接上傳到服務器的 root下.


vim編輯器在secureCRT上的效果 : 




有高亮顯示, 有代碼自動提示;


藍色註釋看得太費眼了, 改爲綠色註釋, 在vimrc文件中加上 hi Comment ctermfg=green , 能夠將註釋顏色改成綠色;




暫時就這樣配置了, 若是有進一步的改進, 在繼續在這篇博客上繼續改進.


3. 編譯運行C語言程序 


編譯剛纔的文件 : 


執行成功, C語言開發環境安裝完畢!



三. 配置J2EE運行環境


1. 安裝tomcat


(1) 下載tomcat

tomcat下載地址 : http://tomcat.apache.org/download-60.cgi

地址欄輸入下面地址可下載 : http://mirror.esocc.com/apache/tomcat/tomcat-6/v6.0.37/bin/apache-tomcat-6.0.37-deployer.tar.gz 


使用xftp將tomcat上傳到阿里雲服務器上, 將tomcat安裝到一個目錄中, 在目錄同級建立一個app目錄, 用來存放網站源碼, war包.




(2) 安裝配置tomcat


使用 tar xvfz apache-tomcat-6.0.37 命令 解壓tar.gz文件到當前文件;




解壓完成後 : 




爲了方面起見, 更改tomcat目錄以及其子目錄下全部文件的訪問權限爲755 :  使用 chmod -R 755 目錄名/* 能夠改變該目錄下全部子文件的訪問權限. 




修改tomcat/conf/server.xml配置 :  在這個文件中添加Context配置, 這個配置指向網站源文件目錄 : 




在app目錄中存放網站的源文件 : 




(3) 啓動tomcat


啓動腳本位置在tomcat根目錄中的 bin 下的 startup.sh, 執行這個腳本文件 便可啓動tomcat .




查看啓動日誌 : 




啓動 tomcat成功;


此時訪問 : http://115.28.42.124:8080 便可訪問該網站, 只是個demo.


2. 期間的一些排錯


好坎坷, 出了好多錯誤, 不過還好都解決了


tomcat啓動端口占用問題 :  執行 ps -ef|grep java 能夠查看java相關的進程




殺死被佔用的進程 : kill -9 31658 就能夠將該tomcat終止;


查看tomcat日誌 命令 : tail -f -n 200 文件名 

其中的-f 是 日誌滾動, -n 200 指定顯示多少航日誌 


vim編輯器複製 : ctrl + shift + c 

vim編輯器粘貼 : ctrl + shift + v


網站地址 : http://115.28.42.124:8080 終於部署好了

360是流氓啊 啥都沒放就說個人網站有病毒 

相關文章
相關標籤/搜索