1. 程式人生 > >從零開始在阿里雲上搭建伺服器(CentOS 6.8系統)

從零開始在阿里雲上搭建伺服器(CentOS 6.8系統)

一.登陸後建立一個新使用者(例如 mirror)

useradd mirror

passwd mirror

輸入兩次密碼

二.安裝圖形介面:

yum groupinstall "Desktop" "X Window System" "Chinese Support" "Internet Browser" "Fonts"

vi /etc/inittab

將3改成5

reboot

用mirror登陸

三.配置LNMP環境

1.基礎設定:

1)關閉SELINUX

修改配置檔案,重啟服務後永久生效。

# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

命令列設定立即生效。

# setenforce 0

2)安全組設定

在ECS安全組放行需訪問的埠和訪問白名單,下面的示例表示允許所有IP訪問伺服器的80埠。您可以根據實際情況放行允許訪問的客戶端IP。

圖片1


2.安裝nginx

1)新增執行nginx服務程序的使用者

  1. # groupadd -r nginx
  2. # useradd -r -g nginx nginx

2)下載原始碼包解壓編譯。

  1. # wget http://nginx.org/download/nginx-1.10.2.tar.gz
  2. # tar xvf nginx-1.10.2.tar.gz -C /usr/local/src
  3. # yum groupinstall "Development tools"
  4. # yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
  5. # cd /usr/local/src/nginx-1.10.2
  6. # ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --user=nginx --group=nginx --with-pcre --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-threads --with-stream --with-stream_ssl_module
  7. # make && make install
  8. # mkdir -pv /var/tmp/nginx/client

3)新增SysV啟動指令碼。

  1. # vim /etc/init.d/nginx
  2. #!/bin/sh
  3. #
  4. # nginx - this script starts and stops the nginx daemon
  5. #
  6. # chkconfig: - 85 15
  7. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  8. # proxy and IMAP/POP3 proxy server
  9. # processname: nginx
  10. # config: /etc/nginx/nginx.conf
  11. # config: /etc/sysconfig/nginx
  12. # pidfile: /var/run/nginx.pid
  13. # Source function library.
  14. ./etc/rc.d/init.d/functions
  15. # Source networking configuration.
  16. ./etc/sysconfig/network
  17. # Check that networking is up.
  18. ["$NETWORKING"="no"]&& exit 0
  19. nginx="/usr/sbin/nginx"
  20. prog=$(basename $nginx)
  21. NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  22. [-f /etc/sysconfig/nginx ]&&./etc/sysconfig/nginx
  23. lockfile=/var/lock/subsys/nginx
  24. start(){
  25. [-x $nginx ]|| exit 5
  26. [-f $NGINX_CONF_FILE ]|| exit 6
  27. echo -n $"Starting $prog: "
  28. daemon $nginx -c $NGINX_CONF_FILE
  29. retval=$?
  30. echo
  31. [ $retval -eq 0]&& touch $lockfile
  32. return $retval
  33. }
  34. stop(){
  35. echo -n $"Stopping $prog: "
  36. killproc $prog -QUIT
  37. retval=$?
  38. echo
  39. [ $retval -eq 0]&& rm -f $lockfile
  40. return $retval
  41. killall -9 nginx
  42. }
  43. restart(){
  44. configtest ||return $?
  45. stop
  46. sleep 1
  47. start
  48. }
  49. reload(){
  50. configtest ||return $?
  51. echo -n $"Reloading $prog: "
  52. killproc $nginx -HUP
  53. RETVAL=$?
  54. echo
  55. }
  56. force_reload(){
  57. restart
  58. }
  59. configtest(){
  60. $nginx -t -c $NGINX_CONF_FILE
  61. }
  62. rh_status(){
  63. status $prog
  64. }
  65. rh_status_q(){
  66. rh_status >/dev/null 2>&1
  67. }
  68. case"$1"in
  69. start)
  70. rh_status_q && exit 0
  71. $1
  72. ;;
  73. stop)
  74. rh_status_q || exit 0
  75. $1
  76. ;;
  77. restart|configtest)
  78. $1
  79. ;;
  80. reload)
  81. rh_status_q || exit 7
  82. $1
  83. ;;
  84. force-reload)
  85. force_reload
  86. ;;
  87. status)
  88. rh_status
  89. ;;
  90. condrestart|try-restart)
  91. rh_status_q || exit 0
  92. ;;
  93. *)
  94. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  95. exit 2
  96. esac

4)賦予指令碼執行許可權。

# chmod +x /etc/init.d/nginx

5)新增至服務管理列表,設定開機自啟。

  1. # chkconfig --add nginx
  2. # chkconfig nginx on

6)啟動服務。

# service nginx start

7)瀏覽器訪問可看到預設歡迎頁面。

3.安裝mysql

1)準備編譯環境。

  1. # yum groupinstall "Server Platform Development" "Development tools" -y
  2. # yum install cmake -y

2)準備mysql資料存放目錄。

  1. # mkdir /mnt/data
  2. # groupadd -r mysql
  3. # useradd -r -g mysql -s /sbin/nologin mysql
  4. # id mysql

3)更改資料目錄屬主屬組。

# chown -R mysql:mysql /mnt/data

4)解壓編譯在MySQL官網下載的穩定版原始碼包

wget -c https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.18.tar.gz

不要感覺奇怪,其實是記憶體不夠導致的,這位兄弟也遇到一樣的問題,如下:
在這裡特別提醒, 對於mysql5.7.8的make編譯, 如果是阿里雲centos主機512M記憶體的, 會在make編譯到45%時會報錯, 這是記憶體不足所致。


c++: Internal error: Killed (program cc1plus)
Please submit a full bug report.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: *** [sql/CMakeFiles/sql.dir/item_geofunc.cc.o] Error 1
make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
make: *** [all] Error 2
那麼設定2G交換分割槽來用下 :


# dd if=/dev/zero of=/swapfile bs=1k count=2048000 --獲取要增加的2G的SWAP檔案塊
# mkswap /swapfile     -- 建立SWAP檔案
# swapon /swapfile     -- 啟用SWAP檔案
# swapon -s            -- 檢視SWAP資訊是否正確
# echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab     -- 新增到fstab檔案中讓系統引導時自動啟動
注意, swapfile檔案的路徑在/var/下 
編譯完後, 如果不想要交換分割槽了, 可以刪除:


# swapoff /swapfile
# rm -fr /swapfile

  1. # tar xvf mysql-5.6.36.tar.gz -C /usr/local/src
  2. # cd /usr/local/src/mysql-5.6.36
  3. # cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mnt/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
  4. # make && make install

5)修改安裝目錄的屬組為mysql。

# chown -R mysql:mysql /usr/local/mysql/

6)初始化資料庫。

# cd /usr/local/mysql/

# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/mnt/data/

# cd /usr/local/src/mysql-5.6.36

注:在CentOS 6.8版作業系統的最小安裝完成後,在/etc目錄下會存在一個my.cnf,需要將此檔案更名為其他的名字,如:/etc/my.cnf.bak,否則,該檔案會干擾原始碼安裝的MySQL的正確配置,造成無法啟動。

7、拷貝配置檔案和啟動指令碼。

  1. # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
  2. # chmod +x /etc/init.d/mysqld
  3. # cp support-files/my-default.cnf /etc/my.cnf

8)設定開機自動啟動。

  1. # chkconfig mysqld on
  2. # chkconfig --add mysqld

9)修改配置檔案中的安裝路徑及資料目錄存放路徑。

# echo -e "basedir = /usr/local/mysql\ndatadir = /mnt/data\n" >> /etc/my.cnf

10)設定PATH環境變數。

  1. # echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
  2. # source /etc/profile.d/mysql.sh

11)啟動服務。

  1. # service mysqld start
  2. # mysql -h 127.0.0.1

4.安裝php

1)安裝依賴包。

  1. # yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel

2)解壓官網下載的原始碼包,編譯安裝。

  1. # tar xvf php-5.6.23.tar.bz2 -C /usr/local/src
  2. # cd /usr/local/src/php-5.6.23
  3. # ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/etc/php.d --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-openssl -enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-bz2
  4. # make && make install

3)新增php和php-fpm配置檔案。

  1. # cp /usr/local/src/php-5.6.23/php.ini-production /etc/php.ini
  2. # cd /usr/local/php/etc/
  3. # cp php-fpm.conf.default php-fpm.conf
  4. # sed -i '[email protected];pid = run/[email protected] = /usr/local/php/var/run/[email protected]' php-fpm.conf

4)新增php-fpm啟動指令碼。

  1. # cp /usr/local/src/php-5.6.23/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  2. # chmod +x /etc/init.d/php-fpm

5)新增php-fpm至服務列表並設定開機自啟。

  1. # chkconfig --add php-fpm
  2. # chkconfig --list php-fpm
  3. # chkconfig php-fpm on

6)啟動服務。

# service php-fpm start

7)新增nginx對fastcgi的支援,首先備份預設的配置檔案。

  1. # cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
  2. # cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf

編輯/etc/nginx/nginx.conf,在所支援的主頁面格式中新增php格式的主頁,類似如下:

  1. location /{
  2. root /usr/local/nginx/html;
  3. index index.php index.html index.htm;
  4. }

取消以下內容前面的註釋:

  1. location ~ \.php$ {
  2. root /usr/local/nginx/html;
  3. fastcgi_pass 127.0.0.1:9000;
  4. fastcgi_index index.php;
  5. fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
  6. include fastcgi_params;
  7. }

重新載入nginx的配置檔案。

# service nginx reload

在/usr/local/nginx/html/新建index.php的測試頁面,內容如下。

  1. <?php
  2. $conn=mysql_connect('127.0.0.1','root','');
  3. if($conn){
  4. echo "LNMP platform connect to mysql is successful!";
  5. 相關推薦

    開始阿里搭建伺服器CentOS 6.8系統

    一.登陸後建立一個新使用者(例如 mirror) useradd mirror passwd mirror 輸入兩次密碼 二.安裝圖形介面: yum groupinstall "Desktop" "X Window System" "Chinese Support" "I

    開始,ubuntu 搭建xilinx zynq linux 編譯環境

    主機環境:ubuntu10.04 lts X64_64bit 編譯器:arm gnu tools for Xilinx  參考網址:http://wiki.xilinx.com/zynq-tools(這個網址的內容真的需要更新了)  詳細步驟:以下操作均在root使用者下

    阿里搭建RabbitMQ1

      剛好有點閒錢,在雙十二上買了一個阿里雲伺服器,買完之後頓時就後悔了,發現騰訊雲比阿里雲更便宜,這是購買阿里雲的心得,下面開始安裝RabbitMQ了 -----------------------------------------------------------------

    阿里安裝LAMPcentos6+Apache+Mysql+PHP環境並上線Java Web專案

    在雲伺服器上安裝好系統後: 1.先檢視系統上有無原有的舊版本的mysql;tomcat;java。 若有則先解除安裝;解除安裝命令使用 yum -y remove mysql*; yum -y remove mysql*; 2.附上能下載的jdk1.7的

    簡述使用BIND配置本地DNS伺服器centos 6.8

    DNS簡介: DNS,Domain Name System,域名系統,用於Internet上域名和IP地址的相互對映,使得使用者不用記憶主機IP地址,僅通過與之對應的域名就可以訪問該主機。 下面是本地dns伺服器搭建過程,環境-centos6.8,本地I

    阿里搭建自己的git伺服器

    這篇文章我就來介紹一下如何在一臺全裸的阿里雲主機上搭建自己的git伺服器。 1. 安裝git 首先安裝git,一般而言,現在的伺服器已經內建了git安裝包,我們只需要執行簡單的安裝命令即可安裝。比如: $ yum install git # centos $ apt-get install git #

    阿里搭建webRTC 伺服器——Licode

    阿里雲上搭建webRTC 伺服器——Licode 系統配置 阿里雲伺服器 Ubuntu 14.04.5 LTS Docker 環境搭建 在一臺空的機器上搭建docker環境,先要安裝docker,執行下面的命令即可: apt-get update apt-get install docker.io

    阿里搭建Git 伺服器

    作業系統: CentOS 6.5 客戶端作業系統:Mac 1、安裝Git $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

    [轉]開始:在Linux覆蓋安裝WINDOWS通用教程(dd)

    備份 虛擬 livecd tfs ocean syntax 文件夾 尋找 font 完整自制尚不方便,還有許多改進的地方.現在可以達到在單硬盤,無救援模式的情況下安裝Winodws.再也不需要強制要求內存大於鏡像包大小了. 本例所給的wget後鏈接均可用,教程是完整的. (

    開始利用vue-cli搭建簡單音樂網站

    路徑 nod .com mman csdn desc blog -a where 最近在學習vue框架,練習了一些例子之後,想著搭建一個vue項目,了解到官方有提供一個vue-cli工具來搭建項目腳手架,嘗試了一下,寫下博客來記錄一下。 一、工具環境 1、node.js 6

    開始系列之vue全家桶4帶新手小白一起搭建第一個個人網站項目

    轉載 個人網站 rfi red nbsp oot ott osx 全部 未經允許,嚴禁轉載,全文由blackchaos提供。 在安裝好了前面大部分需要的插件,我們開始進行第一個個人項目。結合vue+vuex+vue-cli+vue-router+webpack使用。

    [開始]在Jenkins配置P4

    log 圖片 isa http perf nbsp jenkin 管理 從零開始 P4+Jenkins 1. 安裝啟動jenkins   (1) Jenkins下載地址:https://jenkins.io/download/   (2) 配置Jenkins工作空間 系統管

    基於docker在阿里搭建WordPress個人部落格

    環境 centos7.4 安裝docker見https://blog.csdn.net/weixin_38280090/article/details/83590192 下載image docker pull wordpress:latest #下載wordpress在dockerh

    開始使用vue-cli搭建一個vue專案及注意事項

    一、安裝node.js   1.根據電腦的自行下載node.js安裝包http://nodejs.cn        2.點選安裝,按照正常的的一路點選下去   3.驗證安裝是否成功,按鍵win+r,輸入cmd開啟命令列工具,點選確認後再輸入node -v 出現版本好說明npm安裝成功  

    開始使用vue-cli搭建一個vue項目及註意事項

    pack 註意 csharp and init 腳手架 project rect node.js安裝 一、安裝node.js   1.根據電腦的自行下載node.js安裝包http://nodejs.cn        2.點擊安裝,按照正常的的一路點擊下去   3.驗

    阿里搭建DOCKER環境

    前言 最近公司要為新專案搭建一套演示環境,服務比較多。所以準備用docker進行容器化部署。 安裝/升級Docker客戶端 使用yum進行安裝 # step 1: 安裝必要的一些系統工具 sudo yum install -y yum-utils devic

    開始的Hadoop大資料叢集搭建,全免費VirtualBox虛擬機器Ubuntu版,學習向,超詳細---

         在公司工作了一段時間了,大資料平臺都是公司的運維人員搭建維護的,自己也想親自搭建一套,純粹為了學習和提高自己,也為了以後自己研究用。公司的環境不太適合亂來,自己的就可以隨意玩了。     寫這個也是為了記錄自己學習的過程,同時給大家提供一個參考,想要學習大資料的也

    手把手教你如何開始在eclipse搭起一個ssmspring+springMVC+myBatis框架

    1.新建一個Maven專案 直接點選next: 選擇這個,這個是指javaWeb專案 輸入maven專案的座標 點選finish,建立專案完成 2.新增maven依賴並下載 找到剛建的maven專案下的pom.xml配置檔案,開啟: 接下來,在url和depe

    開始學習--kafka叢集搭建的 兩種方式

    目錄(第一種常規版,第二種bitnami版)  一、下載kafka安裝包 二、安裝 三、配置 四、執行   一、下載kafka安裝包  準備好kafka安裝包,官網下載地址: http://kafka.apache.org/do

    開始hadoop分散式環境搭建

    1. Linux虛機換機環境安裝 1.1 linux環境安裝 1.建議選擇虛擬機器:VirtualBox 2.Linux版本:Ubuntu 3.安裝時選擇動態擴充套件磁碟,最大磁碟容量50G(最大磁碟容量太小,hadoop使用過程中容易出現意想不到的