从零开始在阿里云上搭建服务器(CentOS 6.8系统)
2017-12-17 00:00
519 查看
一.登陆后创建一个新用户(例如mirror)
useraddmirror
passwdmirror
输入两次密码
二.安装图形界面:
yumgroupinstall"Desktop""XWindowSystem""ChineseSupport""InternetBrowser""Fonts"
vi/etc/inittab
将3改成5
reboot
用mirror登陆
三.配置LNMP环境
1.基础设置:
1)关闭SELINUX
修改配置文件,重启服务后永久生效。
#sed-i's/SELINUX=.*/SELINUX=disabled/g'/etc/selinux/config
命令行设置立即生效。
#setenforce0
2)安全组设置
在ECS安全组放行需访问的端口和访问白名单,下面的示例表示允许所有IP访问服务器的80端口。您可以根据实际情况放行允许访问的客户端IP。
2.安装nginx
1)添加运行nginx服务进程的用户
#groupadd-rnginx
#useradd-r-gnginxnginx
2)下载源码包解压编译。
#wgethttp://nginx.org/download/nginx-1.10.2.tar.gz
#tarxvfnginx-1.10.2.tar.gz-C/usr/local/src
#yumgroupinstall"Developmenttools"
#yum-yinstallgccwgetgcc-c++automakeautoconflibtoollibxml2-devellibxslt-develperl-develperl-ExtUtils-Embedpcre-developenssl-devel
#cd/usr/local/src/nginx-1.10.2
#./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
#make&&makeinstall
#mkdir-pv/var/tmp/nginx/client
3)添加SysV启动脚本。
#vim/etc/init.d/nginx
#!/bin/sh
#
#nginx-thisscriptstartsandstopsthenginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:nginx
#config:/etc/nginx/nginx.conf
#config:/etc/sysconfig/nginx
#pidfile:/var/run/nginx.pid
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
#Sourcenetworkingconfiguration.
./etc/sysconfig/network
#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0
nginx="/usr/sbin/nginx"
prog=$(basename$nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[-f/etc/sysconfig/nginx]&&./etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start(){
[-x$nginx]||exit5
[-f$NGINX_CONF_FILE]||exit6
echo-n$"Starting$prog:"
daemon$nginx-c$NGINX_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}
stop(){
echo-n$"Stopping$prog:"
killproc$prog-QUIT
retval=$?
echo
[$retval-eq0]&&rm-f$lockfile
return$retval
killall-9nginx
}
restart(){
configtest||return$?
stop
sleep1
start
}
reload(){
configtest||return$?
echo-n$"Reloading$prog:"
killproc$nginx-HUP
RETVAL=$?
echo
}
force_reload(){
restart
}
configtest(){
$nginx-t-c$NGINX_CONF_FILE
}
rh_status(){
status$prog
}
rh_status_q(){
rh_status>/dev/null2>&1
}
case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q||exit7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||exit0
;;
*)
echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit2
esac
4)赋予脚本执行权限。
#chmod+x/etc/init.d/nginx
5)添加至服务管理列表,设置开机自启。
#chkconfig--addnginx
#chkconfignginxon
6)启动服务。
#servicenginxstart
7)浏览器访问可看到默认欢迎页面。
3.安装mysql
1)准备编译环境。
#yumgroupinstall"ServerPlatformDevelopment""Developmenttools"-y
#yuminstallcmake-y
2)准备mysql数据存放目录。
#mkdir/mnt/data
#groupadd-rmysql
#useradd-r-gmysql-s/sbin/nologinmysql
#idmysql
3)更改数据目录属主属组。
#chown-Rmysql:mysql/mnt/data
4)解压编译在MySQL官网下载的稳定版源码包
wget-chttps://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.18.tar.gz
不要感觉奇怪,其实是内存不够导致的,这位兄弟也遇到一样的问题,如下:
在这里特别提醒,对于mysql5.7.8的make编译,如果是阿里云centos主机512M内存的,会在make编译到45%时会报错,这是内存不足所致。
c++:Internalerror:Killed(programcc1plus)
Pleasesubmitafullbugreport.
See<http://bugzilla.redhat.com/bugzilla>forinstructions.
make[2]:***[sql/CMakeFiles/sql.dir/item_geofunc.cc.o]Error1
make[1]:***[sql/CMakeFiles/sql.dir/all]Error2
make:***[all]Error2
那么设置2G交换分区来用下:
#ddif=/dev/zeroof=/swapfilebs=1kcount=2048000--获取要增加的2G的SWAP文件块
#mkswap/swapfile--创建SWAP文件
#swapon/swapfile--激活SWAP文件
#swapon-s--查看SWAP信息是否正确
#echo"/var/swapfileswapswapdefaults00">>/etc/fstab--添加到fstab文件中让系统引导时自动启动
注意,swapfile文件的路径在/var/下
编译完后,如果不想要交换分区了,可以删除:
#swapoff/swapfile
#rm-fr/swapfile
#tarxvfmysql-5.6.36.tar.gz-C/usr/local/src
#cd/usr/local/src/mysql-5.6.36
#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
#make&&makeinstall
5)修改安装目录的属组为mysql。
#chown-Rmysql: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
注:在CentOS6.8版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
7、拷贝配置文件和启动脚本。
#cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
#chmod+x/etc/init.d/mysqld
#cpsupport-files/my-default.cnf/etc/my.cnf
8)设置开机自动启动。
#chkconfigmysqldon
#chkconfig--addmysqld
9)修改配置文件中的安装路径及数据目录存放路径。
#echo-e"basedir=/usr/local/mysql\ndatadir=/mnt/data\n">>/etc/my.cnf
10)设置PATH环境变量。
#echo"exportPATH=$PATH:/usr/local/mysql/bin">/etc/profile.d/mysql.sh
#source/etc/profile.d/mysql.sh
11)启动服务。
#servicemysqldstart
#mysql-h127.0.0.1
#yuminstalllibmcryptlibmcrypt-develmhashmhash-devellibxml2libxml2-develbzip2bzip2-devel
2)解压官网下载的源码包,编译安装。
#tarxvfphp-5.6.23.tar.bz2-C/usr/local/src
#cd/usr/local/src/php-5.6.23
#./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
#make&&makeinstall
3)添加php和php-fpm配置文件。
#cp/usr/local/src/php-5.6.23/php.ini-production/etc/php.ini
#cd/usr/local/php/etc/
#cpphp-fpm.conf.defaultphp-fpm.conf
#sed-i's@;pid=run/php-fpm.pid@pid=/usr/local/php/var/run/php-fpm.pid@'php-fpm.conf
4)添加php-fpm启动脚本。
#cp/usr/local/src/php-5.6.23/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm
#chmod+x/etc/init.d/php-fpm
5)添加php-fpm至服务列表并设置开机自启。
#chkconfig--addphp-fpm
#chkconfig--listphp-fpm
#chkconfigphp-fpmon
6)启动服务。
#servicephp-fpmstart
7)添加nginx对fastcgi的支持,首先备份默认的配置文件。
#cp/etc/nginx/nginx.conf/etc/nginx/nginx.confbak
#cp/etc/nginx/nginx.conf.default/etc/nginx/nginx.conf
编辑/etc/nginx/nginx.conf,在所支持的主页面格式中添加php格式的主页,类似如下:
location/{
root/usr/local/nginx/html;
indexindex.phpindex.htmlindex.htm;
}
取消以下内容前面的注释:
location~\.php${
root/usr/local/nginx/html;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html/$fastcgi_script_name;
includefastcgi_params;
}
重新载入nginx的配置文件。
#servicenginxreload
在/usr/local/nginx/html/新建index.php的测试页面,内容如下。
<?php
$conn=mysql_connect('127.0.0.1','root','');
if($conn){
echo"LNMPplatformconnecttomysqlissuccessful!";
}else{
echo"LNMPplatformconnecttomysqlisfailed!";
}
phpinfo();
?>
浏览器访问测试,如看到以下内容则表示LNMP平台构建完成。
useraddmirror
passwdmirror
输入两次密码
二.安装图形界面:
yumgroupinstall"Desktop""XWindowSystem""ChineseSupport""InternetBrowser""Fonts"
vi/etc/inittab
将3改成5
reboot
用mirror登陆
三.配置LNMP环境
1.基础设置:
1)关闭SELINUX
修改配置文件,重启服务后永久生效。
#sed-i's/SELINUX=.*/SELINUX=disabled/g'/etc/selinux/config
命令行设置立即生效。
#setenforce0
2)安全组设置
在ECS安全组放行需访问的端口和访问白名单,下面的示例表示允许所有IP访问服务器的80端口。您可以根据实际情况放行允许访问的客户端IP。
2.安装nginx
1)添加运行nginx服务进程的用户
#groupadd-rnginx
#useradd-r-gnginxnginx
2)下载源码包解压编译。
#wget
#tarxvfnginx-1.10.2.tar.gz-C/usr/local/src
#yumgroupinstall"Developmenttools"
#yum-yinstallgccwgetgcc-c++automakeautoconflibtoollibxml2-devellibxslt-develperl-develperl-ExtUtils-Embedpcre-developenssl-devel
#cd/usr/local/src/nginx-1.10.2
#./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
#make&&makeinstall
#mkdir-pv/var/tmp/nginx/client
3)添加SysV启动脚本。
#vim/etc/init.d/nginx
#!/bin/sh
#
#nginx-thisscriptstartsandstopsthenginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:nginx
#config:/etc/nginx/nginx.conf
#config:/etc/sysconfig/nginx
#pidfile:/var/run/nginx.pid
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
#Sourcenetworkingconfiguration.
./etc/sysconfig/network
#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0
nginx="/usr/sbin/nginx"
prog=$(basename$nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[-f/etc/sysconfig/nginx]&&./etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start(){
[-x$nginx]||exit5
[-f$NGINX_CONF_FILE]||exit6
echo-n$"Starting$prog:"
daemon$nginx-c$NGINX_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}
stop(){
echo-n$"Stopping$prog:"
killproc$prog-QUIT
retval=$?
echo
[$retval-eq0]&&rm-f$lockfile
return$retval
killall-9nginx
}
restart(){
configtest||return$?
stop
sleep1
start
}
reload(){
configtest||return$?
echo-n$"Reloading$prog:"
killproc$nginx-HUP
RETVAL=$?
echo
}
force_reload(){
restart
}
configtest(){
$nginx-t-c$NGINX_CONF_FILE
}
rh_status(){
status$prog
}
rh_status_q(){
rh_status>/dev/null2>&1
}
case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q||exit7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||exit0
;;
*)
echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit2
esac
4)赋予脚本执行权限。
#chmod+x/etc/init.d/nginx
5)添加至服务管理列表,设置开机自启。
#chkconfig--addnginx
#chkconfignginxon
6)启动服务。
#servicenginxstart
7)浏览器访问可看到默认欢迎页面。
3.安装mysql
1)准备编译环境。
#yumgroupinstall"ServerPlatformDevelopment""Developmenttools"-y
#yuminstallcmake-y
2)准备mysql数据存放目录。
#mkdir/mnt/data
#groupadd-rmysql
#useradd-r-gmysql-s/sbin/nologinmysql
#idmysql
3)更改数据目录属主属组。
#chown-Rmysql:mysql/mnt/data
4)解压编译在
wget-c
不要感觉奇怪,其实是内存不够导致的,这位兄弟也遇到一样的问题,如下:
在这里特别提醒,对于mysql5.7.8的make编译,如果是阿里云centos主机512M内存的,会在make编译到45%时会报错,这是内存不足所致。
c++:Internalerror:Killed(programcc1plus)
Pleasesubmitafullbugreport.
See<http://bugzilla.redhat.com/bugzilla>forinstructions.
make[2]:***[sql/CMakeFiles/sql.dir/item_geofunc.cc.o]Error1
make[1]:***[sql/CMakeFiles/sql.dir/all]Error2
make:***[all]Error2
那么设置2G交换分区来用下:
#ddif=/dev/zeroof=/swapfilebs=1kcount=2048000--获取要增加的2G的SWAP文件块
#mkswap/swapfile--创建SWAP文件
#swapon/swapfile--激活SWAP文件
#swapon-s--查看SWAP信息是否正确
#echo"/var/swapfileswapswapdefaults00">>/etc/fstab--添加到fstab文件中让系统引导时自动启动
注意,swapfile文件的路径在/var/下
编译完后,如果不想要交换分区了,可以删除:
#swapoff/swapfile
#rm-fr/swapfile
#tarxvfmysql-5.6.36.tar.gz-C/usr/local/src
#cd/usr/local/src/mysql-5.6.36
#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
#make&&makeinstall
5)修改安装目录的属组为mysql。
#chown-Rmysql: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
注:在CentOS6.8版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
7、拷贝配置文件和启动脚本。
#cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
#chmod+x/etc/init.d/mysqld
#cpsupport-files/my-default.cnf/etc/my.cnf
8)设置开机自动启动。
#chkconfigmysqldon
#chkconfig--addmysqld
9)修改配置文件中的安装路径及数据目录存放路径。
#echo-e"basedir=/usr/local/mysql\ndatadir=/mnt/data\n">>/etc/my.cnf
10)设置PATH环境变量。
#echo"exportPATH=$PATH:/usr/local/mysql/bin">/etc/profile.d/mysql.sh
#source/etc/profile.d/mysql.sh
11)启动服务。
4.安装php
1)安装依赖包。2)解压官网下载的源码包,编译安装。
#make&&makeinstall
3)添加php和php-fpm配置文件。
4)添加php-fpm启动脚本。
5)添加php-fpm至服务列表并设置开机自启。
6)启动服务。
7)添加nginx对fastcgi的支持,首先备份默认的配置文件。
编辑/etc/nginx/nginx.conf,在所支持的主页面格式中添加php格式的主页,类似如下:
取消以下内容前面的注释:
重新载入nginx的配置文件。
在/usr/local/nginx/html/新建index.php的测试页面,内容如下。
浏览器访问测试,如看到以下内容则表示LNMP平台构建完成。
相关文章推荐
- 从零开始在阿里云上搭建服务器(CentOS 6.8系统)
- 阿里云ECS CentOS6.8系统搭建FTP服务器
- 阿里云服务器CentOS系统搭建php开发环境(apache+php+mysql)
- 阿里云服务器Linux系统CentOS搭建安装svn指南
- 阿里云Linux-CentOS系统下-搭建Git服务器详解
- 阿里云服务器CentOS6.8搭建SVN服务器
- 阿里云CentOS6.8 64位FTP服务器的搭建
- 阿里云服务器上搭建git服务器(CentOS 系统)-有幸运卷
- 阿里云服务器搭建lnmp。Centos6.8 + nginx-1.10.3 + MySQL-5.6.16 + PHP-5.4.16
- 阿里云服务器CentOS 6.5系统搭建php开发环境(apache+php+mysql)
- 购买阿里云服务器CentOs 6.8及搭建lamp环境
- 阿里云Ubuntu系统从0搭建LAMP(Apache+MySQL+PHP)以及服务器生产环境常用配置
- 在阿里云 CentOS 服务器(ECS)上搭建 nginx + mysql + php-fpm 环境
- 基于vCenter/ESXi平台CentOS 6.8系统虚拟机Oracle 12c RAC双节点数据库集群搭建
- 在阿里云CentOS7上搭建ftp服务器
- 阿里云云服务器Linux系统FTP服务器搭建设置教程
- 阿里云服务器连接以及centos 搭建 web java环境(linux java部署 tomcat部署)
- 在阿里云主机上基于CentOS用vsftpd搭建FTP服务器
- 在阿里云 CentOS服务器上搭建nginx+mysql+php环境