CentOS 6.x下LNMP环境源码编译安装及配置

一:环境介绍 1.操作系统:CentOS 6.x ( 双核4G、硬盘至少20G) 2.应用软件:nginx-1.8.1、MySQL-5.6.29、php-5.6.30 二:源码编译安装配置nginx、mysql、php 1.源码编译安装nginx-1.8.1

官网下载nginx-1.8.1.tar.gz

下载pcre-8.40.tar.gz

https://ftp.pcre.org/pub/pcre/

yum安装依赖包

yum install perl gcc-c++ make elinks zlib-devel openssl openssl-devel -y

pcre 解压即可

tar -zxf pcre-8.4.0.tar.gz

开始编译安装nginx-1.8.1

tar -zxf nginx-1.8.1.tar.gz cd nginx-1.8.1 ./configure --prefix=/usr/local/nginx --with-pcre=/root/pcre-8.40 --with-http_stub_status_module --with-http_ssl_module make make install

修改nginx主配置文件,让其包含/usr/local/nginx/conf/conf.d下的所有*.conf文件

mkdir /usr/local/nginx/conf/conf.d sed -i '116s/$/include \/usr\/local\/nginx\/conf\/conf.d\/*.conf;/g' /usr/local/nginx/conf/nginx.conf

至此nginx安装完毕

启动nginx

/usr/local/nginx/sbin/nginx

查看80端口

netstat -ntpl |grep "80"

关闭防火墙/etc/init.d/iptables stop 或者防火墙打开80端口

(关闭nginx)

killall nginx 2.源码编译安装mysql-5.6.29

官网下载mysql-5.6.29.tar.gz

https://downloads.mysql.com/archives/community/

CentOS 6.x下LNMP环境源码编译安装及配置

 

下载cmake-3.4.0

https://cmake.org/files/v3.4/cmake-3.4.0.tar.gz

yum安装依赖包

yum install gcc-c++ ncurses-devel perl-Module-Install.noarch libtool openssl-devel make -y

安装cmake

tar -zxf cmake-3.4.0.tar.gz cd cmake-3.4.0 ./configure && make && make install

cmake安装完毕

开始编译安装mysql-5.6.29

tar -zxf mysql-5.6.29.tar.gz cd mysql-5.6.29

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/usr/local/mysql/data -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DWITH_EXTRA_CHARSETS=all -DWITH_DEBUG=0 -DENABLE_DEBUG_SYNC=0 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_READLINE=1 -DZLIB_INCLUDE_DIR=/usr -DWITH_READLINE=1
make
make install

创建mysql系统用户组和用户,并将mysql安装目录赋予root组和root用户

groupadd mysql useradd -g mysql -s /sbin/nologin -M mysql chown mysql.mysql -R /usr/local/mysql

初始化mysql数据库

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

复制mysql启动脚本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

直接执行修改文件

sed -i '46s/$/\/usr\/local\/mysql/g' /etc/init.d/mysqld sed -i '47s/$/\/usr\/local\/mysql\/data/g' /etc/init.d/mysqld sed -i '263s/datadir/basedir/g' /etc/init.d/mysqld

写入mysql配置文件my.cnf

echo "[mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysqld.sock user = mysql port = 3306 server_id = 2 #log-bin = mysql-bin #log_bin_index = binlog.index character_set_server = utf8 #lower_case_table_names = 1 #binlog_ignore_db = mysql #replicate-do-db = mysql sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES innodb_file_per_table=1 [mysql.server] character_set_server = utf8 socket=/usr/local/mysql/mysqld.sock [client] socket=/usr/local/mysql/mysqld.sock default-character-set = utf8 [mysqld_safe] character_set_server = utf8 [mysql] socket=/usr/local/mysql/mysqld.sock default-character-set = utf8 [mysqldump] socket=/usr/local/mysql/mysqld.sock default-character-set = utf8 [mysqladmin] socket=/usr/local/mysql/mysqld.sock character_set_server = utf8 " > /usr/local/mysql/my.cnf

将mysql加入centos系统环境变量
vim /etc/profile

echo -e "export MYSQL_HOME=\"/usr/local/mysql\" export PATH=\"\$PATH:\$MYSQL_HOME/bin\"" >> /etc/profile

刷新环境变量

source /etc/profile

至此mysql安装完毕

启动mysql

/etc/init.d/mysqld start

查看3306端口

netstat -ntpl |grep "3306"

(停止或重启mysql)

/etc/init.d/mysqld stop /etc/init.d/mysqld restart

shell界面进入mysql 删除默认的多余root账户

mysql -uroot -p delete from mysql.user where Host='::1'; delete from mysql.user where Host='localhost.localdomain'; delete from mysql.user where User='';

将所有的root用户更改密码

update mysql.user set password=password("root") where user="root";

创建一个可以从其他任何地方访问mysql的用户 密码为root

grant all privileges on *.* to 'root'@'%' identified by "root";

对用户进行增删改后需要重启数据库或者执行flush privileges;

查看mysql用户

select user,host,password from mysql.user; 3.源码编译安装php-5.6.30

官网下载php-5.6.30

yum安装依赖包

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4d1c1b0eb6d2d691236a225973baf241.html