一键部署lamp 脚本
一键部署lamp 脚本 如下:
#!/bin/bash systemctl stop firewalld systemctl disable firewalld setenforce 0 #-------Apache------ #安装依赖包 yum -y install gcc gcc-c++ make pcre pcre-devel expat-devel perl #配置软件模块 cd /opt/ tar zxvf apr-1.6.2.tar.gz tar zxvf apr-util-1.6.0.tar.gz tar jxvf httpd-2.4.29.tar.bz2 mv apr-1.6.2 /opt/httpd-2.4.29/srclib/apr mv apr-util-1.6.0 /opt/httpd-2.4.29/srclib/apr-util cd /opt/httpd-2.4.29/ ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi #编译安装,核数提前确认 make -j 2 && make install #优化配置文件路径,并把httpd服务的可执行程序文件放入路径环境变量的目录中便于系统识别 ln -s /usr/local/httpd/conf/httpd.conf /etc/ ln -s /usr/local/httpd/bin/* /usr/local/bin/ #添加httpd系统服务 cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd chmod +x /etc/init.d/httpd sed -i '1i #!/bin/bash' /etc/init.d/httpd sed -i '1a #chkconfig: 35 85 21' /etc/init.d/httpd sed -i '1a # description: Apache is a World Wide Web server' /etc/init.d/httpd chkconfig --add httpd systemctl start httpd.service #修改httpd 服务配置文件 cp /usr/local/httpd/conf/httpd.conf /usr/local/httpd/conf/httpd.conf.bak sed -i '52c Listen 192.168.80.13:80(IP根据实际情况)' /usr/local/httpd/conf/httpd.conf sed -i '198c ServerName www.kgc.com:80(自定)' /usr/local/httpd/conf/httpd.conf systemctl restart httpd #--------mysql-------- #安装依赖包 yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake #配置软件模块 cd /opt/ tar zxvf mysql-5.7.17.tar.gz tar zxvf boost_1_59_0.tar.gz mv boost_1_59_0 /usr/local/boost cd /opt/mysql-5.7.17/ cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DSYSCONFDIR=/etc \ -DSYSTEMD_PID_DIR=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_BOOST=/usr/local/boost \ -DWITH_SYSTEMD=1 #编译安装 make -j 2 && make install #创建mysql用户 useradd -M -s /sbin/nologin mysql #修改mysql 配置文件 rm -rf /etc/my.cnf echo '[client] port = 3306 default-character-set=utf8 socket=/usr/local/mysql/mysql.sock [mysql] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock auto-rehash [mysqld] user = mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data port = 3306 character-set-server=utf8 pid-file = /usr/local/mysql/mysqld.pid socket=/usr/local/mysql/mysql.sock bind-address = 0.0.0.0 skip-name-resolve max_connections=2048 default-storage-engine=INNODB max_allowed_packet=16M server-id = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' >> /etc/my.cnf #更改mysql安装目录和配置文件的属主属组 chown -R mysql:mysql /usr/local/mysql/ chown mysql:mysql /etc/my.cnf #设置路径环境变量 echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile source /etc/profile #初始化数据库 cd /usr/local/mysql/bin/ ./mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data #添加mysqld系统服务 cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ systemctl daemon-reload systemctl start mysqld.service systemctl enable mysqld yum -y install expect mima () { passwd=$1 /usr/bin/expect <<-EOF spawn mysqladmin -u root -p password $passwd expect "Enter password:" send "\r" expect eof EOF } mima "123456" dl () { /usr/bin/expect <<-EOF spawn mysql -u root -p expect "Enter password:" {send "123456\r"} expect "mysql>" {send "grant all privileges on *.* to 'root'@'%' identified by '123456';\r"} expect "mysql>" {send "quit\r"} expect eof EOF } dl #-------PHP #安装GD库和GD库关联程序,用来处理和生成图片 yum -y install \ gd \ libjpeg libjpeg-devel \ libpng libpng-devel \ freetype freetype-devel \ libxml2 libxml2-devel \ zlib zlib-devel \ curl curl-devel \ openssl openssl-devel #配置软件模块 cd /opt tar jxvf php-7.1.10.tar.bz2 cd /opt/php-7.1.10/ ./configure \ --prefix=/usr/local/php7 \ --with-apxs2=/usr/local/httpd/bin/apxs \ --with-mysql-sock=/usr/local/mysql/mysql.sock \ --with-config-file-path=/usr/local/php7 \ --with-mysqli \ --with-zlib \ --with-curl \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-openssl \ --enable-mbstring \ --enable-xml \ --enable-session \ --enable-ftp \ --enable-pdo \ --enable-tokenizer \ --enable-zip #编译安装 make -j 2 && make install #复制模版文件作为PHP 的主配置文件,并进行修改 cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini sed -i '1170c mysqli.default_socket = /usr/local/mysql/mysql.sock' /usr/local/php7/php.ini sed -i '939d' /usr/local/php7/php.ini sed -i '939i date.timezone = Asia/Shanghai' /usr/local/php7/php.ini #优化把PHP 的可执行程序文件放入路径环境变量的目录中便于系统识别 ln -s /usr/local/php7/bin/* /usr/local/bin/ #修改httpd 服务的配置文件,让apache支持PHP sed -i '393i AddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf sed -i '393i AddType application/x-httpd-php-source .phps' /usr/local/httpd/conf/httpd.conf sed -i '256c DirectoryIndex index.html index.php' /usr/local/httpd/conf/httpd.conf #验证PHP测试页 rm -rf /usr/local/httpd/htdocs/index.html echo '<?php phpinfo(); ?>' > /usr/local/httpd/htdocs/index.php systemctl restart httpd.service
自古英雄多磨难