兄弟连lamp环境搭建3

安装Apache
[root@localhost libgd-2.2.4]# cd ..
[root@localhost src]# cp -r apr-1.5.2 httpd-2.4.25/srclib/apr
[root@localhost src]# cp -r apr-util-1.5.4 httpd-2.4.25/srclib/apr-util
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache2/ --sysconfdir=/usr/local/apache2/etc/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared

将Apache安装所要的两个包apr以及apr-util拷贝到Apache安装文件的/srclib目录下并更名,去掉版本号,然后执行configure安装,出现报错

  • configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
安装pcre
[root@localhost httpd-2.4.25]# cd ../pcre-8.39 
[root@localhost pcre-8.39]# ./configure && make && make install
继续安装Apache
[root@localhost pcre-8.39]# cd -
/usr/local/src/httpd-2.4.25
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache2/ --sysconfdir=/usr/local/apache2/etc/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared && make && make install

#######安装ncurses

[root@localhost httpd-2.4.25]# yum install -y ncurses-devel
[root@localhost httpd-2.4.25]# cd ../ncurses-6.0
[root@localhost ncurses-6.0]# ./configure --with-shared --without-debug --without-ada --enable-overwrite && make && make install

#######安装cmake和bison

[root@localhost ncurses-6.0]# cd ..
[root@localhost src]# yum install cmake bison -y
```

#######安装mysql
这里的安装配置为5.7版本 5.4版本略有不同详见[plus mysql5.5版本的安装配置]()
mysql5.7是需要boost, 5.5版本不需要 ,如若 5.7版本 linux无法联网的话可以手动下载,再用xftp工具传入linux
`mkdir /usr/local/boost`
不需要解压直接tar.gz包放入这个目录
5.4版本可以取消这个参数
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost/
5.6版本则必须添加这两个参数,其中Ddownload为1的话是进行下载,如若有下载好的boost可以放在后面定义的目录中并修改为0
```
[root@localhost src]# cd mysql-5.7.17
[root@localhost mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost/
```
成功后显示
>-- Build files have been written to: /usr/local/src/mysql-5.7.17

接下来make and make install 整个安装大概需要持续50分钟耐心等候
`make && make install`

创建mysql用户及用户组
```
[root@localhost mysql-5.7.17]# cd /usr/local/mysql/
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -g mysql mysql
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
```
创建数据库目录,并修改用户为mysql
```
mkdir /home/data
chown mysql:mysql /home/data
```


数据库初始化
`/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/data`
注: 之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃
“–initialize”会生成一个随机密码(~/.mysql_secret),而”–initialize-insecure”不会生成密码
–datadir目标目录下不能有数据文件

如若出现报错mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
则手动创建目录并赋予mysql权限
```
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb
```

如若出现报错mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
```
mkdir -p /var/lib/mysql
chown mysql:mysql /var/lib/mysql
```

如若出现报错mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
`vi /etc/my.cnf`
把
>[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysql/mysqld.pid

改成

>[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/mysql/mysqld.pid

如若出现报错mysqld_safe error: log-error set to '/home/data//localhost.linux.err', however file don't exists. Create writable for user 'mysql'.
```
[root@localhost data]# touch /home/data//localhost.linux.err
[root@localhost data]# chown mysql:mysql /home/data//localhost.linux.err
```

数据库初始化成功后启动并设置密码,注意密码不能加引号5.7版本my-default.cnf 5.4版本为/my-medium.cnf 
```
cd /usr/local/mysql
chown -R root .
cp support-files/my-default.cnf /etc/my.cnf
/usr/local/mysql/bin/mysqld_safe --user=mysql &
/usr/local/mysql/bin/mysqladmin -uroot password newpassword
```

然后mysql就安装成功了,可以使用以下命令进入数据库
`/usr/local/mysql/bin/mysql -uroot -p`

tips
修改数据库root用户密码
方法1: 用SET PASSWORD命令
`mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');`
方法2:用mysqladmin
`shell>/usr/local/mysql/bin/mysqladmin -u root password "newpass"`
如果root已经设置过密码,采用如下方法
`shell>/usr/local/mysql/bin/mysqladmin -u root password oldpass "newpass"`
方法3: 用UPDATE直接编辑user表
mysql新版本中authentication_string是新的用户密码字段,之前为password,后面的PASSWORD是mysql的一个加密函数,后面newpassword改为你修改后的密码
```mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> UPDATE user SET authentication_string = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
```

如若忘记root用户密码或者找不到生成的临时密码,详情见[error]()

配置远程登录mysql
`mysql>grant all privileges on *.* to 'root'@'192.168.1.114' identified by '112233Qq.' with grant option`
允许192.168.1.114这个ip地址以root用户密码为112233Qq.登录到本机数据库

你可能感兴趣的:(兄弟连lamp环境搭建3)